Skip to content

Instantly share code, notes, and snippets.

@codeperfectplus
Created September 8, 2023 14:28
Show Gist options
  • Select an option

  • Save codeperfectplus/90c9aaebd77b8e122c57e3a6129e7040 to your computer and use it in GitHub Desktop.

Select an option

Save codeperfectplus/90c9aaebd77b8e122c57e3a6129e7040 to your computer and use it in GitHub Desktop.
class Solution {
public int reverse(int x) {
StringBuilder s = new StringBuilder();
s.append(Math.abs(x));
s.reverse();
if (s.length() >= 10 ){
int c1 = Integer.parseInt(s.substring(0 , 5) );
int c2 = Integer.parseInt(s.substring(5 , 10) );
if (c1 > 21474 || c2 > 83647){
return 0;
}
}
int num = Integer.parseInt(s.toString());
return (x < 0) ? -num : num ;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment