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
- string
- java
- database
- Number Theory
- 코딩테스트
- sorting
- SQL
- Stack
- Method
- simulation
- dynamic programming
- 코테
- Counting
- Math
- Binary Tree
- bit manipulation
- array
- Data Structure
- Tree
- 자바
- greedy
- Binary Search
- two pointers
- geometry
- 파이썬
- Class
- 구현
- Matrix
- implement
- hash table
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2549. Count Distinct Numbers on Board 본문
1. Input
1) int n
2. Output
1) 10^9일 동안 다음과 같은 행동을 했을 때, 보드에 있는 숫자의 개수를 반환
- 첫날 보드에 n을 쓴다.
- 다음날이 되면 보드에 있는 모든 x에 대해 x % i == 1이 되게 하는 모든 i(1 <= i <= n)를 보드에 쓴다.
- 마지막날 숫자를 셀 때 중복은 세지 않는다.
3. Constraint
1) 1 <= n <= 100
4. Example
Input: n = 5 -> Output: 4
설명:
- 1일: 5
- 2일: 5, 2, 4 <- 5%2==1, 5%4==1
- 3일: 5, 2, 4, 3 <- 4%3==1
- 이후 마지막날까지 숫자 4개만 남아있다.
5. Code
1) 첫 코드(2023/05/06)
class Solution {
public int distinctIntegers(int n) {
return n==1 ? 1 : n-1;
}
}
- 힌트를 참고해서 풀었다. n%(n-1)==1이므로 n보다 1 작은 수가 다 포함된다고 생각하니, 1부터 n-1까지의 모든 수가 적히겠구나 생각했다.
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2582. Pass the Pillow (0) | 2023.05.06 |
---|---|
[LeetCode/Easy] 2570. Merge Two 2D Arrays by Summing Values (0) | 2023.05.06 |
[LeetCode/Easy] 2540. Minimum Common Value (0) | 2023.05.06 |
[LeetCode/Easy] 2520. Count the Digits That Divide a Number (0) | 2023.05.06 |
[LeetCode/Easy] 2515. Shortest Distance to Target String in a Circular Array (0) | 2023.05.06 |