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 | 31 |
Tags
- geometry
- Class
- simulation
- greedy
- 파이썬
- java
- string
- Binary Tree
- 코딩테스트
- sorting
- Binary Search
- Data Structure
- SQL
- 자바
- array
- Math
- dynamic programming
- 구현
- bit manipulation
- Matrix
- Method
- hash table
- Number Theory
- Counting
- 코테
- two pointers
- implement
- Stack
- Tree
- database
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 504. Base 7 본문
1. Input
1) 정수 num
2. Output
1) num을 7진법으로 표현한 수를 담은 문자열
3. Constraint
1) - 10^7 <= num <= 10^7
4. Example
Input: num=100 -> Output: “202”
설명: 100 = 49*2 + 2 = 202(7)
5. Code
1) 첫 코드(2022/07/24)
if(num==0) return "0";
int n = num;
boolean isPos = true;
if(num<0){
n *= -1;
isPos = false;
}
String s = "";
while(n>=1){
s += n%7 + "";
n /= 7;
}
String result = "";
for(int i=s.length()-1 ; i>=0 ; i--)
result += s.charAt(i) + "";
return isPos ? result : "-" + result;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 507. Perfect Number (0) | 2022.12.01 |
---|---|
[LeetCode/Easy] 14. Longest Common Prefix (0) | 2022.11.30 |
[LeetCode/Easy] 500. Keyboard Row (0) | 2022.11.30 |
[LeetCode/Easy] 476. Number Complement (0) | 2022.11.30 |
[LeetCode/Easy] 461. Hamming Distance (0) | 2022.11.30 |