func isPalindrome(x int) bool { if x < 0 { return false } var rev int origX := x for x != 0 { rev = rev * 10 + x % 10 x /= 10 } return rev == origX } Complexity Time: O(n) — where n is number of digits Space: O(1)