Problem Solving/LeetCode
2023.02.14 Today's Challenge
fabichoi
2023. 2. 14. 23:45
https://leetcode.com/problems/add-binary/
Add Binary - LeetCode
Can you solve this real interview question? Add Binary - Given two binary strings a and b, return their sum as a binary string. Example 1: Input: a = "11", b = "1" Output: "100" Example 2: Input: a = "1010", b = "1011" Output: "10101" Constraints: *
leetcode.com
파이썬 내장 함수를 활용하면 매우 편하게 풀 수 있음.
class Solution:
def addBinary(self, a: str, b: str) -> str:
return bin(int(a, 2) + int(b, 2))[2:]
반응형