程式語言 - LeetCode - C++ - 69. Sqrt(x)



參考資訊:
https://www.cnblogs.com/grandyang/p/4346413.html

題目:


解答:

class Solution {
public:
    int mySqrt(int x) {
        for(int i = 1; i <= x; ++i){
            long t = (long)i * i;
    
            if (t == x) {
                return i;
            }
            else if (t > x) {
                return i - 1;
            }
        }

        return 0;
    }
};