코테준비 - Sqrt(x)

정상화·2023년 2월 26일

LeetCode

목록 보기
66/222

Sqrt(x)

class Solution {
public:
    int mySqrt(int x) {
        double pivot = INT32_MAX / 2;

        for (int i = 0; i < 500; i++) {
            pivot = (pivot + (double) x / pivot) / 2;
        }

        return (int) pivot;
    }
};
profile
백엔드 희망

0개의 댓글