Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 동시성문제
- 코딩테스트
- 프로그래머스
- DICTIONARY
- java
- reflection
- springMVC
- process
- TCP/IP
- Queue
- green thread
- Split
- frontPattern
- 크기가 작은 부분 문자열
- annotation
- CPU bound
- 문자열
- 가장 가까운 단어
- 2차원 배열 출력
- URL
- stack
- http
- port
- 문자열 내마음대로 정렬하기
- CPU
- IO bound
- dns
- 십진수 이진수 전환
- Spring
- deque
Archives
- Today
- Total
아무나개발하자
다음 큰 숫자 본문
문제
https://school.programmers.co.kr/learn/courses/30/lessons/12911
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
def convert2binary(num):
temp = []
while True:
remainder = num % 2
num = num // 2
temp.append(remainder)
if num < 2:
temp.append(num)
break
temp.reverse()
result = "".join(map(str, temp))
return result
def solution(n):
answer = 0
binary_n = convert2binary(n)
one_count = binary_n.count("1")
while(True):
n += 1
binary_next = convert2binary(n)
one_count_next = binary_next.count("1")
if (one_count == one_count_next):
answer = n
break
return answer
사실 이게 효율성을 통과 할줄은 몰랐다... 방법이 생각이 안나서 그냥 하나하나 비교하는 방법으로 했는데, 통과하더라... 더좋은 방법이 있으면 댓글에 남겨주세요.
출처 : https://school.programmers.co.kr/learn/courses/30/lessons/12911