# leetcode 一些演算法題目記錄

### 個人

`

``````
var max = Math.pow(2,31) - 1
var isPalindrome = function(x) {
if (x < 0 || x > max || (x != 0 && x % 10 == 0)) return false
if (x < 10) return true
var num = 0
while(x > num) {
num = num * 10   x % 10
x = Math.floor(x / 10)
}
return num == x || (x != 0 && Math.floor(num / 10) == x)
};
``````

#### Container With Most Water

`

``給定一個陣列，想象成一個二位座標系，陣列中每一個元素 a[i] => n 就是座標系上的一條線段[ (i,0) => (i,x) ]。找出任意兩條線段與 x 軸組成的木桶，可以盛水最大的值。``

`

``````
var maxArea = function(height) {
let i = 0, l = height.length -1, res = 0
while(i < l) {
var h = Math.min(height[i],height[l])
res = Math.max(res, (l-i) * h)
if(height[i] < height[l]) {
while(height[i] <= h && i < l){i  }
} else {
while(h >= height[l] && i < l){l--}
}
}
return res
}
``````

#### Regular Expression Matching

`

``````實現正則，
'.' Matches any single character.
'*' Matches zero or more of the preceding element.
isMatch("aa","a") → false
isMatch("ab", ".*") → true
isMatch("aab", "c*a*b") → true
``````

`

``````
var isMatch = function(s, p) {
if(p[0] === undefined) return s[0] === undefined
if (p[1] != '*') {
if (s[0] === p[0] || (p[0] === '.' && s[0] !== undefined))
return isMatch(s.substr(1), p.substr(1))
else
return false
} else {
if (isMatch(s, p.substr(2)))return true
let index = 0
while(index <= s.length && (s[index] === p[0] || p[0] === '.')){
if(isMatch(s.substr(  index), p.substr(2))) return true
}
return false
}
}
``````

#### Is Circular

``````    var a = [1]
a.push(a)
JSON.stringify(a) // => Uncaught TypeError: Converting circular structure to JSON``````

#### Submission Details

``````給一個數字，寫一個函式根據數字生成所有形式良好的括號組合
2 => ["()()", "(())"]
3 =>
[
"((()))",
"(()())",
"(())()",
"()(())",
"()()()"
]
``````