class Solution
{
public:
int mySqrt(int x)
{
int s = 0, e = x;
int ans = 0;
while (s <= e)
{
long long mid = (s + e) / 2;
if (mid * mid > x)
e = mid - 1;
else
{
ans = mid;
s = mid + 1;
}
}
return ans;
}
};
'코딩테스트 > LeetCode' 카테고리의 다른 글
[LeetCode] 1 - Two Sum (0) | 2024.04.03 |
---|---|
[LeetCode] 6 - Zigzag Conversion (0) | 2024.04.03 |
[LeetCode] 153. Find Minimum in Rotated Sorted Array (0) | 2024.03.05 |
[LeetCode] Majority Element (0) | 2023.12.19 |
[LeetCode] Remove All Adjacent Duplicates in String II (0) | 2023.12.12 |