Skip to content

Instantly share code, notes, and snippets.

@u8989332
Created October 11, 2020 12:22
Show Gist options
  • Save u8989332/0a769c5c11b406a93bded3cb51222d8e to your computer and use it in GitHub Desktop.
Save u8989332/0a769c5c11b406a93bded3cb51222d8e to your computer and use it in GitHub Desktop.
LeetCode - 7 Reverse Integer
using System;
namespace LeetCode7
{
public class Solution {
public int Reverse(int x) {
long ans = 0;
while(x != 0){
ans = ans * 10 + (x % 10);
x /= 10;
}
return Math.Abs(ans) > Int32.MaxValue ? 0 : (int)ans;
}
}
public class Program
{
public static void Main()
{
Solution sol = new Solution();
Console.WriteLine(sol.Reverse(123));
Console.WriteLine(sol.Reverse(-123));
Console.WriteLine(sol.Reverse(1234567899));
Console.Read();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment