Skip to content

Instantly share code, notes, and snippets.

@ozscosta
Created December 27, 2023 16:38
Show Gist options
  • Save ozscosta/efc93dc507a1ac505219b74b4ae0c0c1 to your computer and use it in GitHub Desktop.
Save ozscosta/efc93dc507a1ac505219b74b4ae0c0c1 to your computer and use it in GitHub Desktop.
Check is palindrome in Kotlin
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