Skip to content

Commit 619ff7c

Browse files
authored
[moonjonghoo]25.02.14 (#43)
* String_Reversal / 기초 * control_z / 기초 * I_don't_like_English /기초 * String_Calculation / 기초 * Crane_Doll_Picking_Game / 중급 * 순서쌍의_개수 / 기초 * 점의_위치_구하기 / 기초 * 로그인_성공? / 기초 * 특이한_정렬 / 기초 * 프로세스 / 고급 * 프로세스 /고급 수정 * 모스부호(1) / 기초 * A로 B만들기 /기초 * 진료순서/ 기초 * 등수매기기 /기초 * 완주하지 못한 선수 /중급 * maximum_depth_of_binary_tree / 기초 * binary_tree_inorder_traversal /기초 * same_tree /기초 * Invert_Binary_tree/기초 * 중복된_문자_제거 /기초 * 한_번만_등장한_문자 /기초 * 소인수분해 /중급 * 무작위로_K개의_수_뽑기 / 기초
1 parent 4e18165 commit 619ff7c

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function solution(arr, k) {
2+
var answer = [];
3+
for (let i = 0; i < arr.length; i++) {
4+
if (!answer.includes(arr[i])) {
5+
answer.push(arr[i]);
6+
}
7+
}
8+
9+
if (answer.length > k) {
10+
return answer.slice(0, k);
11+
} else if (answer.length < k) {
12+
while (answer.length !== k) {
13+
answer.push(-1);
14+
}
15+
return answer;
16+
} else {
17+
return answer;
18+
}
19+
}
20+
21+
console.log(solution([0, 1, 1, 2, 2, 3], 5));
22+
console.log(solution([0, 1, 1, 1, 1], 4));

Moonjonghoo/set/소인수분해.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function solution(n) {
2+
var answer = [];
3+
let division = 2;
4+
while (n !== 1) {
5+
if (n % division === 0) {
6+
n = n / division;
7+
answer.push(division);
8+
} else {
9+
division++;
10+
}
11+
}
12+
return Array.from(new Set(answer));
13+
}
14+
15+
console.log(solution(12)); // 기대값: [2, 3]
16+
console.log(solution(17)); // 기대값: [17]
17+
console.log(solution(420)); // 기대값: [2, 3, 5, 7]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function solution(my_string) {
2+
var answer = "";
3+
let set = [];
4+
for (let i = 0; i < my_string.length; i++) {
5+
if (!set.includes(my_string[i])) {
6+
set.push(my_string[i]);
7+
answer += my_string[i];
8+
}
9+
}
10+
return answer;
11+
}
12+
13+
console.log(solution("people")); // 기대값: "peol"
14+
console.log(solution("We are the world")); // 기대값: "We arthwold"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// function solution(s) {
2+
// var answer = "";
3+
// let arr = [];
4+
// for (let i = 0; i < s.length; i++) {
5+
// if (!arr.includes(s[i])) {
6+
// arr.push(s[i]);
7+
// } else {
8+
// arr = arr.filter((e) => e !== s[i]);
9+
// }
10+
// }
11+
12+
// answer = arr.sort().join("");
13+
// return answer;
14+
// }
15+
16+
// console.log(solution("abcabcadc")); // 기대값: "d"
17+
// console.log(solution("abdc")); // 기대값: "abdc"
18+
// console.log(solution("hello")); // 기대값: "eho"
19+
// console.log(solution("hlelo"));
20+
21+
function solution(s) {
22+
var answer = "";
23+
let arr = [];
24+
let hash = new Map();
25+
for (let i = 0; i < s.length; i++) {
26+
if (!hash.get(s[i])) {
27+
hash.set(s[i], 1);
28+
} else {
29+
hash.set(s[i], hash.get(s[i]) + 1);
30+
}
31+
}
32+
for (let [key, value] of hash) {
33+
if (value === 1) {
34+
arr.push(key);
35+
}
36+
}
37+
answer = arr.sort().join("");
38+
if (arr.length === 0) return "";
39+
return answer;
40+
}
41+
42+
console.log(solution("abcabcadc")); // 기대값: "d"
43+
console.log(solution("abdc")); // 기대값: "abdc"
44+
console.log(solution("hello")); // 기대값: "eho"

0 commit comments

Comments
 (0)