- isLetterOrDigit()
- s.lengt
- s[left] != s[right]
class Solution {
fun isPalindrome(s: String): Boolean {
var s = s
var left = 0
var right = s.length-1
s = s.toLowerCase()
while(left < right){
if (!s[left].isLetterOrDigit()){
left++
} else if (!s[right].isLetterOrDigit()){
right--
} else {
if(s[left] != s[right]) return false
left++
right--
}
}
return true
}
}
0 comments:
張貼留言