From ccd4d1f82e0593a7cee90fb7bddbcce121b1fad3 Mon Sep 17 00:00:00 2001 From: Shakthi Nandana Date: Sun, 26 Apr 2026 21:57:54 -0400 Subject: [PATCH 1/2] solutions --- mergesorted.py | 25 +++++++++++++++++++++++++ removeduplicates.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 mergesorted.py create mode 100644 removeduplicates.py diff --git a/mergesorted.py b/mergesorted.py new file mode 100644 index 00000000..36800fb3 --- /dev/null +++ b/mergesorted.py @@ -0,0 +1,25 @@ +# // Time Complexity : O(m+n) +# // Space Complexity : O(1) +# // Did this code successfully run on Leetcode : Yes + +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=m-1 + p2=n-1 + + for i in range(m+n-1,-1,-1): + if p2<0: + break + if p1>=0 and nums1[p1]>nums2[p2]: + nums1[i]=nums1[p1] + p1-=1 + else: + nums1[i]=nums2[p2] + p2-=1 \ No newline at end of file diff --git a/removeduplicates.py b/removeduplicates.py new file mode 100644 index 00000000..d528ea59 --- /dev/null +++ b/removeduplicates.py @@ -0,0 +1,28 @@ +# // Time Complexity : O(n) +# // Space Complexity : O(1) +# // Did this code successfully run on Leetcode : Yes + +class Solution(object): + def removeDuplicates(self, nums): + """ + :type nums: List[int] + :rtype: int + """ + p1=0 + p2=1 + count=1 + while (p2=2: + p2+=1 + continue + else: + count+=1 + else: + count=1 + p1+=1 + nums[p1]=nums[p2] + p2+=1 + return p1+1 + + \ No newline at end of file From bde66237c54c44e1c75442fd86b7cc98846eb08e Mon Sep 17 00:00:00 2001 From: Shakthi Nandana Date: Mon, 27 Apr 2026 20:48:53 -0400 Subject: [PATCH 2/2] solution to 2d matrix search --- search2dmatrix.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 search2dmatrix.py diff --git a/search2dmatrix.py b/search2dmatrix.py new file mode 100644 index 00000000..5ee606fe --- /dev/null +++ b/search2dmatrix.py @@ -0,0 +1,29 @@ +# // Time Complexity : O(m+n) +# // Space Complexity : O(1) +# // Did this code successfully run on Leetcode : Yes + +class Solution(object): + def searchMatrix(self, matrix, target): + """ + :type matrix: List[List[int]] + :type target: int + :rtype: bool + """ + m=len(matrix) + n=len(matrix[0]) + + diag = max(m,n) + row=0 + col=n-1 + while 0<=rowmatrix[row][col]: + row+=1 + else: + return True + + return False + + + \ No newline at end of file