Google Interview Question - Sum of Two Integers - LeetCode 371

preview_player
Показать описание


Step by step walk through of the solution to the popular Google coding interview question, Sum of Two Integers.

LeetCode 371

JavaScript

0:00 Intro
0:16 Explanation
2:43 Code

#softwareengineering #javascript #leetcode
Рекомендации по теме
Комментарии
Автор

I have no idea why this has Less views. Other people making 20 minutes videos on same question.

saadanees
Автор

Hey AlgoJS. Thank you so much for sharing this information and answer. My question is, what would be a common usage for the << and ^ symbols. TBH I do not understand what they mean.

GraceandWisdom
Автор

doesn't work for negative numbers in python,
my solution in python:

class Solution:
def getSum(self, a: int, b: int) -> int:
# 32 bits integer max
MAX =
# Mask to get 32 bits
MASK =


while b != 0:
# Calculate carry
carry = (a & b) << 1
# Sum of bits where at least one is not set
a = (a ^ b) & MASK
# Assign carry to b
b = carry & MASK


# if a is negative, return a's 32-bit complement form
return a if a <= MAX else ~(a ^ MASK)

danielziv