1 static int wing=[]() 2 { 3 std::ios::sync_with_stdio(false); 4 cin.tie(NULL); 5 return 0; 6 }(); 7 8 class Solution 9 { 10 public: 11 int getSum(int a, int b) 12 { 13 return b==0?a:getSum(a^b, (a&b)<<1); 14 } 15 };
就是位操作,原理描述起来有点费劲,自行百度吧
1 static int wing=[]() 2 { 3 std::ios::sync_with_stdio(false); 4 cin.tie(NULL); 5 return 0; 6 }(); 7 8 class Solution 9 { 10 public: 11 int getSum(int a, int b) 12 { 13 return b==0?a:getSum(a^b, (a&b)<<1); 14 } 15 };
就是位操作,原理描述起来有点费劲,自行百度吧