Created
December 27, 2023 16:38
-
-
Save ozscosta/efc93dc507a1ac505219b74b4ae0c0c1 to your computer and use it in GitHub Desktop.
Check is palindrome in Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun isPalindrome(x: Int): Boolean | |
{ | |
if (x < 0) return false | |
val x = x.toString() | |
var left = 0; | |
var right = x.length - 1; | |
while (left < right) | |
{ | |
if (x[left] != x[right]) | |
{ | |
return false | |
} | |
left++; | |
right--; | |
} | |
return true; | |
} | |
fun main() { | |
println(isPalindrome(0)); | |
println(isPalindrome(121)); | |
println(isPalindrome(-121)); | |
println(isPalindrome(10)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment