티스토리 뷰
반응형
Description
Given two binary strings, return their sum (also a binary string).
The input strings are both non-empty and contains only characters 1 or 0.
Answer
class Solution:
def addBinary(self, a: str, b: str) -> str:
i = int(a,2)
j = int(b,2)
# ans = i+j
# return bin(ans)[2:]
return format(i+j,'b')
진수 변환
>> bin(30)
'0b1110'
>> oct(30)
'0o36'
>> hex(30)
'0x1e'
Format 함수
# 접두어 제외하기
>> format(0b11110, 'b')
'11110'
# 접두어 포함
>> format(30, '#b')
'11110'
반응형
'Development > Algorithms' 카테고리의 다른 글
| Valid Palindrome in python3 (0) | 2020.07.29 |
|---|---|
| Leetocode 378 Kth Smallest Element in a Sorted Matrix (2) | 2020.06.22 |
| Leetcode No. 234 && 206 Linked List basic Problem (1) | 2020.06.09 |
| Leetcode 35 Search insert Position (2) | 2020.06.08 |
| Leetcode 93. Restore IP address (0) | 2020.06.06 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- Python
- collator
- go
- 한빛미디어
- Shell
- book
- 나는리뷰어다
- Gemma
- Fine-Tuning
- LLM
- Git
- docker
- 파이썬
- error
- Algorithm
- Binary
- kubens
- Container
- 책리뷰
- leetcode
- BASIC
- K8S
- Kubernetes
- kubernetes context
- lllm
- feed-forward
- csv
- palindrome
- AWS
- 키보드
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
글 보관함
반응형