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
- Stack
- Math
- Class
- Tree
- implement
- 파이썬
- SQL
- simulation
- bit manipulation
- 구현
- array
- Matrix
- dynamic programming
- database
- 코테
- 코딩테스트
- Binary Search
- Counting
- Data Structure
- Number Theory
- geometry
- sorting
- 자바
- java
- hash table
- two pointers
- Method
- string
- Binary Tree
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2379. Minimum Recolors to Get K Consecutive Black Blocks 본문
코딩테스트 풀이/JAVA
[LeetCode/Easy] 2379. Minimum Recolors to Get K Consecutive Black Blocks
무지맘 2023. 5. 2. 16:141. Input
1) String blocks
2) int k
2. Output
1) blocks에서 길이가 k인 부분 문자열을 뽑았을 때, 모든 글자가 B가 되도록 바꿔야하는 W의 최소 개수를 반환
3. Constraint
1) n == blocks.length
2) 1 <= n <= 100
3) blocks는 B와 W로 이루어져 있다.
4) 1 <= k <= n
4. Example
Input: blocks = "WBBWWBBWBW", k = 7 -> Output: 3
Input: blocks = "WBWBBBW", k = 2 -> Output: 0
설명:
- 0번째부터 시작하는 WBBWWBB에서 W 3개를 바꾸면 모두 B가 된다.
- 3번째부터 시작하는 BB는 바꿀 필요가 없기 때문에 0을 반환한다.
5. Code
1) 첫 코드(2023/05/02)
class Solution {
public int minimumRecolors(String blocks, int k) {
int min = Integer.MAX_VALUE;
for(int i=0 ; i<=blocks.length()-k ; i++){
int count = 0;
for(int j=i ; j<i+k ; j++)
if(blocks.charAt(j)=='W')
count++;
if(count<min)
min = count;
}
return min;
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[백준 온라인 저지] 19532. 수학은 비대면강의입니다 (0) | 2023.05.02 |
---|---|
[백준 온라인 저지] 2231. 분해합 (0) | 2023.05.02 |
[LeetCode/Easy] 2373. Largest Local Values in a Matrix (0) | 2023.05.02 |
[LeetCode/Easy] 2367. Number of Arithmetic Triplets (0) | 2023.05.02 |
[LeetCode/Easy] 2363. Merge Similar Items (0) | 2023.05.02 |