Movatterモバイル変換


[0]ホーム

URL:


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

Commit8ba5926

Browse files
committed
Create 7-Reverse-Integer.cs
1 parent2c47cad commit8ba5926

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎csharp/7-Reverse-Integer.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
publicclassSolution{
2+
publicintReverse(intx){
3+
intrev=0;
4+
5+
while(x!=0){
6+
vardigit=x%10;
7+
x=x/10;
8+
if(rev>Int32.MaxValue/10||
9+
// since max value is 2,147,483,647,
10+
// last digit greater than 7 will overflow
11+
(rev==Int32.MaxValue/10&&digit>7))
12+
return0;
13+
14+
if(rev<Int32.MinValue/10||
15+
// since min value is -2,147,483,648
16+
(rev==Int32.MinValue/10&&digit<-8))
17+
return0;
18+
19+
rev=rev*10+digit;
20+
}
21+
22+
returnrev;
23+
}
24+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp