[LeetCode][Python3] 75. Sort Colors
2019. 1. 24. 01:47 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/sort-colors/
My Solution :
class Solution:
def sortColors(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""
i, j, k = 0, len(nums)-1, 0
while k <= j:
if nums[k] == 0 and k != i:
nums[k], nums[i] = nums[i], nums[k]
i += 1
elif nums[k] == 2 and k != j:
nums[k], nums[j] = nums[j], nums[k]
j -= 1
else:
k += 1
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 279. Perfect Squares (0) | 2019.01.31 |
---|---|
[LeetCode][Python3] 162. Find Peak Element (0) | 2019.01.25 |
[LeetCode][Python3] 328. Odd Even Linked List (0) | 2019.01.25 |
[LeetCode][Python3] 287. Find the Duplicate Number (0) | 2019.01.25 |
[LeetCode][Python3] 102. Binary Tree Level Order Traversal (0) | 2019.01.22 |
[LeetCode][Python3] 230. Kth Smallest Element in a BST (0) | 2019.01.15 |
[LeetCode][Python3] 454. 4Sum II (1) | 2019.01.13 |
[LeetCode][Python3] 78. Subsets (0) | 2019.01.13 |
최근에 달린 댓글 최근에 달린 댓글