C++
1 class Solution {
2 public:
3 /*
4 * @param a: The first integer
5 * @param b: The second integer
6 * @return: The sum of a and b
7 */
8 int aplusb(
int a,
int b) {
9 // write your code here, try to do it without arithmetic operators.
10 int sum = a^
b;
11 int carry = (a&b) <<
1;
12 int tmp;
13 while (carry) {
14 tmp =
sum;
15 sum = tmp^
carry;
16 carry = (tmp&carry) <<
1;
17 }
18 return sum;
19 }
20 };
转载于:https://www.cnblogs.com/CheeseZH/p/4998708.html
相关资源:数据结构—成绩单生成器
转载请注明原文地址: https://win8.8miu.com/read-1494728.html