Created
September 8, 2023 14:28
-
-
Save codeperfectplus/90c9aaebd77b8e122c57e3a6129e7040 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 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