Created
March 5, 2013 21:54
-
-
Save guolinaileen/5094675 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
public class Solution { | |
public int reverse(int x) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
if(x==0) return 0; | |
boolean negative=false; | |
if(x<0) { negative=true; x=-x; } | |
int result=0; | |
while(x!=0) | |
{ | |
result=result*10 + x%10; | |
x=x/10; | |
} | |
return negative? -result: result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment