← All problems

Sqrt(x) without built-ins

Easy searchingmath LeetCode ↗
Compute the integer square root of a non-negative integer x: the largest integer r such that r*r <= x. Do not use built-in exponent or root functions; x can be up to 2^31 - 1, so watch for overflow.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(log x), Space O(1)

Common pitfalls

  • mid*mid overflow
  • Float precision issues

Your solution

Log in to save your code and track progress.