forked from BigEggStudy/LeetCode-CS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path007-ReverseInteger.cs
More file actions
30 lines (26 loc) · 808 Bytes
/
007-ReverseInteger.cs
File metadata and controls
30 lines (26 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//-----------------------------------------------------------------------------
// Runtime: 40ms
// Memory Usage: 14.6 MB
// Link: https://leetcode.com/submissions/detail/359575927/
//-----------------------------------------------------------------------------
namespace LeetCode
{
public class _007_ReverseInteger
{
public int Reverse(int x)
{
var result = 0;
var positiveOverflow = int.MaxValue / 10;
var nagativeOverflow = int.MinValue / 10;
for (; x != 0; x /= 10)
{
if (result > positiveOverflow || result < nagativeOverflow)
{
return 0;
}
result = result * 10 + x % 10;
}
return result;
}
}
}