8000 11th problem · Tahirc1/LeetcodeJs@e7e4551 · GitHub
[go: up one dir, main page]

Skip to content

Commit e7e4551

Browse files
committed
11th problem
1 parent 6f64676 commit e7e4551

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
8000 -0
lines changed

11. Container With Most Water.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var maxArea = function(height) {
2+
let max = 0
3+
let i = 0 // start pointer
4+
let j = height.length - 1 // end pointer
5+
let k = 0
6+
let water = 0
7+
while(i < j){
8+
// store height of short wall
9+
k = Math.min(height[i] , height[j])
10+
// water it can hold
11+
water = (j-i)*k
12+
// if it stores more water make it max
13+
if(water > max){max = water}
14+
// move the line to new position
15+
if(height[i] < height[j]){i++}else{j--}
16+
}
17+
return max
18+
};

8. String to Integer (atoi).js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var myAtoi = function(s) {
2+
// convert to number
3+
let num = parseInt(s)
4+
// if num smaller than negative limit
5+
if(num < -Math.pow(2, 31)){return -Math.pow(2, 31)}
6+
// if num greater than positive limit
7+
else if(num > Math.pow(2, 31) - 1){return Math.pow(2, 31) - 1}
8+
// if num is NotANumber
9+
else if(isNaN(num)){return 0}
10+
// return number
11+
else{return num}
12+
};

9. Palindrome Number.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var isPalindrome = function(x) {
2+
// turn int to String
3+
let s = x+""
4+
// Iterate the String
5+
for(let i = 0 ; i < s.length/2 ; i++){
6+
// Check if match or not
7+
if(s[i] != s[(s.length-i-1)]){
8+
return false
9+
}
10+
}
11+
return true
12+
};

0 commit comments

Comments
 (0)
674
0