C# Solution


  • 0
    C
    public class Solution {
        public int Reverse(int x) {
            if( x < -2147483647 || x > 2147483647) return 0;
            Boolean isNegative = x<0 ? true : false;
            x = Math.Abs(x);
            var asCharArray  = ("" +x).ToCharArray();
            Array.Reverse(asCharArray);
            try{
                int ret = Int32.Parse(new String(asCharArray));
                if(isNegative){
                    return ret - (ret *2);
                }
                else{
                    return ret;
                }
            }
            catch(System.OverflowException ex){
                return 0;
            }
        }
    }
    

Log in to reply
 

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