Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 유니온 파인드
- swea
- 그리디
- BFS
- 스택
- 세그먼트 트리
- 구현
- 플로이드-와샬
- 투 포인터
- 백트래킹
- 프로그래머스
- 시뮬레이션
- 문자열
- Kotlin
- 후니의 쉽게 쓴 시스코 네트워킹
- CS
- 위상정렬
- 알고리즘
- dfs
- 에라토스테네스의 체
- JUnit 5
- java
- 수학
- Effective Java
- 이분탐색
- Network
- 동적계획법
- mst
- 완전탐색
- 백준
Archives
반갑습니다!
[프로그래머스] 내적 본문
풀이
벡터의 내적을 구현해주면 된다. 문제에서 알려준대로 그대로 구현하면 쉽게 풀 수 있다.
코드
C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
using namespace std; | |
int solution(vector<int> a, vector<int> b) { | |
int answer = 0; | |
for(int i=0; i<a.size(); i++) | |
answer += (a[i] * b[i]); | |
return answer; | |
} |
Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int solution(int[] a, int[] b) { | |
int answer = 0; | |
for(int i=0; i<a.length; i++) | |
answer += (a[i] * b[i]); | |
return answer; | |
} | |
} |
Python3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(a, b): | |
answer = 0 | |
for i in range(len(a)): | |
answer += (a[i] * b[i]) | |
return answer |
Kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
fun solution(a: IntArray, b: IntArray): Int { | |
var answer = 0 | |
for (i in a.indices) | |
answer += (a[i] * b[i]) | |
return answer | |
} | |
} |
'알고리즘 문제 풀이' 카테고리의 다른 글
[백준] 1956 운동 (0) | 2020.11.26 |
---|---|
[백준] 2075 N번째 큰 수 (0) | 2020.11.08 |
[백준] 2959 거북이 (0) | 2020.11.04 |
[백준] 12096 (0) | 2020.11.04 |
[백준] 15663 N과 M (9) (0) | 2020.11.02 |