Skip to content

Commit 82396c1

Browse files
committed
Runtime: 69 ms (Top 81.31%) | Memory: 50.80 MB (Top 73.94%)
1 parent 6fb6679 commit 82396c1

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1+
// Runtime: 69 ms (Top 81.31%) | Memory: 50.80 MB (Top 73.94%)
2+
13
class Solution {
24
public:
35
int getCommon(vector<int>& nums1, vector<int>& nums2) {
4-
int i=0, j=0, element;
6+
int i=0, j=0, element;
57
while(i<nums1.size() && j<nums2.size()) {
6-
if(nums1[i]<nums2[j])
7-
{
8+
if(nums1[i]<nums2[j]) {
9+
// if the ith element in nums1 is smaller than
10+
// the jth element in nums2, increment pointer i
811
i++;
9-
}
10-
else if(nums1[i]>nums2[j])
11-
{
12+
} else if(nums1[i]>nums2[j]) {
13+
// if the ith element in nums1 is greater than
14+
// the jth element in nums2, increment pointer j
1215
j++;
13-
}
14-
else if(nums1[i] == nums2[j])
15-
{
16+
} else if(nums1[i] == nums2[j]) {
17+
// if the ith and jth elements are equal, return it
18+
// this will always return the smallest element
1619
return nums1[i];
1720
}
1821
}
1922
return -1;
2023
}
21-
};
24+
};

0 commit comments

Comments
 (0)