Skip to content

Commit 75e1039

Browse files
committed
Changes for Google questions
1 parent ffed77d commit 75e1039

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {number[]} height
3+
* @return {number}
4+
*/
5+
var maxArea = function(height) {
6+
let p1 = 0, p2 = height.length - 1;
7+
let maxArea = 0;
8+
while(p1 != p2){
9+
if(height[p1] < height[p2]){
10+
maxArea = Math.max((p2 - p1) * height[p1], maxArea);
11+
p1++;
12+
} else {
13+
maxArea = Math.max((p2 - p1) * height[p2], maxArea);
14+
p2--;
15+
}
16+
}
17+
return maxArea;
18+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var lengthOfLongestSubstring = function(s) {
6+
let charMap = {}, maxLength = 0, curLength = 0;
7+
for(let i=0; i<s.length; i++){
8+
if(charMap[s[i]] == null || charMap[s[i]] < i - curLength){
9+
charMap[s[i]] = i;
10+
curLength++;
11+
} else {
12+
curLength = i - charMap[s[i]];
13+
charMap[s[i]] = i;
14+
}
15+
maxLength = Math.max(maxLength, curLength);
16+
}
17+
return maxLength;
18+
};

0 commit comments

Comments
 (0)