Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

2022年03月28日(월) jaewon1676 풀이 5문제 추가, 파일명 변경 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
codeisneverodd merged 5 commits into codeisneverodd:main from jaewon1676:main
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion level-1/K번째수.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,17 @@ function solution(array, commands) {
return arrCmd[cmd[2] - 1]
})
return answer;
}
}

//정답 2 - jaewon1676
function solution(array, commands) {
var result = [];
var temp = [];
for(var i=0; i<commands.length; i++){
temp = array.slice(commands[i][0] - 1, commands[i][1]).sort((a,b) => {return a - b})
console.log(temp)
result.push(temp[commands[i][2]-1])
}
return result
}

24 changes: 23 additions & 1 deletion level-1/시저-암호.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,26 @@ function solution(s, n) {
}
}).join('')
return answer;
}
}

//정답 2 - jaewon1676
function solution(s, n) {
return s.split("").map((el) => {
if (el == " ") return el;
let tmp = el.charCodeAt()
return el.toLowerCase().charCodeAt()+n > 122
? String.fromCharCode(tmp+n-26)
: String.fromCharCode(tmp+n)
}).join('')
}
/* 문자열 -> 아스키코드 : s.charCodeAt()
Copy link
Owner

@codeisneverodd codeisneverodd Mar 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석을 정말 잘 달아주셨네요! 감사합니다 😁

jaewon1676 reacted with laugh emoji
아스키코드 -> 문자열 : String.fromCharCode()
풀이과정
1. 배열을 문자열로 쪼개서 map 메서드로 하나씩 순회한다., 문자열이 비어있으면 리턴한다.
2. 알파벳을 통일 하기 위해 소문자 아스키코드로 변환한다.
대문자 아스키코드는 65가 A, 90이 Z이다.
소문자 아스키코드는 97이 a, 122가 z이다.
3. 변환한 아스키코드 + n이 122이상이면 알파벳 단어 길이 25 + 알파벳 앞으로 이동 1만큼 뺴준고
그렇지 않으면 그대로 더한 후 해당 아스키코드의 알파벳으로 변환해준다.
*/

39 changes: 38 additions & 1 deletion level-1/제일-작은-수-제거하기.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,41 @@ function solution(arr) {
arr.splice(index, 1)
answer = arr.length === 0 ? [-1] : arr
return answer;
}
}

//정답 2 - jaewon1676
function solution(arr) {
var answer = [];

let min = Math.min(...arr)
while(1){
for (let i=0; i<arr.length; i++){
if (min == arr[i]){
arr.splice(i, 1)
if (arr.length == 0){
return [-1]
}
else {
return arr;
}
}
}
}
return -1
}
/* 풀이과정
1. 배열의 최솟값을 min 변수에 담아줍니다.
2. 배열을 순회하며 최솟값을 찾아 splice 메서드를 사용해 최솟값의 자리만 제거해줍니다.
3. 최솟값 제거 후 배열 크기가 0이면 -1, 그렇지 않으면 배열 그대로 반환합니다. */

//정답 3 - jaewon1676
function solution(arr) {
arr.splice(arr.indexOf(Math.min(...arr)),1);
if (arr.length < 1) return [-1];
return arr;
}
/* 풀이과정 arr [4,3,2,1] 일경우
Math.min(...arr)은 1
arr.indexOf(1), 1이 있는 index가 3이므로 3 반환.
arr.splice(3, 1) arr의 3번째 index만 제거 해준다.
arr의 크기가 1보다 작으면 -1, 그렇지 않으면 그대로 반환. */
15 changes: 14 additions & 1 deletion level-1/폰켓몬.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,17 @@ function solution(nums) {
const setLen = numSet.size
answer = numLen / 2 >= setLen ? setLen : numLen / 2
return answer;
}
}

//정답 2 - jaewon1676
function solution(nums) {
let max = nums.length / 2; // N / 2
let set = [...new Set(nums)] // 중복을 없앤다.
return set.length > max ? max : set.length
}
/* 풀이 과정
1. 많은 종류의 폰켓몬을 포함해서 N/2마리 선택해야한다.
2. 같은 숫자는 같은 종류이므로 set을 활용해 중복을 없애고 진행한다.
3. 최대로 고를 수 있는 폰켓몬 수는 N / 2마리가 set의 길이보다 크냐 작냐에 따라
두가지 경우의 수로 좁혀진다. */

58 changes: 58 additions & 0 deletions level-2/[1차]-캐시.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//https://github.com/codeisneverodd/programmers-coding-test
Copy link
Owner

@codeisneverodd codeisneverodd Mar 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

허걱 공백 제거 감사합니다! 😄

jaewon1676 reacted with laugh emoji
//완벽한 정답이 아닙니다.
//정답 1 - codeisneverodd
function solution(cacheSize, cities) {
var answer = 0;
let cache = []
if (cacheSize === 0) return 5 * cities.length
for (const city of cities) {
const cityLC = city.toLowerCase()
if (cache.includes(cityLC)) {
cache.splice(cache.indexOf(cityLC), 1)
cache.unshift(cityLC)
answer += 1
} else {
if (cache.length >= cacheSize) cache.pop()
cache.unshift(cityLC)
answer += 5
}
}
return answer;
}

//정답 2 - jaewon1676
function solution(cacheSize, cities) {
var answer = 0;
let cache = [];

//캐시 크기가 0인 경우는 따로 처리
if (cacheSize === 0) return cities.length * 5;

while (cities.length != 0) {
// 맨 앞의 배열의 요소 히나를 소문자로 변환해서 city에 넣는다.
const city = cities.shift().toLowerCase();
// cities의 요소 city가 캐시 안에 있는지 비교한다. (hit or miss)
if (cache.includes(city)) {
// 캐시 안에 있으면 그 위치에 있는 캐시를 빼주고,
cache.splice(cache.indexOf(city), 1);
// 맨 뒤로 push 해준다.
cache.push(city);
// cache hit
answer += 1;
} else { // 캐시 크기가 꽉 차있으면 캐시 맨 앞에 요소를 하나 빼준다.
if (cache.length === cacheSize) {
cache.shift();
}
// 새로운 캐시 맨 뒤로 push
cache.push(city);
// cache miss
answer += 5;
}
}
return answer;
}
/* LRU 알고리즘
n이 배열 안에 있으면 배열 안의 n을 빼주고, 새 n을 배열의 맨 뒤로 push 한다.
n이 배열 안에 없으면 n을 배열의 맨 뒤로 push 한다. 이때 배열의 크기 여유가 없으면
배열에서 가장 오래된 요소를 하나 뺴준다. (arr.shift()) */

21 changes: 0 additions & 21 deletions level-2/[1차]-캐시.js
View file Open in desktop

This file was deleted.

AltStyle によって変換されたページ (->オリジナル) /