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
- 파이썬
- Binary Tree
- 자바
- array
- Counting
- geometry
- sorting
- Tree
- hash table
- 코딩테스트
- Method
- Class
- dynamic programming
- Binary Search
- Stack
- 코테
- implement
- java
- simulation
- database
- two pointers
- string
- Number Theory
- Matrix
- Data Structure
- bit manipulation
- Math
- greedy
- 구현
- SQL
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1281. Subtract the Product and Sum of Digits of an Integer 본문
코딩테스트 풀이/JAVA
[LeetCode/Easy] 1281. Subtract the Product and Sum of Digits of an Integer
무지맘 2022. 12. 24. 01:181. Input
1) 정수 n
2. Output
1) n의 각 자릿수의 곱과 합의 차
3. Constraint
1) 1 <= n <= 10^5
4. Example
Input: n = 234 -> Output: 15
설명:
- 각 자릿수의 곱 = 2 * 3 * 4 = 24
- 각 자릿수의 합 = 2 + 3 + 4 = 9
- 따라서 24 - 9 = 15를 반환한다.
5. Code
1) 첫 코드(2022/06/03)
int pro = 1;
int sum = 0;
int d;
while(n>=1){
d = n%10;
pro *= d;
sum += d;
n /= 10;
}
return pro-sum;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1295. Find Numbers with Even Number of Digits (0) | 2022.12.24 |
---|---|
[LeetCode/Easy] 1290. Convert Binary Number in a Linked List to Integer (0) | 2022.12.24 |
[LeetCode/Easy] 1266. Minimum Time Visiting All Points (0) | 2022.12.24 |
[LeetCode/Easy] 1252. Cells with Odd Values in a Matrix (0) | 2022.12.24 |
[LeetCode/Easy] 1221. Split a String in Balanced Strings (0) | 2022.12.23 |