Um momento
Leetcode / 9. Palindrome Number

Pick a programming language:

Here is the source code for the solution to this problem.

class Solution {
    // time complexity O(log(x))
    // space complexity O(1)
    public boolean isPalindrome(int x) {
        int n = x;
        int reversed = 0;

        while (n > 0) {
            int digit = n % 10;
            n /= 10;

            reversed = reversed * 10 + digit;
        }

        return reversed == x;
    }
}
Gostou da aula? 😆👍
Apoie nosso trabalho com uma doação: