File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
MayLeetCodingChallenge_2020 Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ // https://leetcode.com/explore/challenge/card/may-leetcoding-challenge/537/week-4-may-22nd-may-28th/3338/
2
+
3
+
4
+ class Solution {
5
+ public:
6
+ vector<vector<int >> intervalIntersection (vector<vector<int >>& A, vector<vector<int >>& B) {
7
+ int l = A.size ();
8
+ int m = B.size ();
9
+ int i = 0 , j = 0 ;
10
+
11
+ vector<vector<int >> ans;
12
+
13
+ while (i < l && j < m) {
14
+ int start_a = A[i][0 ], end_a = A[i][1 ];
15
+ int start_b = B[j][0 ], end_b = B[j][1 ];
16
+ vector<int > temp;
17
+ if (end_a < start_b)
18
+ i++;
19
+ else if (end_b < start_a)
20
+ j++;
21
+ else if (start_a >= start_b && start_a <= end_b) {
22
+ temp.push_back (start_a);
23
+ if (end_a >= start_b && end_a <= end_b){
24
+ temp.push_back (end_a);
25
+ i++;
26
+ } else {
27
+ temp.push_back (end_b);
28
+ j++;
29
+ }
30
+ ans.push_back (temp);
31
+ }
32
+ else if (start_b >= start_a && start_b <= end_a) {
33
+ temp.push_back (start_b);
34
+ if (end_b >= start_a && end_b <= end_a){
35
+ temp.push_back (end_b);
36
+ j++;
37
+ } else {
38
+ temp.push_back (end_a);
39
+ i++;
40
+ }
41
+ ans.push_back (temp);
42
+ }
43
+ }
44
+ return ans;
45
+ }
46
+ };
You can’t perform that action at this time.
0 commit comments