Square Root
MATH
BINARY SEARCH
Problem
Given a non-negative integer x
, return the integer part of its square root. For any non-perfect square, round down to the nearest integer.
Examples:
integerSqrt(4); // 2 integerSqrt(10); // 3 // The square root of 10 is approximately 3.1622, so round down to the nearest integer
Time Complexity
Aim for a time complexity of O(log n)
, where n
is the input integer x
.
Loading...