| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- Writing
- realclass
- 미드시청
- English
- 뭐든
- 10분
- Problem Solving
- 개발자
- 링피트
- 프로젝트
- 영어원서읽기
- 영어공부
- 쓰릴오브파이트
- 30분
- 스탭퍼
- 읽기
- FIT XR
- 매일
- 운동
- 사이드
- 괜찮음
- leetcode
- 잡생각
- 만화도
- 3줄정리
- 화상영어
- Daily Challenge
- 파비최
- 월간
- 리얼 클래스
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers/
Concatenation of Consecutive Binary Numbers - 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
주어진 조건으로 그냥 풀면 TLE가 남.. 그래서 뒷자리 몇개를 잘라 봤는데 값이 이상하게 나옴.
결국 또 솔루션 확인 ㅠ_ㅠ
'''
# WRONG ANSWER
class Solution:
def concatenatedBinary(self, n: int) -> int:
b = ''
for i in range(n, 0, -1):
b = bin(i).replace('0b', '') + b
return int('0b' + b, 2) % (10**9 + 7)
'''
이상하네.. 정방향으로 하면 문제 없이 풀림 =_=
뭐 땜시 그러는거지..
class Solution:
def concatenatedBinary(self, n: int) -> int:
b = ''
for i in range(1, n+1):
b += format(i, 'b')
return int(b, 2) % (10**9 + 7)반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| Today's Challenge (0) | 2022.09.25 |
|---|---|
| Today's Challenge (0) | 2022.09.24 |
| Today's Challenge (0) | 2022.09.22 |
| Today's Challenge (0) | 2022.09.21 |
| Today's Challenge (2) | 2022.09.20 |
Comments