Missed case of pow(0,0)?


  • 1
    R

    This code is accepted as 0^0 is not taken account in the test cases?

    class Solution {
    public:
        double pow(double x, int n) {
            if (n < 0){
                return 1.0/power(x, -n);
            }
            else{ 
                return power(x, n);
            }
        }
    private:
        double power(double x, int n){
            if(x==0 && n==0) return 1;
            if(n == 0) return 1;
            double v = power(x, n/2);
            if (n%2 == 0)    
                return v*v;
            else
                return v*v*x;
        }
    };

  • 0
    L

    0^0 is mathematically indeterminate. Like 0/0 if you want. However, there are many good reasons to define 0^0 = 1, fewer reasons to define 0^0 = 0. I think it's not in the test cases to avoid lengthly discussions on how to define 0^0.


Log in to reply
 

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