LeetCode Palindrome Number

原题链接在这里:https://leetcode.com/problems/palindrome-number/

div 表示能走到的第二高位。

Time Complexity: O(digit), digit代表x共有多少位。

AC Java:

 1 public class Solution {
 2     public boolean isPalindrome(int x) {
 3         if(x<0){
 4             return false;
 5         }
 6         
 7         int div = 1;
 8         while(div <= x/10){
 9             div*=10;
10         }
11         while(x!=0){
12             if(x/div != x%10){
13                 return false;
14             }
15             x = (x%div)/10;
16             div /= 100;
17         }
18         return true;
19     }
20 }

你可能感兴趣的:(LeetCode Palindrome Number)