Merge branch 'master' of http://git.cuenet.net/roakfwk30/algorithm
@2e022d459d48f536474310132b76d035d270f384
--- al01/17.js
+++ al01/17.js
... | ... | @@ -1,7 +1,10 @@ |
1 | 1 |
function solution(str){ |
2 | 2 |
|
3 |
- let arr = []; |
|
4 | 3 |
|
4 |
+ let arr = []; |
|
5 |
+ for(let s of str){ |
|
6 |
+ arr.push(s); |
|
7 |
+ } |
|
5 | 8 |
|
6 | 9 |
for(let i = 0; i < arr.length; i++){ |
7 | 10 |
for(let k = arr.length; k > i; k--){ |
... | ... | @@ -10,8 +13,8 @@ |
10 | 13 |
} |
11 | 14 |
} |
12 | 15 |
} |
13 |
- return str; |
|
16 |
+ return arr; |
|
14 | 17 |
|
15 | 18 |
} |
16 | 19 |
|
17 |
-console.log(solution("good", "time", "good", "time", "student"));(No newline at end of file) |
|
20 |
+console.log(solution(["good", "time", "good", "time", "student"]));(No newline at end of file) |
--- al01/8.js
+++ al01/8.js
... | ... | @@ -1,22 +1,42 @@ |
1 | 1 |
//7 난쟁이 키 합 100인 조합 찾기 |
2 | 2 |
|
3 |
-function solution(arr){ |
|
4 | 3 |
|
5 |
- let arrSum = 0; |
|
6 | 4 |
|
7 |
- for(let i = 0; i < arr.length; i++){ |
|
8 |
- arrSum += arr[i]; |
|
9 |
- } |
|
10 |
- for(let i = 0; i < arr.length-1; i++){ |
|
11 |
- for(let j = i+1; j < arr.length; j++){ |
|
12 |
- if(arrSum - (arr[i]+arr[j]) === 100){ |
|
13 |
- arr.splice(j, 1); |
|
14 |
- arr.splice(i, 1); |
|
15 |
- } |
|
16 |
- } |
|
17 |
- } |
|
18 |
- console.log(arr); |
|
19 |
- |
|
5 |
+ |
|
6 |
+ |
|
7 |
+ |
|
8 |
+ |
|
9 |
+ |
|
10 |
+ |
|
11 |
+function a(n){ |
|
12 |
+ |
|
13 |
+ if(n < 1) return 1; |
|
14 |
+ return a(n - 1) * n; |
|
15 |
+ |
|
20 | 16 |
} |
17 |
+console.log(a(3)); |
|
21 | 18 |
|
22 |
-solution([20, 7, 23, 19, 10, 15, 25, 8, 13]);(No newline at end of file) |
|
19 |
+ |
|
20 |
+ |
|
21 |
+ |
|
22 |
+ |
|
23 |
+// function solution(arr){ |
|
24 |
+ |
|
25 |
+// let arrSum = 0; |
|
26 |
+ |
|
27 |
+// for(let i = 0; i < arr.length; i++){ |
|
28 |
+// arrSum += arr[i]; |
|
29 |
+// } |
|
30 |
+// for(let i = 0; i < arr.length-1; i++){ |
|
31 |
+// for(let j = i+1; j < arr.length; j++){ |
|
32 |
+// if(arrSum - (arr[i]+arr[j]) === 100){ |
|
33 |
+// arr.splice(j, 1); |
|
34 |
+// arr.splice(i, 1); |
|
35 |
+// } |
|
36 |
+// } |
|
37 |
+// } |
|
38 |
+// console.log(arr); |
|
39 |
+ |
|
40 |
+// } |
|
41 |
+ |
|
42 |
+// solution([20, 7, 23, 19, 10, 15, 25, 8, 13]);(No newline at end of file) |
+++ al01/jaegui.js
... | ... | @@ -0,0 +1,33 @@ |
1 | + | |
2 | + | |
3 | + | |
4 | + | |
5 | + | |
6 | + | |
7 | + | |
8 | + | |
9 | + | |
10 | + | |
11 | + | |
12 | + | |
13 | + | |
14 | + | |
15 | + | |
16 | + | |
17 | + | |
18 | + | |
19 | + | |
20 | + | |
21 | + | |
22 | + | |
23 | + | |
24 | +function factorial(n) | |
25 | +{ | |
26 | + if (n == 1) // n이 1일 때 | |
27 | + return 1; // 1을 반환하고 재귀호출을 끝냄 | |
28 | + | |
29 | + return n * factorial(n - 1); // n과 factorial 함수에 n - 1을 넣어서 반환된 값을 곱함 | |
30 | +} | |
31 | + | |
32 | + | |
33 | +console.log(factorial(3));(No newline at end of file) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?