-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverseInteger.cs
More file actions
47 lines (44 loc) · 1.03 KB
/
Copy pathreverseInteger.cs
File metadata and controls
47 lines (44 loc) · 1.03 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace reverseInteger
{
class Program
{
static void Main(string[] args)
{
//int temp = int.MaxValue;
//int num = temp * 2;
//int num = -12010;
Console.WriteLine(Reverse(1534236469));
}
public static int Reverse(int x)
{
if( (x * 2) / 2 != x)
{
return 0;
}
if (x >= 0)
{
return Reverse_sub(x);
}
else
{
return -Reverse_sub(-x);
}
}
public static int Reverse_sub(int x)
{
int rev_x = 0;
while (x / 10 != 0)
{
rev_x = rev_x * 10 + x % 10;
x = x / 10;
}
rev_x = rev_x * 10 + x;
return rev_x;
}
}
}