【例题1】2235. 两整数相加 - 力扣(LeetCode)
int sum(int num1, int num2){
return num1+num2;
}
【例题2】1812. 判断国际象棋棋盘中一个格子的颜色 - 力扣(LeetCode)
bool squareIsWhite(char * coordinates){
switch(coordinates[0]){
case 'a': case 'c': case 'e': case 'g':
if(((int)*(coordinates+1)) % 2 == 0){
return true;
}
break;
default:
if (((int)*(coordinates+1)) % 2 != 0){
return true;
}
}
return false;
}
【例题3】2651. 计算列车到站时间 - 力扣(LeetCode)
int findDelayedArrivalTime(int arrivalTime, int delayedTime){
return (arrivalTime+delayedTime)%24;
}
【例题4】191. 位1的个数 - 力扣(LeetCode)
int hammingWeight(uint32_t n) {
int num = 32;
int count = 0;
while(num-- > 0){
if (n%2==1){
count++;
}
n = n>>1;
}
return count;
}
【例题5】461. 汉明距离 - 力扣(LeetCode)
int hammingDistance(int x, int y){
int z = x ^ y;
int num = 32;
int count = 0;
while(num-- > 0){
if (z % 2 == 1){
count++;
}
z /= 2;
}
return count;
}
【例题6】面试题 17.01. 不用加号的加法 - 力扣(LeetCode)
int add(int a, int b){
while( b!=0 ){
unsigned int key = (unsigned int)(a & b)<<1;
a = a^b;
b = key;
}
return a;
}