MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / reverse

Method reverse

Java/reverse-integer.java:9–26  ·  view source on GitHub ↗
(int x)

Source from the content-addressed store, hash-verified

7*/
8class Solution {
9 public int reverse(int x) {
10 StringBuilder sb = new StringBuilder(""+x);
11 sb.reverse();
12 String str = sb.toString();
13
14 if(str.charAt(str.length()-1) == '-') {
15 str = "-" + str.substring(0, str.length()-1);
16 }
17 int ans = 0;
18
19 try{
20 ans = Integer.parseInt(str);
21 } catch(Exception ex){
22 return 0;
23 }
24
25 return ans;
26 }
27}

Callers 1

addTwoNumbersMethod · 0.45

Calls 1

lengthMethod · 0.80

Tested by

no test coverage detected