diff --git "a/level-1/\352\260\200\354\232\264\353\215\260-\352\270\200\354\236\220-\352\260\200\354\240\270\354\230\244\352\270\260.js" "b/level-1/\352\260\200\354\232\264\353\215\260-\352\270\200\354\236\220-\352\260\200\354\240\270\354\230\244\352\270\260.js" index 526bcf3..9422925 100644 --- "a/level-1/\352\260\200\354\232\264\353\215\260-\352\270\200\354\236\220-\352\260\200\354\240\270\354\230\244\352\270\260.js" +++ "b/level-1/\352\260\200\354\232\264\353\215\260-\352\270\200\354\236\220-\352\260\200\354\240\270\354\230\244\352\270\260.js" @@ -37,4 +37,14 @@ function solution(s) { : s[s.length / 2 - 1] + s[s.length / 2]; } - +// 정답 5 - jaewon1676 +function solution(s) { + var answer = ''; + + if (s.length % 2 == 0 ) { // 짝수일 경우, + answer = s[s.length / 2 - 1] + s[s.length / 2]; + } else { + answer = s[parseInt(s.length / 2)]; // 홀수일 경우 + } + return answer; +} diff --git "a/level-1/\354\240\225\354\210\230-\354\240\234\352\263\261\352\267\274-\355\214\220\353\263\204.js" "b/level-1/\354\240\225\354\210\230-\354\240\234\352\263\261\352\267\274-\355\214\220\353\263\204.js" index 00c9cbe..52609e2 100644 --- "a/level-1/\354\240\225\354\210\230-\354\240\234\352\263\261\352\267\274-\355\214\220\353\263\204.js" +++ "b/level-1/\354\240\225\354\210\230-\354\240\234\352\263\261\352\267\274-\355\214\220\353\263\204.js" @@ -22,3 +22,11 @@ function solution(n) { // 아니라면 -1 반환 return -1; } + +//정답 4 - jaewon1676 +function solution(n) { + let s = parseInt(Math.sqrt(n)) // n의 제곱근을 확인 + if (s ** 2 === n) return ((s+1) ** 2) + + return -1; +} \ No newline at end of file diff --git "a/level-2/\353\251\200\354\251\241\355\225\234-\354\202\254\352\260\201\355\230\225.js" "b/level-2/\353\251\200\354\251\241\355\225\234-\354\202\254\352\260\201\355\230\225.js" index 6cba747..1cffefd 100644 --- "a/level-2/\353\251\200\354\251\241\355\225\234-\354\202\254\352\260\201\355\230\225.js" +++ "b/level-2/\353\251\200\354\251\241\355\225\234-\354\202\254\352\260\201\355\230\225.js" @@ -33,4 +33,20 @@ let greatestCommonDivisor = (a, b) => { b = r; } return a; -} \ No newline at end of file +} + +//정답 3 - jaewon1676 +// 유클리드 호제법을 이용한 최대 공약수 구하기 +function gcd(w, h) { + let mod = w % h; // w와 h의 나머지를 구합니다. + + if (mod === 0) { // 나머지가 0일 경우 h를 반환합니다. + return h; + } + // 만약 0이 아닐경우 w에 h를 넣고 h에 나머지인 mod를 넣어 해당 함수를 다시 호출해 줍니다. + return gcd(h, mod); +} +function solution(w, h) { + const gcdVal = gcd(w, h); // 최대 공약수를 구해줍니다. + return w * h - (w + h - gcdVal); +}