프로그래머스 42862 체육복

1 개요[ | ]

프로그래머스 42862 체육복

2 C++[ | ]

#include <string>
#include <vector>

using namespace std;

int solution(int n, vector<int> lost, vector<int> reserve) {
    vector<int> have(n+1, 1);
    for(const auto& i: reserve) {
        have[i]++;
    }
    for(const auto& i: lost) {
        have[i]--;
    }
    int answer = 0;
    for(int i=1; i<=n;i ++) {
        if(have[i] > 0) {
            have[i]--;
            answer++;
            continue;
        }
        if(i>=2 && have[i-1] > 0) {
            have[i-1]--;
            answer++;
            continue;
        }
        if(i<=n-1 && have[i+1] > 1) {
            have[i+1]--;
            answer++;
            continue;
        }
    }
    return answer;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}