-
[Programmers] 체육복STUDYING/Algorithm 2021. 9. 27. 00:36728x90
https://programmers.co.kr/learn/courses/30/lessons/42862
#include <string> #include <vector> using namespace std; int solution(int n, vector<int> lost, vector<int> reserve) { int answer = 0; vector<int> students(n, 1); for (int i = 0; i < lost.size(); ++i) students[lost[i] - 1]--; for (int i = 0; i < reserve.size(); ++i) students[reserve[i] - 1]++; for (int i = 0; i < n; i++) { if (i != 0 && students[i] == 0) { if (students[i - 1] == 2) { students[i]++; students[i - 1]--; continue; } } if (i != n - 1 && students[i] == 0) { if (students[i + 1] == 2) { students[i]++; students[i + 1]--; } } } for (int i = 0; i < n; ++i) { if (students[i] > 0) { answer++; } } return answer; }
'STUDYING > Algorithm' 카테고리의 다른 글
[Programmers] 가장 먼 노드 (0) 2021.09.27 [Programmers] 타겟 넘버 (0) 2021.09.27 [Programmers] 모의고사 (0) 2021.09.27 [Programmers] K번째 수 (0) 2021.09.27 [Programmers] 완주하지 못한 선수 (0) 2021.09.27