We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8cdb2dc commit 8255243Copy full SHA for 8255243
valid-palindrome/sunjae95.js
@@ -0,0 +1,29 @@
1
+/**
2
+ * @description
3
+ * brainstorming:
4
+ * string method + two pointer
5
+ *
6
+ * time complexity: O(n)
7
+ * space complexity: O(n)
8
+ */
9
+
10
+var isPalindrome = function (s) {
11
+ const asciiArray = [];
12
13
+ for (let i = 0; i < s.length; i++) {
14
+ const asciiCode = s[i].toLowerCase().charCodeAt(0);
15
+ const isNumber = asciiCode >= 48 && asciiCode <= 57;
16
+ const isLowerCase = asciiCode >= 97 && asciiCode <= 122;
17
18
+ if (isNumber || isLowerCase) asciiArray.push(asciiCode);
19
+ }
20
21
+ const len = asciiArray.length;
22
+ const middleIndex = Math.floor(len);
23
24
+ for (let i = 0; i < middleIndex; i++) {
25
+ if (asciiArray[i] !== asciiArray[len - i - 1]) return false;
26
27
28
+ return true;
29
+};
0 commit comments