Sum of Two Integers Without Arithmetic Operator || LeetCode Sum of Two Integers 371

preview_player
Показать описание
🈚️ BEST RESOURCES FOR SOFTWARE ENGINEERING PREP

✅️ Blind 75 LeetCode Questions - Udemy Course:

✅️ Grokking Dynamic Programming Patterns - Udemy Course

371. Sum of Two Integers. Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.

Example 1:
Input: a = 1, b = 2
Output: 3

Example 2:
Input: a = -2, b = 3
Output: 1

++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++
#LeetCode #CSNinja
Рекомендации по теме
Комментарии
Автор

Finally found a video that explains the XOR and AND operator thoroughly..

edwardteach
Автор

Very precise and detailed explaination .thanks for the solution 😀

sa
Автор

It won't work when both the numbers are equal and of opposite signs. For ex - (-1, 1).
It"ll give runtime error in c++, works fine in Java.

AkashVerma-worh
Автор

Thanks a lot. Its working perfectly fine!! short and very well explained solution !!

priyankagupta
Автор

The above code does NOT work if b is -ve and a is > 40 a=50, b=-3

def add(a, b):
if a == 0:return b
if b == 0:return a
axorb=a^b
carry=a&b
if carry == 0:
return axorb
else:
return add(axorb, carry<<1)



print(add(50, -3) )

Recrsion depth Error The code has a strange bug

zameerahmed
Автор

wow, amazing explained it well. Tysm 😍

dineshkumark
Автор

Doesn't work for negative integers, since left shift operator on negative integers is not standardized and would give different answers based on compiler.

kalashnikov
Автор

Baki sab to sahi hai bas agli baar se muh se paan thuk ke video banana dost :-)

namandaga