Another approach


  • 0
    A

    public class Solution {
    public int mySqrt(int x) {
    if (x == 0){
    return 0;
    }

     if (x == 1){
       return 1;
     }   
     int i = 1;
     int count = 0;
     int num = x;
    
     while (num > 0){
          num = num - i;
          i+=2;
          if (num >= 0){
            count++;
          }
      }  
        return count;
    }
    

    }


Log in to reply
 

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