Beat 100% csharp submisions


  • 0
    L
            public int Reverse(int x)
            {
                if (x == 0) return 0;
                bool flag = x > 0;
                int value = flag ? x : -x;
                long result = 0;
                while (value > 0)
                {
                    int num = value % 10;
                    value = value / 10;
                    result = result * 10 + num;
                    if (result > int.MaxValue) return 0;
                }
    
                return (int)(flag ? result : -result);
            }
    

Log in to reply
 

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