题解 | #不用加减乘除做加法#
不用加减乘除做加法
https://www.nowcoder.com/practice/59ac416b4b944300b617d4f7f111b215
class Solution { public: int Add(int num1, int num2) { while(num2!=0){ int t1,t2; t1=num1^num2; t2=num1&num2; num1=t1; num2=t2<<1; } return num1; } };
不用加减乘除做加法
https://www.nowcoder.com/practice/59ac416b4b944300b617d4f7f111b215
class Solution { public: int Add(int num1, int num2) { while(num2!=0){ int t1,t2; t1=num1^num2; t2=num1&num2; num1=t1; num2=t2<<1; } return num1; } };
相关推荐