File tree 2 files changed +47
-1
lines changed
2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,067 LeetCode solutions in JavaScript
1
+ # 1,068 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcode.com/ ] ( https://leetcode.com/ )
4
4
794
794
983|[ Minimum Cost For Tickets] ( ./solutions/0983-minimum-cost-for-tickets.js ) |Medium|
795
795
984|[ String Without AAA or BBB] ( ./solutions/0984-string-without-aaa-or-bbb.js ) |Medium|
796
796
985|[ Sum of Even Numbers After Queries] ( ./solutions/0985-sum-of-even-numbers-after-queries.js ) |Easy|
797
+ 986|[ Interval List Intersections] ( ./solutions/0986-interval-list-intersections.js ) |Medium|
797
798
989|[ Add to Array-Form of Integer] ( ./solutions/0989-add-to-array-form-of-integer.js ) |Easy|
798
799
994|[ Rotting Oranges] ( ./solutions/0994-rotting-oranges.js ) |Medium|
799
800
997|[ Find the Town Judge] ( ./solutions/0997-find-the-town-judge.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 986. Interval List Intersections
3
+ * https://leetcode.com/problems/interval-list-intersections/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given two lists of closed intervals, firstList and secondList, where
7
+ * firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each list of
8
+ * intervals is pairwise disjoint and in sorted order.
9
+ *
10
+ * Return the intersection of these two interval lists.
11
+ *
12
+ * A closed interval [a, b] (with a <= b) denotes the set of real numbers x with a <= x <= b.
13
+ *
14
+ * The intersection of two closed intervals is a set of real numbers that are either empty
15
+ * or represented as a closed interval. For example, the intersection of [1, 3] and
16
+ * [2, 4] is [2, 3].
17
+ */
18
+
19
+ /**
20
+ * @param {number[][] } firstList
21
+ * @param {number[][] } secondList
22
+ * @return {number[][] }
23
+ */
24
+ var intervalIntersection = function ( firstList , secondList ) {
25
+ const result = [ ] ;
26
+ let i = 0 ;
27
+ let j = 0 ;
28
+
29
+ while ( i < firstList . length && j < secondList . length ) {
30
+ const start = Math . max ( firstList [ i ] [ 0 ] , secondList [ j ] [ 0 ] ) ;
31
+ const end = Math . min ( firstList [ i ] [ 1 ] , secondList [ j ] [ 1 ] ) ;
32
+
33
+ if ( start <= end ) {
34
+ result . push ( [ start , end ] ) ;
35
+ }
36
+
37
+ if ( firstList [ i ] [ 1 ] < secondList [ j ] [ 1 ] ) {
38
+ i ++ ;
39
+ } else {
40
+ j ++ ;
41
+ }
42
+ }
43
+
44
+ return result ;
45
+ } ;
You can’t perform that action at this time.
0 commit comments