Skip to content

Commit d435b1e

Browse files
authored
Merge pull request #38 from limbowandering/master
add javascript solutions
2 parents 903cf2a + 99fabad commit d435b1e

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const maxArea2 = function(height){
2+
let result = 0;
3+
for(let i = 0; i < height.length; i++){
4+
for(let j = i + 1; j < height.length; j++){
5+
result = Math.max(result, Math.min(height[i],height[j])*(j-i));
6+
}
7+
}
8+
return result;
9+
};
10+
11+
const maxArea = function(height){
12+
let result = 0, l = 0, r = height.length - 1;
13+
while(l < r){
14+
result = Math.max(result, Math.min(height[l],height[r])*(r-l));
15+
height[l] < height[r] ? l++ : r--;
16+
}
17+
return result;
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const hammingWeight = function(n){
2+
let result = 0;
3+
while(n){
4+
result += n & 1;
5+
n = n >>> 1;
6+
}
7+
return result;
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const minFlipsMonoIncr = function (S) {
2+
let n = S.length;
3+
let f = [];
4+
for (let i = 0; i < n + 1; i++) {
5+
f.push(0);
6+
}
7+
for (let i = 0; i < n; i++) {
8+
f[i + 1] = f[i] + (S[i] === '1');
9+
}
10+
let ans = n;
11+
for (let i = 0; i <= n; i++) {
12+
let a = f[i];
13+
let b = (n - i) - (f[n] - f[i]);
14+
ans = Math.min(ans, b + a);
15+
}
16+
return ans;
17+
};

0 commit comments

Comments
 (0)