MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / reverse

Method reverse

java/0007-reverse-integer.java:3–18  ·  view source on GitHub ↗
(int x)

Source from the content-addressed store, hash-verified

1class Solution {
2
3 public int reverse(int x) {
4 boolean isNegative = x < 0;
5
6 x = Math.abs(x);
7
8 int num = 0;
9
10 while (x > 0) {
11 if (Integer.MAX_VALUE / 10 < num) return 0;
12
13 num = 10 * num + x % 10;
14 x /= 10;
15 }
16
17 return isNegative ? -num : num;
18 }
19}

Callers 15

replaceElementsFunction · 0.45
findOrderFunction · 0.45
bfsFunction · 0.45
sortedSquaresFunction · 0.45
reverseFunction · 0.45
topKFrequentFunction · 0.45
addToArrayFormFunction · 0.45
alienOrderFunction · 0.45
replaceElementsFunction · 0.45
multiplicationFunction · 0.45
reverseFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected