From ab150b1dce6a2d397322ea1e3627a314c415b98d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=91=9E=E5=96=9C?= <79238676+Happhee@users.noreply.github.com> Date: Wed, 8 Jun 2022 16:15:12 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat=20:=20=EB=AA=A8=EC=9D=98=EA=B3=A0?= =?UTF-8?q?=EC=82=AC=20=ED=88=AC=ED=8F=AC=EC=9D=B8=ED=84=B0=20=EC=86=94?= =?UTF-8?q?=EB=A3=A8=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\204\234\355\235\254/solution.js" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "problems/\352\265\254\353\252\205\353\263\264\355\212\270/\354\204\234\355\235\254/solution.js" diff --git "a/problems/\352\265\254\353\252\205\353\263\264\355\212\270/\354\204\234\355\235\254/solution.js" "b/problems/\352\265\254\353\252\205\353\263\264\355\212\270/\354\204\234\355\235\254/solution.js" new file mode 100644 index 0000000..778b3f6 --- /dev/null +++ "b/problems/\352\265\254\353\252\205\353\263\264\355\212\270/\354\204\234\355\235\254/solution.js" @@ -0,0 +1,22 @@ +function solution(people,limit){ + let [ answer, currentWeight, start, end ] = [0, 0, 0, people.length - 1 ]; + people.sort((a,b)=> b-a); + + while(start < end){ + if(currentWeight + people[start] <= limit ){ + currentWeight += people[start]; + start+=1; + } + + if(currentWeight + people[end] <= limit){ + currentWeight += people[end]; + end -= 1; + } else { + currentWeight = 0; + answer +=1 + } + + } + answer += currentWeight != 0 ? 1 : 0; + return start === end ? answer + 1 : answer ; +} From 636ac69da6208ae27f1547ee6122e6156c5c6e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=91=9E=E5=96=9C?= <79238676+Happhee@users.noreply.github.com> Date: Wed, 8 Jun 2022 16:26:50 +0900 Subject: [PATCH 2/5] =?UTF-8?q?feat=20:=20=EA=B5=AC=EB=AA=85=EB=B3=B4?= =?UTF-8?q?=ED=8A=B8=20README.md=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\204\234\355\235\254/README.md" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "problems/\352\265\254\353\252\205\353\263\264\355\212\270/\354\204\234\355\235\254/README.md" diff --git "a/problems/\352\265\254\353\252\205\353\263\264\355\212\270/\354\204\234\355\235\254/README.md" "b/problems/\352\265\254\353\252\205\353\263\264\355\212\270/\354\204\234\355\235\254/README.md" new file mode 100644 index 0000000..f5fd756 --- /dev/null +++ "b/problems/\352\265\254\353\252\205\353\263\264\355\212\270/\354\204\234\355\235\254/README.md" @@ -0,0 +1,36 @@ +# 프로그래머스 [구명보트](https://programmers.co.kr/learn/courses/30/lessons/42885) + +## solution + +```js +function solution(people,limit){ + let [ answer, currentWeight, start, end ] = [0, 0, 0, people.length - 1 ]; + people.sort((a,b)=> b-a); + + while(start < end){ + if(currentWeight + people[start] <= limit ){ + currentWeight += people[start]; + start+=1; + } + + if(currentWeight + people[end] <= limit){ + currentWeight += people[end]; + end -= 1; + } else { + currentWeight = 0; + answer +=1 + } + } + answer += currentWeight != 0 ? 1 : 0 + return start === end ? answer + 1 : answer ; +} +``` + +1. 구조 분해 할당을 통해 결과, 현재 보트의 무게, 시작과 끝을 가리키는 포인터 변수를 초기화 한다. +2. 내림차순으로 people을 정렬한다. +3. 투포인터가 만나기전까지 반복문을 수행한다. + 1. 현재 보트 무게 + 시작 포인터 사람 무게가 제한보다 작거나 같으면 보트에 태우고, 시작 포인터와 현재 보트 무게 증가 시킨다. + 2. 현재 보트 무게 + 끝 포인터 사람 무게가 제한보다 작거나 같으면 보트에 태우고, 끝 포인터는 내리고, 현재 보트 무게를 증가시킨다. + 3. 2가 아니라면 현재 보트 무게 0으로 초기화 및 결과 +1로 보트 수를 갱신한다. +4. 현재 보트 무게가 0이 아니라면 사람이 타고 있으므로 결과 +1 를 진행한다. +5. 시작과 끝 포인터가 동일지점이라면 answer+1 한 값을, 그게 아니라면 answer값을 반환하고 종료한다. From ec460778e3608a3a1c6cdc3e8ff05bb2a47ab4e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=91=9E=E5=96=9C?= <79238676+Happhee@users.noreply.github.com> Date: Wed, 8 Jun 2022 17:37:59 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E2=9C=A8=20=EC=8B=A0=EA=B3=A0=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=EB=B0=9B=EA=B8=B0=20=EC=86=94=EB=A3=A8=EC=85=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../solution.js" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 "problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/solution.js" diff --git "a/problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/solution.js" "b/problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/solution.js" new file mode 100644 index 0000000..abb912c --- /dev/null +++ "b/problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/solution.js" @@ -0,0 +1,19 @@ +function solution(id_list, report, k) { + const resultCount = new Array(id_list.length).fill(0); + const reportCount = new Array(id_list.length).fill(0); + + report = [...new Set(report)] + .map((sentence) => sentence.split(' ')); + + report.forEach(([_, reporter])=> { + reportCount[id_list.indexOf(reporter)] += 1; + }) + + report.forEach(([user,reporter])=>{ + if(reportCount[id_list.indexOf(reporter)] >= k ){ + resultCount[id_list.indexOf(user)] += 1; + } + }) + + return resultCount; +} From d735cbebd004b95956d70f0d16eb762869328a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=91=9E=E5=96=9C?= <79238676+Happhee@users.noreply.github.com> Date: Wed, 8 Jun 2022 17:41:22 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=E2=9C=A8=20=EC=8B=A0=EA=B3=A0=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=EB=B0=9B=EA=B8=B0=20=EB=A6=AC=EB=93=9C=EB=AF=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\204\234\355\235\254/README.md" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/\354\204\234\355\235\254/README.md" diff --git "a/problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/\354\204\234\355\235\254/README.md" "b/problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/\354\204\234\355\235\254/README.md" new file mode 100644 index 0000000..d9d65fd --- /dev/null +++ "b/problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/\354\204\234\355\235\254/README.md" @@ -0,0 +1,31 @@ + +# 프로그래머스 [신고결과받기](https://programmers.co.kr/learn/courses/30/lessons/92334) + +## solution + +```js +function solution(id_list, report, k) { + const resultCount = new Array(id_list.length).fill(0); + const reportCount = new Array(id_list.length).fill(0); + + report = [...new Set(report)].map((sentence) => sentence.split(' ')); + + report.forEach(([_, reporter])=> { + reportCount[id_list.indexOf(reporter)] += 1; + }) + + report.forEach(([user,reporter])=>{ + if(reportCount[id_list.indexOf(reporter)] >= k ){ + resultCount[id_list.indexOf(user)] += 1; + } + }) + return resultCount; + +} +``` + +1. 결과 횟수, 신고 횟수 담을 배열 초기화 +2. report의 중복제거 후 이용자 / 신고자 나눠주기 진행 +3. 신고자 별 신고 당한 횟수를 반복문을 통해 저장한다. +4. k와 신고자별 신고당한 횟수를 비교하여 결과 횟수를 갱신해나간다. +5. 최종적으로 resultCount반환한후 종료. From c6dd4f10aa47ece50ef7ba2612c32a7b460cca17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=91=9E=E5=96=9C?= <79238676+Happhee@users.noreply.github.com> Date: Wed, 8 Jun 2022 17:42:10 +0900 Subject: [PATCH 5/5] =?UTF-8?q?Rename=20problems/=EC=8B=A0=EA=B3=A0?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=EB=B0=9B=EA=B8=B0/solution.js=20to=20problem?= =?UTF-8?q?s/=EC=8B=A0=EA=B3=A0=EA=B2=B0=EA=B3=BC=EB=B0=9B=EA=B8=B0/?= =?UTF-8?q?=EC=84=9C=ED=9D=AC/solution.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\204\234\355\235\254/solution.js" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/solution.js" => "problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/\354\204\234\355\235\254/solution.js" (100%) diff --git "a/problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/solution.js" "b/problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/\354\204\234\355\235\254/solution.js" similarity index 100% rename from "problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/solution.js" rename to "problems/\354\213\240\352\263\240\352\262\260\352\263\274\353\260\233\352\270\260/\354\204\234\355\235\254/solution.js"