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
- greedy
- Binary Search
- database
- 코테
- Counting
- geometry
- sorting
- hash table
- Binary Tree
- Number Theory
- SQL
- Class
- simulation
- 구현
- Tree
- two pointers
- string
- Math
- Method
- bit manipulation
- 파이썬
- 자바
- 코딩테스트
- java
- Stack
- Data Structure
- dynamic programming
- Matrix
- implement
- array
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2652. Sum Multiples 본문
1. Input
1) int n
2. Output
1) [1, n] 구간의 자연수 중 3 또는 5 또는 7로 나누어 떨어지는 수의 합을 반환
3. Constraint
1) 1 <= n <= 10^3
4. Example
Input: n = 10 -> Output: 40
설명: 1부터 10까지의 자연수 중 3 또는 5 또는 7로 나누어 떨어지는 수는 3, 5, 6, 7, 9, 10이므로 이들의 합인 40을 반환한다.
5. Code
1) 첫 코드(2023/05/08)
class Solution {
public int sumOfMultiples(int n) {
int sum = 0;
for(int i=3 ; i<=n ; i++){
if(i%3==0) sum += i;
else if(i%5==0) sum += i;
else if(i%7==0) sum += i;
}
return sum;
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2670. Find the Distinct Difference Array (0) | 2023.05.08 |
---|---|
[LeetCode/Easy] 2656. Maximum Sum With Exactly K Elements (0) | 2023.05.08 |
[LeetCode/Easy] 2651. Calculate Delayed Arrival Time (0) | 2023.05.08 |
[LeetCode/Easy] 2644. Find the Maximum Divisibility Score (0) | 2023.05.08 |
[LeetCode/Easy] 2643. Row With Maximum Ones (0) | 2023.05.08 |