2235. Add Two Integers 發表於 2023-02-13 | 分類於 leetcode problemsolutionoption 1 - native123456class Solution {public: int sum(int num1, int num2) { return num1+num2; }}; option 2 - without +12345678910111213class Solution {public: int sum(int num1, int num2) { while(num2!=0){ unsigned int total = num1^num2; unsigned int carry = num1&num2; num1 = total; num2 = carry<<1; } return num1; }}; 12345678910class Solution {public: int sum(int num1, int num2) { while(num2){ int carry = (num1&num2&0x7fffffff)<<1, total = num1^num2; num2 = carry, num1 = total; } return num1; }};