A C# solution using 66ms


  • 0
    O
    public class Solution {
        public int Reverse(int x) {
           long result = 0;
           do
           {
                result = x % 10 + result * 10;
                x = x / 10;
           }while(x != 0);
          
           if(result > (long)int.MaxValue || result < (long)int.MinValue)
           {
               result = 0;
           }
           return (int)result;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.