• 문제 링크
Sqrt(x) - LeetCode
Can you solve this real interview question? Sqrt(x) - Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well. You must not use any built-in exponent function or o
leetcode.com
• 풀이 코드
public class Solution {
public int mySqrt(int x) {
long n = x;
while (n * n > x) n = (n + x / n) >> 1;
return (int) n;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 67. Add Binary - Java (0) | 2026.05.21 |
|---|---|
| [LeetCode] 66. Plus One - Java (0) | 2026.05.20 |
| [LeetCode] 58. Length of Last Word - Java (0) | 2026.05.19 |
| [LeetCode] 35. Search Insert Position - Java (0) | 2026.05.18 |
| [LeetCode] 24. Swap Nodes in Pairs - Java (0) | 2026.05.17 |
댓글