- 난이도: Lv1
프로그래머스 링크: https://school.programmers.co.kr/learn/courses/30/lessons/161989
풀이 링크(GitHub): hayannn/CodingTest_Java/프로그래머스/1/161989. 덧칠하기
풀이 시간 : 12분
import java.util.*;
class Solution {
public int solution(int n, int m, int[] section) {
int startP = section[0];
int endP = section[0] + (m-1);
int answer = 0;
for(int i=0; i<section.length; i++){
if(i>=startP && i<= endP) continue;
else {
startP = i;
endP = i + (m-1);
answer++;
}
}
return answer;
}
}
//before
int answer = 0;
for(int i=0; i<section.length; i++){
//after
int answer = 1;
for(int i=1; i<=section.length; i++){
//before
int answer = 1;
for(int i=1; i<=section.length; i++){
//after
int answer = 0;
int endP = 0;
for(int i=0; i<section.length; i++){
if(section[i] > endP){
endP = section[i] + m - 1;
answer++;
}
}
풀이 시간 : 35분(첫 풀이 시간 포함)
import java.util.*;
class Solution {
public int solution(int n, int m, int[] section) {
int answer = 0;
int endP = 0;
for(int i=0; i<section.length; i++){
if(section[i] > endP){
endP = section[i] + m - 1;
answer++;
}
}
return answer;
}
}