diff --git a/Two-Pointers/MergeTwoSortedListsII.cpp b/Two-Pointers/MergeTwoSortedListsII.cpp index 3aa6232..26fd293 100644 --- a/Two-Pointers/MergeTwoSortedListsII.cpp +++ b/Two-Pointers/MergeTwoSortedListsII.cpp @@ -1,31 +1,42 @@ -// https://www.interviewbit.com/problems/merge-two-sorted-lists-ii/ +// // https://www.interviewbit.com/problems/merge-two-sorted-lists-ii/ -bool checkGreater(int A, int B){ - if(A > B){ - return true; - } - return false; -} +// bool checkGreater(int A, int B){ +// if(A > B){ +// return true; +// } +// return false; +// } +// void Solution::merge(vector &A, vector &B) { +// // Do not write main() function. +// // Do not read input, instead use the arguments to the function. +// // Do not print the output, instead return values as specified +// // Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details +// int i = 0, j = 0; +// while((i < A.size()) && (j < B.size())){ +// bool a = checkGreater(A[i], B[j]); +// if(a){ +// A.insert(A.begin()+i, B[j]); +// i++; +// j++; +// } +// else{ +// i++; +// } +// } +// while(j != B.size()){ +// A.push_back(B[j]); +// j++; +// } +// } void Solution::merge(vector &A, vector &B) { // Do not write main() function. // Do not read input, instead use the arguments to the function. // Do not print the output, instead return values as specified // Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details - int i = 0, j = 0; - while((i < A.size()) && (j < B.size())){ - bool a = checkGreater(A[i], B[j]); - if(a){ - A.insert(A.begin()+i, B[j]); - i++; - j++; - } - else{ - i++; - } - } - while(j != B.size()){ - A.push_back(B[j]); - j++; - } + + for(int i=0;i