From 0f9fa38dbf88e90002386c862be02d17c37b38cf Mon Sep 17 00:00:00 2001 From: "Hey :) Harjas Kaur This side" <98317221+harjasgit@users.noreply.github.com> Date: Wed, 5 Oct 2022 19:15:47 +0530 Subject: [PATCH 1/2] Added Binary.cpp code --- .../Add Binary.cpp/harjasgit/README.md | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Remove Numbers from easy/Add Binary.cpp/harjasgit/README.md diff --git a/Remove Numbers from easy/Add Binary.cpp/harjasgit/README.md b/Remove Numbers from easy/Add Binary.cpp/harjasgit/README.md new file mode 100644 index 0000000..81a725d --- /dev/null +++ b/Remove Numbers from easy/Add Binary.cpp/harjasgit/README.md @@ -0,0 +1,35 @@ +# Remove Numbers From Easy +## Added Binary.cpp code +- Written the code of an above issue + + +class Solution { + + +public: + + string addBinary(string a, string b) + { + + + string res; + 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; + res += to_string(sum % 2); + } + + if(carry) res += to_string(carry); + reverse(res.begin(), res.end()); + return res; + + } +}; + + From 1f484fc9b539bdf55fbbd7c5884ed38d31368e6b Mon Sep 17 00:00:00 2001 From: "Hey :) Harjas Kaur This side" <98317221+harjasgit@users.noreply.github.com> Date: Thu, 6 Oct 2022 12:46:07 +0530 Subject: [PATCH 2/2] Update README.md --- .../Add Binary.cpp/harjasgit/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Remove Numbers from easy/Add Binary.cpp/harjasgit/README.md b/Remove Numbers from easy/Add Binary.cpp/harjasgit/README.md index 81a725d..3638af7 100644 --- a/Remove Numbers from easy/Add Binary.cpp/harjasgit/README.md +++ b/Remove Numbers from easy/Add Binary.cpp/harjasgit/README.md @@ -1,3 +1,12 @@ + +QUESTION : Problem Statement: Given two binary strings a and b, return their sum as a binary string. +Example: +Input: a = "1010", b = "1011" +Output: "10101" + + + + # Remove Numbers From Easy ## Added Binary.cpp code - Written the code of an above issue