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
- Tree
- java
- SQL
- Math
- 코딩테스트
- 자바
- hash table
- geometry
- dynamic programming
- Binary Search
- Method
- 구현
- two pointers
- simulation
- 코테
- Stack
- Matrix
- 파이썬
- Class
- Binary Tree
- database
- Data Structure
- bit manipulation
- Number Theory
- sorting
- string
- greedy
- implement
- Counting
- array
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 258. Add Digits 본문
1. Input
1) int 변수 num
2) 각 자리수를 계속 더해서 1자리수가 나올때 까지 반복
2. Output
1) 최종적으로 나온 1자리 정수
3. Constraint
1) 0 <= num <= 2^31 - 1
4. Example
Input: num = 38
Output: 2
설명:
- 38 -> 3 + 8 -> 11
- 11 -> 1 + 1 -> 2
5. Code
1) 첫 코드(2022/07/06)
if(num<10)
return num;
int n = num;
int sum = 0;
while(n>=10){
while(n>=1){
sum += n%10;
n /=10;
}
if(sum>=10){
n = sum;
sum = 0;
}
}
return sum;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 268. Missing Number (0) | 2022.10.14 |
---|---|
[LeetCode/Easy] 263. Ugly Number (0) | 2022.10.14 |
[LeetCode/Easy] 242. Valid Anagram (0) | 2022.10.13 |
[LeetCode/Easy] 231. Power of Two (0) | 2022.10.13 |
[LeetCode/Easy] 217. Contains Duplicate (0) | 2022.10.12 |