diff --git a/solution/011. Container With Most Water/Solution.js b/solution/011. Container With Most Water/Solution.js new file mode 100644 index 0000000000000..5fe55494d506d --- /dev/null +++ b/solution/011. Container With Most Water/Solution.js @@ -0,0 +1,18 @@ +const maxArea2 = function(height){ + let result = 0; + for(let i = 0; i < height.length; i++){ + for(let j = i + 1; j < height.length; j++){ + result = Math.max(result, Math.min(height[i],height[j])*(j-i)); + } + } + return result; +}; + +const maxArea = function(height){ + let result = 0, l = 0, r = height.length - 1; + while(l < r){ + result = Math.max(result, Math.min(height[l],height[r])*(r-l)); + height[l] < height[r] ? l++ : r--; + } + return result; +} diff --git a/solution/191. Number of 1 Bits/Solution.js b/solution/191. Number of 1 Bits/Solution.js new file mode 100644 index 0000000000000..e5dcf21d897d4 --- /dev/null +++ b/solution/191. Number of 1 Bits/Solution.js @@ -0,0 +1,8 @@ +const hammingWeight = function(n){ + let result = 0; + while(n){ + result += n & 1; + n = n >>> 1; + } + return result; +} \ No newline at end of file diff --git a/solution/926. Flip String to Monotone Increasing/Solution.js b/solution/926. Flip String to Monotone Increasing/Solution.js new file mode 100644 index 0000000000000..0b30dc295464a --- /dev/null +++ b/solution/926. Flip String to Monotone Increasing/Solution.js @@ -0,0 +1,17 @@ +const minFlipsMonoIncr = function (S) { + let n = S.length; + let f = []; + for (let i = 0; i < n + 1; i++) { + f.push(0); + } + for (let i = 0; i < n; i++) { + f[i + 1] = f[i] + (S[i] === '1'); + } + let ans = n; + for (let i = 0; i <= n; i++) { + let a = f[i]; + let b = (n - i) - (f[n] - f[i]); + ans = Math.min(ans, b + a); + } + return ans; +}; \ No newline at end of file