g0001_0100.s0009_palindrome_number.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
package g0001_0100.s0009_palindrome_number
// #Easy #Math #Udemy_Integers #2023_07_03_Time_217_ms_(95.34%)_Space_36.1_MB_(98.21%)
class Solution {
fun isPalindrome(x: Int): Boolean {
if (x < 0) return false
var rev = 0
var localX = x
while (localX > 0) {
rev *= 10
rev += localX % 10
localX /= 10
}
return rev == x
}
}