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 4170eec

Browse files
Add 같은-숫자는-싫어.js
1 parent fc5a9cd commit 4170eec

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎level-1/같은-숫자는-싫어.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,23 @@ function solution(arr) {
2323
// 첫 번째 요소의 경우 undefined와 비교
2424
return arr.filter((item, index) => item !== arr[index - 1]);
2525
}
26+
27+
28+
// 정답 4 - prove-ability
29+
function solution(arr) {
30+
let answer = [];
31+
// 이중 배열을 사용해서 포인터?를 두 개를 사용한다
32+
for (let i = 0, len = arr.length - 1; i < len; i++) {
33+
// i 의 다음수를 비교하기 위해 j = (i + 1)
34+
for (let j = i + 1, len = arr.length; j < len; j++) {
35+
// i 와 j 번째 값이 같이 않다면
36+
if (arr[i] !== arr[j]) {
37+
answer.push(arr[i]);
38+
i = j - 1;
39+
break;
40+
}
41+
}
42+
}
43+
answer.push(arr[arr.length - 1]);
44+
return answer;
45+
}

0 commit comments

Comments
(0)

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