Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6cdf4df

Browse files
committed
feat: 숫자짝꿍 풀이
1 parent 7b21a65 commit 6cdf4df

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎level-1/숫자짝꿍&131128&.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// 정답 1 - ssi02014
2+
// 길이가 3,000,000 이므로 객체를 이용한 연산 횟수 최적화 풀이
3+
function solution(X, Y) {
4+
const commons = [];
5+
const obj = {};
6+
7+
for (const el of X) {
8+
obj[el] = (obj[el] || 0) + 1;
9+
}
10+
11+
for (const el of Y) {
12+
if (obj[el]) {
13+
commons.push(el);
14+
obj[el]--;
15+
}
16+
}
17+
18+
commons.sort((a, b) => b - a);
19+
20+
if (!commons.length) return "-1";
21+
else if (commons[0] === "0") return "0";
22+
return commons.reduce((acc, cur) => acc + cur, "");
23+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /