LeetCode 69. Sqrt(x) (Java)



Implement int sqrt(int x).

Compute and return the square root of x.

x is guaranteed to be a non-negative integer.

Example 1:

Example 2:


We can convert square root from a math problem to a computer science problem. To find a square root is actually to search for a number among 0 to x. Just use binary search to solve the problem.

Video Tutorial

Java Solution

Leave a Reply

Your email address will not be published. Required fields are marked *