From 6327da447020129ab469ff9052e3f068aa6648d5 Mon Sep 17 00:00:00 2001 From: earnMoneyToBuyMoon <42364813+earnMoneyToBuyMoon@users.noreply.github.com> Date: Mon, 21 Oct 2019 14:08:41 +0800 Subject: [PATCH 1/4] Add files via upload --- Week 01/id_226/merge_two_array.py | 24 ++++++++++++++++++++++++ Week 01/id_226/move_zero.py | 15 +++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 Week 01/id_226/merge_two_array.py create mode 100644 Week 01/id_226/move_zero.py diff --git a/Week 01/id_226/merge_two_array.py b/Week 01/id_226/merge_two_array.py new file mode 100644 index 000000000..bc1597de8 --- /dev/null +++ b/Week 01/id_226/merge_two_array.py @@ -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] diff --git a/Week 01/id_226/move_zero.py b/Week 01/id_226/move_zero.py new file mode 100644 index 000000000..dd61ef173 --- /dev/null +++ b/Week 01/id_226/move_zero.py @@ -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 + From 7b415a30de34c5b645336df4ada5bc17739953c8 Mon Sep 17 00:00:00 2001 From: earnMoneyToBuyMoon <42364813+earnMoneyToBuyMoon@users.noreply.github.com> Date: Mon, 21 Oct 2019 15:21:11 +0800 Subject: [PATCH 2/4] Delete merge_two_array.py --- Week 01/id_226/merge_two_array.py | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 Week 01/id_226/merge_two_array.py diff --git a/Week 01/id_226/merge_two_array.py b/Week 01/id_226/merge_two_array.py deleted file mode 100644 index bc1597de8..000000000 --- a/Week 01/id_226/merge_two_array.py +++ /dev/null @@ -1,24 +0,0 @@ -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] From 45121e2adc225b138b88baf3a2374027ff92f92d Mon Sep 17 00:00:00 2001 From: earnMoneyToBuyMoon <42364813+earnMoneyToBuyMoon@users.noreply.github.com> Date: Mon, 21 Oct 2019 15:21:18 +0800 Subject: [PATCH 3/4] Delete move_zero.py --- Week 01/id_226/move_zero.py | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 Week 01/id_226/move_zero.py diff --git a/Week 01/id_226/move_zero.py b/Week 01/id_226/move_zero.py deleted file mode 100644 index dd61ef173..000000000 --- a/Week 01/id_226/move_zero.py +++ /dev/null @@ -1,15 +0,0 @@ -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 - From f639056990500db61fdd657393ee27471ba86ddf Mon Sep 17 00:00:00 2001 From: earnMoneyToBuyMoon <42364813+earnMoneyToBuyMoon@users.noreply.github.com> Date: Mon, 21 Oct 2019 15:21:47 +0800 Subject: [PATCH 4/4] Add files via upload --- Week 01/id_226/leetCode_226.py | 15 +++++++++++++++ Week 01/id_226/leetCode_88_226.py | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 Week 01/id_226/leetCode_226.py create mode 100644 Week 01/id_226/leetCode_88_226.py diff --git a/Week 01/id_226/leetCode_226.py b/Week 01/id_226/leetCode_226.py new file mode 100644 index 000000000..dd61ef173 --- /dev/null +++ b/Week 01/id_226/leetCode_226.py @@ -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 + diff --git a/Week 01/id_226/leetCode_88_226.py b/Week 01/id_226/leetCode_88_226.py new file mode 100644 index 000000000..bc1597de8 --- /dev/null +++ b/Week 01/id_226/leetCode_88_226.py @@ -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]