Adding Binary Numbers in JavaScript (LeetCode 67)

preview_player
Показать описание
We go over how to add binary numbers as integers and BigInts in JavaScript
Рекомендации по теме
Комментарии
Автор

I appreciate you walking through this!

ryanscoville
Автор

Brilliant. Learn something new everyday!! Thanks

msaurabh
Автор

This is a great explanation, thanks man

ryanxvx
Автор

12:16
"You can try to compare if you want" laughs*
this man is evil. he knows no one will dare to compare this so he mocked us 🤣

Great explanation. Super easy man

thakursaad
Автор

I don't believe this should be labeled easy. Sure the solution is easy enough to implement, but getting to the correct solution requires trial and error and research. Should be a medium question.

bigkurz
Автор

Would you not want to change a.length < 53 to (a.length +b.length) <53 . Since you are adding numbers wouldn't you have to be afraid that the added numbers are going to break the max safe integer size?

var addBinary = function(a, b) {
let sum =0

if(a.length+b.length < 53){
return sum = (parseInt(a, 2)+parseInt(b, 2)).toString(2)
}else{
sum = BigInt("0b"+a) +BigInt("0b"+b)
return sum.toString(2)
}

};

LSUHEBERT
welcome to shbcf.ru