Skip to content
Open
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
18 changes: 18 additions & 0 deletions Problem 1- Leetcode80.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#Time Complexity: O(n)
#Space Complexity: O(1)

class Solution(object):
def removeDuplicates(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
slow, fast = 2, 2
while fast < len(nums):
if nums[fast] != nums[slow - 2]:
nums[slow] = nums[fast]
slow += 1
fast += 1
return slow


28 changes: 28 additions & 0 deletions Problem 2- Leetcode88.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#Time Complexity: O(n)
#Space Complexity: O(1)

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.
"""
p1, p2, idx = m - 1, n - 1, m + n - 1
while p1 >= 0 and p2 >= 0:
if nums1[p1] > nums2[p2]:
nums1[idx] = nums1[p1]
p1 -= 1
idx -= 1
else:
nums1[idx] = nums2[p2]
p2 -= 1
idx -= 1

while p2 >= 0:
nums1[idx] = nums2[p2]
p2 -= 1
idx -= 1

20 changes: 20 additions & 0 deletions Problem 3- Leetcode240.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#Time Complexity: O(m+n)
#Space Complexity: O(1)

class Solution(object):
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
m, n = len(matrix), len(matrix[0])
r, c = 0, n - 1

while r < m and c >= 0:
if matrix[r][c] == target: return True
elif matrix[r][c] > target: c -= 1
else: r += 1

return False