Solution in C#


  • 0
    K
    public class Solution {
        public int Reverse(int x) {
            if (x == Int32.MaxValue || x == Int32.MinValue) return 0;
            var charArray = Math.Abs(x).ToString().ToCharArray();
            Array.Reverse(charArray);
            var result = Int64.Parse(new string(charArray));
            if (result >= Int32.MaxValue) return 0;
            return x>=0?(int)result:(int)-result;
        }
    }
    

Log in to reply
 

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