문제링크: 3진법 뒤집기
✍🏻 Information
| content | |
|---|---|
| 언어 | python |
| 난이도 | ⭐️ |
| 풀이시간 | 15분 |
| 제출횟수 | 1 |
| 인터넷검색유무 | yes |
🍒 My Code
def solution(n):
answer = 0
three = []
a, b = n, n
while a!=0:
b = a%3
a = a//3
three.insert(0,b)
three.reverse()
for i in range(len(three)-1,-1,-1):
square = len(three)-i-1
answer+=three[i]*(3**square)
return answer
💡 What I learned
while a!=0:
b = a%3
a = a//3
three=b+three
for i in three:
reverse = i + reverse
int(string, 진법)하면 10진법으로 출력해주는 기능이 있었다..def solution(n):
tmp = ''
while n:
tmp += str(n % 3)
n = n // 3
answer = int(tmp, 3)
return answer