[LeetCode] 125. Valid Palindrome(Kotlin)

0

LeetCode

목록 보기
12/58
post-thumbnail

[LeetCode] 125. Valid Palindrome(Kotlin)

풀이

  • Alphanumeric char를 남겨야 함에 주의!
class Solution {
    fun isPalindrome(s: String): Boolean {
        val sList = s.lowercase().toList().filter{it in 'a'..'z' || it in '0'..'9'}

        println("$sList")
        val n = sList.size
        for(i in 0 until (n/2)){
            if(sList[i] != sList[n - i - 1]) return false
        }
        return true
    }
}
profile
Be able to be vulnerable, in search of truth

0개의 댓글