Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Week 01/id_226/leetCode_226.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution(object):
def moveZeroes(self, nums):
"""
:type nums: List[int]
:rtype: None Do not return anything, modify nums in-place instead.
"""
snowBall = 0
index = 0
while index < len(nums):
if nums[index] == 0:
snowBall += 1
elif snowBall > 0:
nums[index] , nums[index - snowBall] = nums[index - snowBall],nums[index]
index += 1

24 changes: 24 additions & 0 deletions Week 01/id_226/leetCode_88_226.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution(object):
def merge(self, nums1, m, nums2, n):
"""
:type nums1: List[int]
:type m: int
:type nums2: List[int]
:type n: int
:rtype: None Do not return anything, modify nums1 in-place instead.
"""
if m == 0:
nums1[:] = nums2
tail1 = m - 1
tail2 = n - 1
tail = m + n -1
while tail1 >= 0 and tail2 >=0:
if nums1[tail1] < nums2[tail2]:
nums1[tail] = nums2[tail2]
tail2 -= 1
else:
nums1[tail] = nums1[tail1]
tail1 -= 1
tail -= 1
if tail2 >= 0:
nums1[:tail2 + 1] = nums2[:tail2 + 1]