diff --git "a/level-2/\352\265\254\353\252\205\353\263\264\355\212\270.js" "b/level-2/\352\265\254\353\252\205\353\263\264\355\212\270.js" index ecc2bf1..c6819b5 100644 --- "a/level-2/\352\265\254\353\252\205\353\263\264\355\212\270.js" +++ "b/level-2/\352\265\254\353\252\205\353\263\264\355\212\270.js" @@ -16,4 +16,28 @@ function solution(people, limit) { cnt++; } return cnt; -} // 4주차 2번 문제와 유사함 \ No newline at end of file +} // 4주차 2번 문제와 유사함 + +// 정답 2- prove-ability +function solution(people, limit) { + let count = 0; + // 오름차순 정렬 + people.sort((a, b) => a - b); + + // people 배열 요소가 있다면? + while(people.length) { + + // 요소 중 가장 큰 수인 마지막 요소를 가져온다 + let sum = people.pop(); + + // 요소 중 가장 작은 수를 더한다 + sum += people[0] + + // 합이 무게제한보다 작거나 같다면 가장 작은 요소 제거 + if(sum <= limit) people.shift(); + + count++; + } + + return count; +} \ No newline at end of file diff --git "a/level-2/\354\210\253\354\236\220\354\235\230-\355\221\234\355\230\204.js" "b/level-2/\354\210\253\354\236\220\354\235\230-\355\221\234\355\230\204.js" index 5509d0f..7c455db 100644 --- "a/level-2/\354\210\253\354\236\220\354\235\230-\355\221\234\355\230\204.js" +++ "b/level-2/\354\210\253\354\236\220\354\235\230-\355\221\234\355\230\204.js" @@ -14,4 +14,21 @@ function solution(n) { //수학적 풀이는 별도로 하지 않았습니다. } } return answer; +} + +//정답 2 - prove-ability +function solution(n) { + let answer = 0; + for(let i = 1; i <= n; i++) { + let sum = 0; + for(let j = i; j <= n; j++) { + sum += j; + if(sum > n) break; + if(n === sum) { + answer++; + break; + } + } + } + return answer; } \ No newline at end of file diff --git "a/level-2/\354\265\234\353\214\223\352\260\222\352\263\274-\354\265\234\354\206\237\352\260\222.js" "b/level-2/\354\265\234\353\214\223\352\260\222\352\263\274-\354\265\234\354\206\237\352\260\222.js" index e16ed19..7f79f2f 100644 --- "a/level-2/\354\265\234\353\214\223\352\260\222\352\263\274-\354\265\234\354\206\237\352\260\222.js" +++ "b/level-2/\354\265\234\353\214\223\352\260\222\352\263\274-\354\265\234\354\206\237\352\260\222.js" @@ -23,4 +23,10 @@ function solution(s) { let small = s[0] // s의 최솟값 let large = s[s.length - 1] // s의 최댓값 return (small + ' ' + large) +} + +//정답 4 - prove-ability +function solution(s) { + s = s.split(" ").map((v) => parseInt(v, 10)) + return `${Math.min(...s)} ${Math.max(...s)}`; } \ No newline at end of file