Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4e5da21

Browse files
Time: 140 ms (80.28%), Space: 34.5 MB (84.51%) - LeetHub
1 parent b30ec2f commit 4e5da21

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import kotlin.math.abs
2+
3+
class Solution {
4+
fun reverse(x: Int): Int {
5+
var origin = abs(x)
6+
var result = 0
7+
8+
while (origin != 0) {
9+
var new = result * 10
10+
if (x < 0) {
11+
new -= origin % 10
12+
}
13+
else {
14+
new += origin % 10
15+
}
16+
17+
if (new / 10 != result) {
18+
return 0
19+
}
20+
21+
result = new
22+
origin /= 10
23+
}
24+
25+
return result
26+
}
27+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /