1. Description
Given two binary string a and b, return their sums as a binary string.
constraints :
- 1 <= a.length, b.length <= 104
- a and b consist only of '0' or '1' characters.
- Each string does not contain leading zeros except for the zero itself.
2. Algorithms
Python's built-in function int() can change input string into number system what we want. And also, built-in function format() can change int into string number system what we want.
3. Codes
class Solution:
def addBinary(self, a: str, b: str) -> str:
return format(int(a, 2) + int(b, 2), 'b')
4. Conclusion
'LeetCode > Easy' 카테고리의 다른 글
70 Climbing Stairs (0) | 2022.07.22 |
---|---|
69 Sqrt(x) (0) | 2022.07.21 |
66 Plus One (0) | 2022.07.21 |
58 Length of Last Word (0) | 2022.07.20 |
35 Search Insert Position (0) | 2022.07.20 |