Notice
Recent Posts
Recent Comments
Today
Total
01-26 01:17
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[์›”๊ฐ„ ์ฝ”๋“œ ์ฑŒ๋ฆฐ์ง€ ์‹œ์ฆŒ1] ๋‚ด์  ๋ณธ๋ฌธ

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

[์›”๊ฐ„ ์ฝ”๋“œ ์ฑŒ๋ฆฐ์ง€ ์‹œ์ฆŒ1] ๋‚ด์ 

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

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

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ๋‚ด์ 

๊ธธ์ด๊ฐ€ ๊ฐ™์€ ๋‘ 1์ฐจ์› ์ •์ˆ˜ ๋ฐฐ์—ด a, b๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. a์™€ b์˜ ๋‚ด์ ์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ด๋•Œ, a์™€ b์˜ ๋‚ด์ ์€ a[0]*b[0] + a[1]*b[1] + ... + a[n-1]*b[n-1] ์ž…๋‹ˆ๋‹ค. (n์€ a, b์˜

programmers.co.kr

๋ง ๊ทธ๋Œ€๋กœ ๋‘ 1์ฐจ์› ๋ฒกํ„ฐ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ ๋‚ด์ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋œ๋‹ค.

 

#include <string>
#include <vector>

using namespace std;

int solution(vector<int> a, vector<int> b) {
    int answer = 1234567890; int pdc = 0;

    for (int i = 0; i < a.size(); i++)
    {
        pdc += a[i] * b[i];

    }
    answer = pdc;

    return answer;
}
728x90
๋ฐ˜์‘ํ˜•
LIST
Comments