8000 2 medium problems · KevinTrinh1227/leetcode@1e247a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e247a2

Browse files
2 medium problems
1 parent e5e1b45 commit 1e247a2

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
};

0 commit comments

Comments
 (0)
0