O(n) time, O(1) extra memory.
Tag Archives: Two Pointers
Partition Array – Python 3 (Week 18 – 11)
3Sum – Python 3 (Week 18 – 10)
Sort Colors II – Python 3 (Week 18 – 09)
Two Sum II – Input array is sorted – Python 3 (Week 18 – 08)
Sort Integers II – Python 3 ( Week 18 – 07)
Solution 1 quick sort Time O(nlogn). Space O(1). Solution 2 merge sort Time O(nlogn). Space O(n).
Remove Duplicate Numbers in Array – Python 3 ( Week 18 – 06)
Solution 1 O(n) time, O(n) space Solution 2 O(nlogn) time, O(1) space
Middle of Linked List – Python 3 (Week 18 – 05)
Partition Array – Python 3 (Week 14 – 18)
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 start, end = 0, len(nums) – 1 while start <= end: while start <= end and nums[start] < k: start += 1 while start <= …
Continue reading “Partition Array – Python 3 (Week 14 – 18)”