일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Writing
- Problem Solving
- 화상영어
- 파비최
- FIT XR
- 괜찮음
- 3줄정리
- 30분
- English
- 사이드
- 뭐든
- 매일
- 개발자
- 영어공부
- 링피트
- 리얼 클래스
- 읽기
- 만화도
- 미드시청
- 잡생각
- 스탭퍼
- realclass
- 운동
- 쓰릴오브파이트
- 월간
- 영어원서읽기
- Daily Challenge
- 10분
- leetcode
- 프로젝트
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