Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- """
- @param nums: The integer array you should partition
- @param k: An integer
- @return: The index after partition
- """
- def partitionArray(self, nums, k):
- # write your code here
- if len(nums) == 0:
- return 0
- j = len(nums)-1
- i = 0
- while i <=j and nums[i]<k:
- i+=1
- if i > j:
- return len(nums)
- while nums[j] >= k:
- if j > i:
- j -= 1
- else:
- break
- if j == i:
- return j
- while i<j:
- if nums[i]>=k:
- while nums[j]>=k:
- if j > i:
- j-=1
- else:
- return j
- temp = nums[j]
- nums[j]=nums[i]
- nums[i]=temp
- i+=1
- return j
Add Comment
Please, Sign In to add comment