Possible lot of precision , it says, but it seems the solution is correct. (Can any one help)


  • 0
    V

    public class Solution {
    public int sqrt(int x) {
    int start = 0;
    int finale = x;
    while(start<finale)
    {

            float mid = (start+finale)/2;
            
            float diff = (mid*mid)-x;
            if(Math.abs(diff)<0.000000000001)
            return(int) mid;
            else if (diff > 0)
               finale = mid-1;
            else if(diff<0)
              start = (mid+1);
        }
      return -1;  
    }
    

    }


Log in to reply
 

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