C++)
#include <string>
#include <vector>
using namespace std;
int solution(int n, int m, vector<int> section) {
int answer = 0;
int cur = 0;
for(auto ele : section) {
if(cur <= ele) {
answer++;
cur = ele + m;
}
}
return answer;
}
첫 시도에서 틀려서 생각해본 반례
n = 10
m = 3
section = [1,3,4,8,9]
Python)
def solution(n, m, section):
if m == 1:
return len(section)
cur = section[0]
ans = 0
for s in section:
if cur <= s:
ans += 1
cur = s + m
return ans
또 다른 반례
n = 10
m = 2
section = [1, 3, 4, 7, 9, 10]
'프로그래머스 > Level1' 카테고리의 다른 글
| [Level1] 숫자 문자열과 영단어 (C++) (0) | 2023.05.13 |
|---|---|
| [Level1] 다트 게임 (C++) (0) | 2023.05.06 |
| [Level1] 공원 산책 (C++) (0) | 2023.05.04 |
| [Level1] 바탕화면 정리 (C++) (0) | 2023.04.27 |
| [Level1] 달리기 경주 (C++) (0) | 2023.04.26 |