Skip to content

Instantly share code, notes, and snippets.

@guolinaileen
Created March 5, 2013 21:54
Show Gist options
  • Save guolinaileen/5094675 to your computer and use it in GitHub Desktop.
Save guolinaileen/5094675 to your computer and use it in GitHub Desktop.
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