Skip to content

Commit 244a2f8

Browse files
authored
Update 125. Valid Palindrome.md
1 parent 5401727 commit 244a2f8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

101-200/125. Valid Palindrome.md

+31
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,34 @@ nope.
6161

6262
* Time complexity : O(n).
6363
* Space complexity : O(n).
64+
65+
66+
```js
67+
/**
68+
* @param {string} s
69+
* @return {boolean}
70+
*/
71+
var isPalindrome = function(s) {
72+
73+
s = s.toLowerCase().replace(/[\W_]/g, '');
74+
75+
let left = 0;
76+
let right = s.length - 1;
77+
78+
while (left < right) {
79+
if (s[left] !== s[right]) {
80+
return false
81+
}
82+
left++;
83+
right--;
84+
}
85+
86+
return true;
87+
88+
};
89+
```
90+
91+
**Complexity:**
92+
93+
* Time complexity : O(n).
94+
* Space complexity : O(1). left and right pointers take the constant space.

0 commit comments

Comments
 (0)