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.
2 parents 4143862 + 1671464 commit 87d975cCopy full SHA for 87d975c
valid-palindrome/Lustellz.ts
@@ -0,0 +1,17 @@
1
+function isPalindrome(s: string): boolean {
2
+ // https://leetcode.com/problems/valid-palindrome/
3
+ // Runtime: 6ms
4
+ // Memory: 58.88MB
5
+ const convertedString: string = s.replace(/[^a-zA-Z0-9]/g, '').toLowerCase()
6
+ let lettersArray: string[]
7
+ if(convertedString.length>0){
8
+ lettersArray = convertedString.split("")
9
+ for(let idx = 0; idx<(lettersArray.length/2); idx++){
10
+ if(lettersArray[idx] !== lettersArray[lettersArray.length-idx-1]) return false
11
+ }
12
13
+ return true
14
+
15
+ // what I had done wrong at first: reducing the length of the array
16
+ // simple solution: reverse and compare (return convertedString === convertedString.split("").reverse().join(""))
17
+};
0 commit comments