抗日奇侠 下载,金钱之味快播,环保意识
write a function that add two numbers a and b.
are a and b both 32-bit
integers?
can i use bit operation?
given a=1
and b=2
return 3
.
of course you can just return a + b to get accepted. but can you challenge not do it like that?(you should not use +
or any arithmetic operators.)
using a recursion method to solve this problem!
1 /** 2 * @param a: an integer 3 * @param b: an integer 4 * @return: the sum of a and b 5 */ 6 int aplusb(int a, int b) { 7 // recursion process 8 if ( (a & b) == 0 ){ 9 return a ^ b; 10 } else { 11 return aplusb( (a^b), ((a&b)<<1) ); 12 } 13 }
it's not the only way to get the right answer. can you try the other way like the loop structure?
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
如何在没有core文件的情况下用dmesg+addr2line定位段错误
用QT制作3D点云显示器——QtDataVisualization
网友评论