C# Solution


  • 0
    N
    public class Solution {
        public int Reverse(int x) {
            
            var n =0;
            while(x!=0) {
                var mod = x%10;
                x=x/10;
                if (n> Int32.MaxValue/10 || n< Int32.MinValue/10){
                    return 0;
                }
                else if(n==Int32.MaxValue/10 && mod >= Int32.MaxValue %10) {
                    return 0;
                }
                else if(n==Int32.MinValue/10 && mod <= Int32.MinValue %10) {
                    return 0;
                }
                n = n*10 + mod;
            }
            
            return n;
        }
    }
    

Log in to reply
 

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