367.有效的完全平方数
题目链接
static const auto io_speed_up = []()
{
ios::sync_with_stdio(0);
cin.tie(0);
return 0;
}();
class Solution {
public:
bool isPerfectSquare(int num) {
double ans = num;
while(ans * ans - num > 0.5){
ans = (ans + num/ans) / 2.0;
}
if((int)ans * (int)ans == num)return 1;
return 0;
}
};
371.两整数之和
题目链接
没有-0这一说,所以会报错,所以用unsigned int
class Solution {
public:
int getSum(int a, int b) {
int c;
while(b){
c = (unsigned int)(a&b)<<1;
a ^= b;
b = c;
}
return a;
}
};