Last active
December 14, 2015 13:39
-
-
Save guolinaileen/5095316 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
bool isPalindrome(int x) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
if(x<0) return false; | |
int counter=1; | |
while(x/counter>=10) | |
{ | |
counter*=10; | |
} | |
while(x!=0) | |
{ | |
if(x/counter!=x%10) return false; | |
x=(x%counter)/10; | |
counter/=100; | |
} | |
return true; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public boolean isPalindrome(int x) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
if(x<0) return false; | |
int counter=1; | |
while(x/counter>=10) | |
{ | |
counter*=10; | |
} | |
while(x!=0) | |
{ | |
int left=x/counter; | |
int right=x%10; | |
if(left!=right) return false; | |
x=(x-left*counter-right)/10; | |
counter/=100; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment