forked from yingl/LintCodeInPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpartition_array.py
More file actions
25 lines (24 loc) · 764 Bytes
/
Copy pathpartition_array.py
File metadata and controls
25 lines (24 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-
class Solution:
"""
@param nums: The integer array you should partition
@param k: As description
@return: The index after partition
"""
def partitionArray(self, nums, k):
# write your code here
# you should partition the nums by k
# and return the partition index as description
if not nums:
return 0
start, end = 0, len(nums) - 1
while start < end:
if nums[start] < k:
start += 1
elif nums[end] >= k:
end -= 1
else:
nums[start], nums[end] = nums[end], nums[start]
start += 1
end -= 1
return start + 1 if nums[start] < k else start