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 4fb5408

Browse files
chaerin-devcodeisneverodd
authored andcommitted
solution 튜플
1 parent 8061345 commit 4fb5408

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎level-2/튜플.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,24 @@ function solution(s) {
1010
.sort((a, b) => a.length - b.length)
1111
for (const set of sets) answer.push(...set.filter(x => !answer.includes(x)))
1212
return answer;
13+
}
14+
15+
//정답 2 - chaerin-dev
16+
function solution(s) {
17+
// 문자열 -> 정수 이차원 배열
18+
const sArr = s
19+
.substring(2, s.length - 2)
20+
.split("},{")
21+
.map((e) => e.split(",").map((e) => parseInt(e)))
22+
.sort((a, b) => a.length - b.length);
23+
// 정답을 저장할 배열
24+
const answer = [];
25+
// 이차원배열을 순회하며 직전 배열과 겹치지 않는 요소만 answer에 추가
26+
for (let i = 0; i < sArr.length; i++) {
27+
for (let j = 0; j < sArr[i].length; j++) {
28+
const temp = sArr[i][j];
29+
if (!answer.includes(sArr[i][j])) answer.push(sArr[i][j]);
30+
}
31+
}
32+
return answer;
1333
}

0 commit comments

Comments
(0)

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