Skip to content

Commit c7b1459

Browse files
committed
[level 1] Title: 내적, Time: 0.03 ms, Memory: 80.5 MB -BaekjoonHub
1 parent afd19ab commit c7b1459

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# [level 1] 내적 - 70128
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/70128)
4+
5+
### 성능 요약
6+
7+
메모리: 80.5 MB, 시간: 0.03 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 월간 코드 챌린지 시즌1
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 07월 16일 17:57:14
20+
21+
### 문제 설명
22+
23+
<p>길이가 같은 두 1차원 정수 배열 a, b가 매개변수로 주어집니다. a와 b의 <a href="https://en.wikipedia.org/wiki/Dot_product" target="_blank" rel="noopener">내적</a>을 return 하도록 solution 함수를 완성해주세요.</p>
24+
25+
<p>이때, a와 b의 내적은 <code>a[0]*b[0] + a[1]*b[1] + ... + a[n-1]*b[n-1]</code> 입니다. (n은 a, b의 길이)</p>
26+
27+
<hr>
28+
29+
<h5>제한사항</h5>
30+
31+
<ul>
32+
<li>a, b의 길이는 1 이상 1,000 이하입니다.</li>
33+
<li>a, b의 모든 수는 -1,000 이상 1,000 이하입니다.</li>
34+
</ul>
35+
36+
<hr>
37+
38+
<h5>입출력 예</h5>
39+
<table class="table">
40+
<thead><tr>
41+
<th>a</th>
42+
<th>b</th>
43+
<th>result</th>
44+
</tr>
45+
</thead>
46+
<tbody><tr>
47+
<td><code>[1,2,3,4]</code></td>
48+
<td><code>[-3,-1,0,2]</code></td>
49+
<td>3</td>
50+
</tr>
51+
<tr>
52+
<td><code>[-1,0,1]</code></td>
53+
<td><code>[1,0,-1]</code></td>
54+
<td>-2</td>
55+
</tr>
56+
</tbody>
57+
</table>
58+
<hr>
59+
60+
<h5>입출력 예 설명</h5>
61+
62+
<p>입출력 예 #1</p>
63+
64+
<ul>
65+
<li>a와 b의 내적은 <code>1*(-3) + 2*(-1) + 3*0 + 4*2 = 3</code> 입니다.</li>
66+
</ul>
67+
68+
<p>입출력 예 #2</p>
69+
70+
<ul>
71+
<li>a와 b의 내적은 <code>(-1)*1 + 0*0 + 1*(-1) = -2</code> 입니다.</li>
72+
</ul>
73+
74+
75+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int solution(int[] a, int[] b) {
3+
int answer = 0;
4+
5+
int len = a.length;
6+
for(int i=0; i<len ; i++){
7+
answer += a[i]*b[i];
8+
}
9+
10+
return answer;
11+
}
12+
}

0 commit comments

Comments
 (0)