We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5cd52d6 commit 05a6e0cCopy full SHA for 05a6e0c
1 file changed
sum-of-two-integers/PDKhan.cpp
@@ -0,0 +1,29 @@
1
+class Solution {
2
+ public:
3
+ int getSum(int a, int b) {
4
+ unsigned int result = 0;
5
+ int carry = 0;
6
+
7
+ for(int i = 0; i < 32; i++){
8
+ unsigned int aa = a & (1U << i);
9
+ unsigned int bb = b & (1U << i);
10
11
+ if(aa && bb){
12
+ if(carry)
13
+ result |= (1U << i);
14
15
+ carry = 1;
16
+ }else if(aa == 0 && bb == 0){
17
18
19
20
+ carry = 0;
21
+ }else{
22
+ if(carry == 0)
23
24
+ }
25
26
27
+ return result;
28
29
+ };
0 commit comments