Skip to content

Commit 8bfbfc2

Browse files
author
gyeong-hyeon-kim
committed
Solved 2 problems
1 parent b515451 commit 8bfbfc2

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

level-2/H-Index.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
//정답 1
4+
function solution(citations) {
5+
var answer = 0;
6+
citations.sort((a,b)=>b-a)
7+
let h = 0
8+
while(h+1<=citations[h]) h++
9+
answer = h
10+
return answer;
11+
}
12+
13+
//정답 2
14+
function solution(citations) {
15+
var answer = 0;
16+
let h = 0
17+
let length = 0
18+
while(length >= h){
19+
h++
20+
length = citations.filter(citation => citation>=h).length
21+
}
22+
answer = h - 1
23+
return answer;
24+
}

level-2/타겟-넘버.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
function solution(numbers, target) {
4+
var answer = 0;
5+
const binaryLength = numbers.length
6+
const binary = 2**binaryLength
7+
for(let i=0; i<binary; i++){
8+
const numSlice = numbers.slice()
9+
const binaryString = i.toString(2).padStart(binaryLength, '0')
10+
for(let j=0; j<binaryString.length; j++) binaryString[j] === '0' ? numSlice[j] *= -1 : null
11+
const calculated = numSlice.reduce((prev, current) => prev + current)
12+
if(calculated === target) answer += 1
13+
}
14+
return answer;
15+
}

0 commit comments

Comments
 (0)