class Solution { public: int mysqrt(int x) { if( x == 0 || x == 1) return x; //处理特殊情况 int top = x / 2; cout<< top<<endl; int ans; for(int i = 1; i <= top; i++){ if(i * i == x ){ ans = i; break; } else if(i * i > x){ if((i - 1) * (i - 1) < x) ans = i - 1; break; } } return ans; } };