first problems

This commit is contained in:
2023-11-22 11:52:21 -05:00
parent 396460bcd3
commit ccca2169f0
8 changed files with 106 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
class Solution:
def addBinary(self, a: str, b: str) -> str:
a = a[::-1]
b = b[::-1]
carry = 0
c = ""
for i in range(max(len(a), len(b))):
d = carry + int(a[i]) + int(b[i])
if d == 3:
c = c + "1"
carry = 1
if d == 2:
c = c + "0"
carry = 1
if d == 1:
c = c + "1"
carry = 0
if d == 0:
c = c + "0"
carry = 0
else:
print(d)
raise Exception
return(c[::-1])
+5
View File
@@ -0,0 +1,5 @@
import Solution
s = Solution.Solution()
print(s.addBinary("11", "1"))