-
Notifications
You must be signed in to change notification settings - Fork 0
69_Sqrt(x)
a920604a edited this page Apr 14, 2023
·
1 revision
class Solution {
public:
int mySqrt(int x) {
if(x< 2) return x;
int ret = 0, i ;
for(i=1;i*i<=x;++i){
if(i+1> INT_MAX/(i+1)) return i;
}
return i-1;
}
};
- time complexity
O(sqrt(n))
O(logn)
- space complexity
O(1)
footer