LeetCode 썸네일형 리스트형 AddDigit Problem Given an integer num, repeatedly add all its digits until the result has only one digit, and return it. 정수 값이 들어오면 정수값을 포함하고 있는 자리수의 모든 값들의 합이 하나만 남을때까지 반복하여 더하고 그 값을 반환하는 문제 38 → 3 + 8 → 11 → 1 + 1 → 2 → return 2 Solution class Solution: def addDigits(self, num: int) -> int: res = num while res > 9: res_list = list(str(res)) result = 0 for i in res_list: result += int(i) res = result re.. 더보기 AddBinary Problem Given two binary strings a and b, return their sum as a binary string. 스트링으로 구성된 바이너리 a,b가 input으로 들어오면 두 바이너리의 합을 string값으로 돌려주는 문제 “11”, “1” 이 들어오면 바이너리의 합인 “100” 을 출력하라! Solution class Solution: def add_bianry(self, a: str, b: str) -> str: a_list = list(a) b_list = list(b) carry = 0 result = '' while a_list or b_list or carry: if a_list: carry = carry + int(a_list.pop()) if b_list: ca.. 더보기 이전 1 다음