File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } height
3
+ * @return {number }
4
+ */
5
+ var maxArea = function ( height ) {
6
+ let maxArea = 0 ;
7
+ let l = 0 ;
8
+ let r = height . length - 1 ;
9
+ while ( l <= r ) {
10
+ let area = Math . min ( height [ l ] , height [ r ] ) * ( r - l ) ;
11
+ maxArea = Math . max ( maxArea , area ) ;
12
+ if ( height [ l ] < height [ r ] ) {
13
+ l ++ ;
14
+ } else if ( height [ l ] > height [ r ] ) {
15
+ r -- ;
16
+ } else {
17
+ l ++ ;
18
+ }
19
+ }
20
+
21
+ return maxArea ;
22
+ } ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } nums
3
+ * @return {number }
4
+ */
5
+ var longestConsecutive = function ( nums ) {
6
+ let someSet = new Set ( nums ) ;
7
+ let longestCount = 0 ;
8
+ let currCount = 0 ;
9
+
10
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
11
+ if ( someSet . has ( nums [ i ] - 1 ) == false ) {
12
+ currCount = 0 ;
13
+ while ( someSet . has ( nums [ i ] + currCount ) ) {
14
+ currCount ++ ;
15
+ }
16
+ if ( currCount > longestCount ) {
17
+ longestCount = currCount ;
18
+ }
19
+ }
20
+ }
21
+
22
+ return longestCount ;
23
+ } ;
You can’t perform that action at this time.
0 commit comments