Add Binary | LeetCode 67 | C++, Java, Python

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

**** Best Books For Data Structures & Algorithms for Interviews:**********
*****************************************************************************

July LeetCoding Challenge | Problem 19 | Add Binary | 19 July,
Facebook Coding Interview question,
google coding interview question,
leetcode,
Add Binary,
Add Binary c++,
Add Binary Java,
Add Binary python,
Add Binary solution,
67. Add Binary,

#CodingInterview #LeetCode #JulyLeetCodingChallenge #Google #Amazon #AddBinary #BinaryAddition
Рекомендации по теме
Комментарии
Автор

Could not understand the code explanation

devanshmudgal
Автор

Your videos are really helpful. It does not matter whether the problem is easy or complex but the way you solve it, teaches me something new. Thanks a lot!

srikantsharma
Автор

Always something to learn from sir's videos. I used to always get stuck in this type of problems but now I know better all because of sir. Thank you so much sir ji ❤️

agileprogramming
Автор

Hello sir....could you plz explain the line no. 9 again(i.e. why did you subtract '0' from a[i])?

manasvishahi
Автор

Hi Sir, Can you do some code run or solve questions of leetcode weekly or bi-weekly contest. Because the third or fourth questions are tough to solve, and your explanation is better and easy to understand than those of other pro leetcoders. Thanks in advance.

tusharsinha
Автор

Why did we do if(i>=0) sum+= a[i--] - '0' ?? how are we adding string a[i] to int sum ?? and why are we subtracting - '0'??

Thanks for the great solution!!

shubhamgawle
Автор

how can we do this by using push_back?
like when i writing
in place of result+=to_string(sum%2), i am getting output as this "))" brackets??

deepakgurjar
Автор

Thank you sir for the explanation...
can you mention what's the time n space complexities..?

ranasauravsingh
Автор

sir what's the use of this line =>
result += str(sum%2)

siddharthsingh
Автор

Sir but 0+1 1 hoga na and 1+1 zero correct he kya .He rule addition me bhi chalat hai kya?
Pls reply me soon.

vipulpatil
Автор

I did not get the carry part .... carry = sum>1 ?1:0
if 1001 +1010 -> if we consider last digit i.e 1+0 = 1 here sum is 1 then carry should be 0 ...
according to ur statement if sum = 1 the carry should be one ...
can u please explain this

an
Автор

can we pay for your membership? This is so good!

zhenyuzhang
Автор

Yours video is always nice to understand

uavishal
Автор

Nice explanation are doing a great job.

paragroy
Автор

Sir please make Codeforces problems also for atleast div 3 for people like us
Those are very hard to get the logic for beginners
I was able to solve 2 questions out of 7

midhileshmomidi
Автор

Hi, could you please tell why have you took i and j as a.length()-1 and b.length()-1 respectively, shouldn't their values be a.length() and b.length() . As indexing if string starts from 1 and not 0 . Could you please clear this?

gta
Автор

Can u share the code also for reference

Pritamdaspk
Автор

why does your video reload so much in between? it is so irruitating

pleasesirmorevideos
Автор

class Solution {
public:
string addBinary(string a, string b) {
string result;
int i = a.length() - 1;
int j = b.length() - 1;
int carry = 0;
while(i >= 0 || j >= 0) {
int sum = carry;
if(i>=0)
sum += a[i--] - '0';
if(j>=0)
sum += b[j--] - '0';
carry = sum > 1 ? 1 : 0;
result += to_string(sum%2);
}
if(carry) result += to_string(carry);
reverse(result.begin(), result.end());
return result;
}

};

tisitabarman
Автор

3 liner
a = int(a, 2)
b = int(b, 2)
return bin(a+b)[2:]

siddharthsingh
welcome to shbcf.ru