Notice
														
													
												
											
												
												
													Recent Posts
													
											
												
												
													Recent Comments
													
											
												
												
											            
									| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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
													
											
												
												- programmers
- 맥북
- dacon
- SW Expert Academy
- hackerrank
- 자연어처리
- github
- Docker
- AI 경진대회
- 편스토랑 우승상품
- 데이콘
- Kaggle
- 코로나19
- Baekjoon
- 편스토랑
- 우분투
- Real or Not? NLP with Disaster Tweets
- Git
- ubuntu
- ChatGPT
- 프로그래머스 파이썬
- leetcode
- 백준
- 금융문자분석경진대회
- 캐치카페
- 파이썬
- 프로그래머스
- PYTHON
- gs25
- 더현대서울 맛집
													Archives
													
											
												
												- Today
- Total
솜씨좋은장씨
[leetCode] 504. Base 7 (Python) 본문
728x90
    
    
  반응형
    
    
    
  
Given an integer, return its base 7 string representation.
Example 1:
Input: 100
Output: "202"Example 2:
Input: -7
Output: "-10"Note: The input will be in range of [-1e7, 1e7].
Solution
class Solution:
    def convertToBase7(self, num: int) -> str:
        if num == 0:
            return str(num)
        
        sign = 1 
        if num < 0:
            sign = -1
            
        num = abs(num)
        answer = ''
        
        while num:
            answer = str(num % 7) + answer
            num //= 7
            
        return ('-' if sign < 0 else '') + answer
SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
| [leetCode] 347. Top K Frequent Elements (Python) (0) | 2020.10.14 | 
|---|---|
| [leetCode] 442. Find All Duplicates in an Array (Python) (0) | 2020.10.13 | 
| [leetCode] 1470. Shuffle the Array (Python) (0) | 2020.10.10 | 
| [leetCode] 896. Monotonic Array (Python) (0) | 2020.10.09 | 
| [leetCode] 258. Add Digits (Python) (0) | 2020.10.08 | 
								  Comments
								
							
						
					
                    
                
					
					
					
					
					
					
				 
						
					 
					 
													 
													 
													