Notice
Recent Posts
Recent Comments
Today
Total
01-27 06:30
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[์›”๊ฐ„ ์ฝ”๋“œ ์ฑŒ๋ฆฐ์ง€ ์‹œ์ฆŒ3] ์—†๋Š” ์ˆซ์ž ๋”ํ•˜๊ธฐ ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm || ๋ฌธ์ œํ’€์ด/PS

[์›”๊ฐ„ ์ฝ”๋“œ ์ฑŒ๋ฆฐ์ง€ ์‹œ์ฆŒ3] ์—†๋Š” ์ˆซ์ž ๋”ํ•˜๊ธฐ

WonderJay 2022. 7. 1. 22:08
728x90
๋ฐ˜์‘ํ˜•
SMALL

https://programmers.co.kr/learn/courses/30/lessons/86051

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ์—†๋Š” ์ˆซ์ž ๋”ํ•˜๊ธฐ

0๋ถ€ํ„ฐ 9๊นŒ์ง€์˜ ์ˆซ์ž ์ค‘ ์ผ๋ถ€๊ฐ€ ๋“ค์–ด์žˆ๋Š” ์ •์ˆ˜ ๋ฐฐ์—ด numbers๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. numbers์—์„œ ์ฐพ์„ ์ˆ˜ ์—†๋Š” 0๋ถ€ํ„ฐ 9๊นŒ์ง€์˜ ์ˆซ์ž๋ฅผ ๋ชจ๋‘ ์ฐพ์•„ ๋”ํ•œ ์ˆ˜๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.

programmers.co.kr

visit ๋ฐฐ์—ด์— ๋‚˜์˜จ ์ˆซ์ž ์ธ๋ฑ์Šค์— ๋งˆํ‚นํ•˜๊ณ , ์ธ๋ฑ์Šค ๋˜์ง€ ์•Š์€ ์ˆซ์ž์˜ ์ธ๋ฑ์Šค๋ฅผ answer ์— ์ €์žฅํ•˜๋ฉด ๋œ๋‹ค.

 

#include <string>
#include <vector>

using namespace std;

int solution(vector<int> numbers) {
    int answer = -1; int sum = 0;
    vector<int> visit(10, 0);

    for (int& ele : numbers)
    {
        visit[ele] = 1;
    }

    for (int i = 0; i < 10; i++)
    {
        if (!visit[i])
            sum += i;
    }
    answer = sum;

    return answer;
}

 

 

728x90
๋ฐ˜์‘ํ˜•
LIST
Comments