C# Accepted Solution Handles Minimum Int Value 98% RunTime


  • 0
    L
     public double MyPow(double x, int n) {
            double result = 1;
            
            if(n < 0)
            {
                if(n == Int32.MinValue){
                    result = MyPow(x, n + 1);
                    return result / x;
                }
                n = n * -1;
                x = 1/x;
            }
            
            while(n > 0)
            {
                if((n & 1) == 1)
                {
                    result = result * x;
                }
                
                n = n >> 1;
                x = x * x;
            }
    
            return result;
        }

  • 0
    C

    ... I thought it is a bug that -2147483648 is not a c# int...
    it looks like it is int32


Log in to reply
 

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