We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5401727 commit 244a2f8Copy full SHA for 244a2f8
101-200/125. Valid Palindrome.md
@@ -61,3 +61,34 @@ nope.
61
62
* Time complexity : O(n).
63
* 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