본문 바로가기

Algorithm/Implementation

(Python) - LeetCode (easy) 67. Add Binary

반응형

https://leetcode.com/problems/add-binary/

 

Add Binary - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

이진수 변환 문제였습니다.

📕 풀이방법

📔 풀이과정

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:]

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.