Skip to content

Instantly share code, notes, and snippets.

@rohanjai777
Created March 23, 2021 14:09
Show Gist options
  • Save rohanjai777/db5c2408d4ec2e8fcbcd10e9335fa5c2 to your computer and use it in GitHub Desktop.
Save rohanjai777/db5c2408d4ec2e8fcbcd10e9335fa5c2 to your computer and use it in GitHub Desktop.
public class Solution {
public void merge(ArrayList<Integer> a, ArrayList<Integer> b) {
int i=0;
int j=0;
int n = a.size();
int m = b.size();
//ArrayList<Integer> al = new ArrayList<>();
while(i<n || j<m){
if(i<n && j<m){
int v1 = a.get(i);
int v2 = b.get(j);
if(v1<=v2){
a.add(v1);
i++;
}else{
a.add(v2);
j++;
}
}else if(i<n){
int v1 = a.get(i);
i++;
a.add(v1);
}else if(j<m){
int v2 = b.get(j);
j++;
a.add(v2);
}
}
i = 0;
while(i<n){
a.remove(0);
i++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment