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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/Two-Pointers-2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions MergeSortedArrays.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import java.util.Arrays;
public class MergeSortedArrays {
public void merge(int[] nums1, int m, int[] nums2, int n){
int i = m - 1;
int j = n - 1;
int k = m + n - 1;
while(i >= 0 && j >= 0){
if(nums1[i] >= nums2[j]){
nums1[k] = nums1[i];
k--;
i--;
}else{
nums1[k] = nums2[j];
k--;
j--;
}
}
}
public static void main(String[] args){
MergeSortedArrays solution = new MergeSortedArrays();

int [] nums1 = {1,2,3,0,0,0}; int m = 3;
int [] nums2 = {2,5,6}; int n = 3;
solution.merge(nums1, m, nums2, n);
System.out.println(Arrays.toString(nums1));
}
}

//Time complexity : O(m+n)
//Space complexity : O(1)
19 changes: 19 additions & 0 deletions RemoveDuplicates.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class RemoveDuplicates {
public static int removeDuplicates(int[] nums) {
int i = 0;
for(int n: nums){
if(i<2 || n!=nums[i-2]){
nums[i++]=n;
}
}
return i;
}
public static void main(String[] args){
int[] nums={1,1,1,2,2,3,3,4};
System.out.println(removeDuplicates(nums));
}
}


//Time complexity : O(n)
//Space complexity : O(1)
23 changes: 23 additions & 0 deletions SearchMatrix.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class SearchMatrix {
public boolean searchMatrix(int[][] matrix, int target) {
int m = matrix.length;
int n = matrix[0].length;
int i = 0;
int j = n - 1;
while(i < m && j >= 0 ){
if(matrix[i][j] == target) return true;
else if(matrix[i][j] > target){
j--;
} else{
i++;
}
}
return false;
}
}

//TC :Time Complexity:
//O(m log n)

//Space Complexity:
//O(1)
3 changes: 3 additions & 0 deletions out/production/Two-Pointers-2/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions out/production/Two-Pointers-2/.idea/Two-Pointers-2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions out/production/Two-Pointers-2/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions out/production/Two-Pointers-2/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions out/production/Two-Pointers-2/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions out/production/Two-Pointers-2/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
10 changes: 10 additions & 0 deletions out/production/Two-Pointers-2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Two-Pointers-2

## Problem1 (https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/)


## Problem2 (https://leetcode.com/problems/merge-sorted-array/)


## Problem3 (https://leetcode.com/problems/search-a-2d-matrix-ii/)

Binary file added out/production/Two-Pointers-2/RemoveDuplicates.class
Binary file not shown.