Wht time limited exceed in this C code?


  • 0
    A

    int maxDiv(int a, int b);
    bool isUgly(int num) {

     int no=0;
     no = maxDiv(num,2);
     no = maxDiv(no,3);
     no = maxDiv(no,5);
     return (no == 1) ? 1:0;
    

    }

    int maxDiv(int a, int b)
    {
    while(a%b==0)
    a = a/b;
    return a;
    }


  • 0
    C

    when num's value is 0, then maxDiv function get a dead loop.


Log in to reply
 

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