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 208ccc7 commit 5f005ffCopy full SHA for 5f005ff
βvalid-palindrome/tolluset.tsβ
@@ -0,0 +1,31 @@
1
+/*
2
+ * TC: O(n)
3
+ * SC: O(n)
4
+ * */
5
+function isPalindrome(s: string): boolean {
6
+ const parsedString = s.replace(/[^A-Za-z0-9]/g, "").toLowerCase();
7
+ const n = parsedString.length;
8
+
9
+ if (n === 0) {
10
+ return true;
11
+ }
12
13
+ for (let i = 0; i < n / 2; i++) {
14
+ if (parsedString[i] !== parsedString[n - i - 1]) {
15
+ return false;
16
17
18
19
20
+}
21
22
+// Time complexity: O(n)
23
24
+const t1 = isPalindrome("A man, a plan, a canal: Panama");
25
+console.info("π : tolluset.ts:18: t1=", t1);
26
27
+const t2 = isPalindrome("race a car");
28
+console.info("π : tolluset.ts:21: t2=", t2);
29
30
+const t3 = isPalindrome(" ");
31
+console.info("π : tolluset.ts:24: t3=", t3);
0 commit comments