GoConqr has a new look! Let us know what you think.

Flashcards

Sqrt(x)

Suhas S English 1 card

Cards in this deck (1)

  1. 1In while, If mid < sqrt(x), left = mid + 1 executed, right pointer is not moving, and right is the answer. If while, If mid > sqrt(x), right = mid - 1 executed, right pointer shifts left 1, closest to sqrt(x), right is also the answer.class Solution {
    public int mySqrt(int x) {
    if( x == 0 )return 0;
    int left = 1; int right = x;
    while(left<= right){
    int mid = left + (right - left)/2;
    if(mid == x/mid) return mid;
    if(mid < x/mid) left = mid + 1;
    else right = mid - 1;
    }
    return right;
    }
    }

Information

Description
Flashcards on Sqrt(x), created by Suhas S on 23/03/2018.
Created by
Suhas S
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?