반응형
https://leetcode.com/problems/add-binary/
이진수 변환 문제였습니다.
📕 풀이방법
📔 풀이과정
1. binary string인 a, b를 10진수로 변환 후 더해줍니다.
2. 더해준 값을 다시 binary string으로 바꾸고 2번째 문자까지 slice한 문자를 반환합니다.
📕 Code
📔 python
class Solution:
def addBinary(self, a: str, b: str) -> str:
a = int(a, 2)
b = int(b, 2)
return bin(a + b)[2:]
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Implementation' 카테고리의 다른 글
(C++) - LeetCode (easy) 118. Pascal's Triangle (0) | 2022.11.27 |
---|---|
(C++) - LeetCode (easy) 69. Sqrt(x) (0) | 2022.11.10 |
(Python) - LeetCode (easy) 66. Plus One (0) | 2022.11.08 |
(C++) - LeetCode (easy) 13. Roman to Integer (2) | 2022.10.11 |
(C++) - 백준(BOJ) 3533 : Explicit Formula (0) | 2022.10.07 |