美文网首页
9. Palindrome Number

9. Palindrome Number

作者: becauseyou_90cd | 来源:发表于2018-08-01 07:29 被阅读0次

    https://leetcode.com/problems/palindrome-number/description/

    解题思路:

    1. 反向相乘去得到目标值
      reverse = reverse * 10 + temp % 10;
      temp /= 10;

    代码:
    class Solution {
    public boolean isPalindrome(int x) {
    if(x < 0) return false;
    int reverse = 0, temp = x;
    while(temp > 0){
    reverse = reverse * 10 + temp % 10;
    temp /= 10;
    }
    return reverse == x;
    }
    }

    相关文章

      网友评论

          本文标题:9. Palindrome Number

          本文链接:https://www.haomeiwen.com/subject/ceflvftx.html