๋ฐ˜์‘ํ˜•

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ 25

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ํ”ผ์ž ๋‚˜๋ˆ  ๋จน๊ธฐ (2)

Problem Description ๋จธ์“ฑ์ด๋„ค ํ”ผ์ž๊ฐ€๊ฒŒ๋Š” ํ”ผ์ž๋ฅผ ์—ฌ์„ฏ ์กฐ๊ฐ์œผ๋กœ ์ž˜๋ผ ์ค๋‹ˆ๋‹ค. ํ”ผ์ž๋ฅผ ๋‚˜๋ˆ ๋จน์„ ์‚ฌ๋žŒ์˜ ์ˆ˜ n์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, n๋ช…์ด ์ฃผ๋ฌธํ•œ ํ”ผ์ž๋ฅผ ๋‚จ๊ธฐ์ง€ ์•Š๊ณ  ๋ชจ๋‘ ๊ฐ™์€ ์ˆ˜์˜ ํ”ผ์ž ์กฐ๊ฐ์„ ๋จน์–ด์•ผ ํ•œ๋‹ค๋ฉด ์ตœ์†Œ ๋ช‡ ํŒ์„ ์‹œ์ผœ์•ผ ํ•˜๋Š”์ง€๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. 1 ≤ n ≤ 100 Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 6๋ช…์ด ๋ชจ๋‘ ๊ฐ™์€ ์–‘์„ ๋จน๊ธฐ ์œ„ํ•ด ํ•œ ํŒ์„ ์‹œ์ผœ์•ผ ํ”ผ์ž๊ฐ€ 6์กฐ๊ฐ์œผ๋กœ ๋ชจ๋‘ ํ•œ ์กฐ๊ฐ์”ฉ ๋จน์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 10๋ช…์ด ๋ชจ๋‘ ๊ฐ™์€ ์–‘์„ ๋จน๊ธฐ ์œ„ํ•ด ์ตœ์†Œ 5ํŒ์„ ์‹œ์ผœ์•ผ ํ”ผ์ž๊ฐ€ 30์กฐ๊ฐ์œผ๋กœ ๋ชจ๋‘ ์„ธ ์กฐ๊ฐ์”ฉ ๋จน์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #3 4๋ช…์ด ๋ชจ๋‘ ๊ฐ™์€ ์–‘์„ ๋จน๊ธฐ ์œ„ํ•ด ์ตœ์†Œ 2ํŒ์„ ์‹œํ‚ค๋ฉด ..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์ˆœ์„œ์Œ์˜ ๊ฐœ์ˆ˜

Problem Description ์ˆœ์„œ์Œ์ด๋ž€ ๋‘ ๊ฐœ์˜ ์ˆซ์ž๋ฅผ ์ˆœ์„œ๋ฅผ ์ •ํ•˜์—ฌ ์ง์ง€์–ด ๋‚˜ํƒ€๋‚ธ ์Œ์œผ๋กœ (a, b)๋กœ ํ‘œ๊ธฐํ•ฉ๋‹ˆ๋‹ค. ์ž์—ฐ์ˆ˜ n์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ ๋‘ ์ˆซ์ž์˜ ๊ณฑ์ด n์ธ ์ž์—ฐ์ˆ˜ ์ˆœ์„œ์Œ์˜ ๊ฐœ์ˆ˜๋ฅผ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions. 1 ≤ n ≤ 1,000,000 Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 n์ด 20 ์ด๋ฏ€๋กœ ๊ณฑ์ด 20์ธ ์ˆœ์„œ์Œ์€ (1, 20), (2, 10), (4, 5), (5, 4), (10, 2), (20, 1) ์ด๋ฏ€๋กœ 6์„ returnํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 n์ด 100 ์ด๋ฏ€๋กœ ๊ณฑ์ด 100์ธ ์ˆœ์„œ์Œ์€ (1, 100), (2, 50), (4, 25), (5, 20), (10, 10), (20, 5), (25, 4), (5..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž

Problem Description ๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜ํ•œ ๋ฌธ์ž์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions 1 ≤ my_string์˜ ๊ธธ์ด ≤ 1,000 my_string์€ ์˜์–ด ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž๋กœ๋งŒ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ # 1 ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พผ "CCCccc"๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 ์†Œ๋ฌธ์ž๋Š” ๋Œ€๋ฌธ์ž๋กœ ๋Œ€๋ฌธ์ž๋Š” ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พผ "ABcDeFGHij"๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. My solution function solution(my_string) { return my_string.split("").map((x) => x ..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์ง์ˆ˜๋Š” ์‹ซ์–ด์š”

Problem Description ์ •์ˆ˜ n์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, n ์ดํ•˜์˜ ํ™€์ˆ˜๊ฐ€ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ๋‹ด๊ธด ๋ฐฐ์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions 1 ≤ n ≤ 100 Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 10 ์ดํ•˜์˜ ํ™€์ˆ˜๊ฐ€ ๋‹ด๊ธด ๋ฐฐ์—ด [1, 3, 5, 7, 9]๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 15 ์ดํ•˜์˜ ํ™€์ˆ˜๊ฐ€ ๋‹ด๊ธด ๋ฐฐ์—ด [1, 3, 5, 7, 9, 11, 13, 15]๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. My solution function solution(n) { let array = []; let i for (i = 0; i x%2 == 1) } Another solutions function solution(n) { var answer = [..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์ค‘๋ณต๋œ ์ˆซ์ž ๊ฐœ์ˆ˜

Problem Description ์ •์ˆ˜๊ฐ€ ๋‹ด๊ธด ๋ฐฐ์—ด array์™€ ์ •์ˆ˜ n์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, array์— n์ด ๋ช‡ ๊ฐœ ์žˆ๋Š” ์ง€๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions 1 ≤ array์˜ ๊ธธ์ด ≤ 100 0 ≤ array์˜ ์›์†Œ ≤ 1,000 0 ≤ n ≤ 1,000 Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 [1, 1, 2, 3, 4, 5] ์—๋Š” 1์ด 2๊ฐœ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 [0, 2, 3, 4] ์—๋Š” 1์ด 0๊ฐœ ์žˆ์Šต๋‹ˆ๋‹ค. My solution function solution(array, n) { return array.filter((x) => x == n).length } https://school.programmers.co.kr/l..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ํ”ผ์ž ๋‚˜๋ˆ  ๋จน๊ธฐ (1)

Problem Description ๋จธ์“ฑ์ด๋„ค ํ”ผ์ž๊ฐ€๊ฒŒ๋Š” ํ”ผ์ž๋ฅผ ์ผ๊ณฑ ์กฐ๊ฐ์œผ๋กœ ์ž˜๋ผ ์ค๋‹ˆ๋‹ค. ํ”ผ์ž๋ฅผ ๋‚˜๋ˆ ๋จน์„ ์‚ฌ๋žŒ์˜ ์ˆ˜ n์ด ์ฃผ์–ด์งˆ ๋•Œ, ๋ชจ๋“  ์‚ฌ๋žŒ์ด ํ”ผ์ž๋ฅผ ํ•œ ์กฐ๊ฐ ์ด์ƒ ๋จน๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•œ ํ”ผ์ž์˜ ์ˆ˜๋ฅผ return ํ•˜๋Š” solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions 1 ≤ n ≤ 100 Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 7๋ช…์ด ์ตœ์†Œ ํ•œ ์กฐ๊ฐ์”ฉ ๋จน๊ธฐ ์œ„ํ•ด์„œ ์ตœ์†Œ 1ํŒ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 1๋ช…์€ ์ตœ์†Œ ํ•œ ์กฐ๊ฐ์„ ๋จน๊ธฐ ์œ„ํ•ด 1ํŒ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 15๋ช…์ด ์ตœ์†Œ ํ•œ ์กฐ๊ฐ์”ฉ ๋จน๊ธฐ ์œ„ํ•ด์„œ ์ตœ์†Œ 3ํŒ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. My solution function solution(n) { if ((n % 7) >= 0) { return Math.ceil(n/7) } } An..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์‚ผ๊ฐํ˜•์˜ ์™„์„ฑ์กฐ๊ฑด (1)

Problem Description ์„ ๋ถ„ ์„ธ ๊ฐœ๋กœ ์‚ผ๊ฐํ˜•์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€์žฅ ๊ธด ๋ณ€์˜ ๊ธธ์ด๋Š” ๋‹ค๋ฅธ ๋‘ ๋ณ€์˜ ๊ธธ์ด์˜ ํ•ฉ๋ณด๋‹ค ์ž‘์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์‚ผ๊ฐํ˜•์˜ ์„ธ ๋ณ€์˜ ๊ธธ์ด๊ฐ€ ๋‹ด๊ธด ๋ฐฐ์—ด sides์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์„ธ ๋ณ€์œผ๋กœ ์‚ผ๊ฐํ˜•์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค๋ฉด 1, ๋งŒ๋“ค ์ˆ˜ ์—†๋‹ค๋ฉด 2๋ฅผ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions sides์˜ ์›์†Œ๋Š” ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค. sides์˜ ๊ธธ์ด๋Š” 3์ž…๋‹ˆ๋‹ค. 1 ≤ sides์˜ ์›์†Œ ≤ 1,000 Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 ๊ฐ€์žฅ ํฐ ๋ณ€์ธ 3์ด ๋‚˜๋จธ์ง€ ๋‘ ๋ณ€์˜ ํ•ฉ 3๊ณผ ๊ฐ™์œผ๋ฏ€๋กœ ์‚ผ๊ฐํ˜•์„ ์™„์„ฑํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ 2๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 ๊ฐ€์žฅ ํฐ ๋ณ€์ธ 6์ด ๋‚˜๋จธ์ง€ ๋‘ ..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๋ฌธ์ž ๋ฐ˜๋ณต ์ถœ๋ ฅํ•˜๊ธฐ

Problem Description ๋ฌธ์ž์—ด my_string๊ณผ ์ •์ˆ˜ n์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, my_string์— ๋“ค์–ด์žˆ๋Š” ๊ฐ ๋ฌธ์ž๋ฅผ n๋งŒํผ ๋ฐ˜๋ณตํ•œ ๋ฌธ์ž์—ด์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions 2 ≤ my_string ๊ธธ์ด ≤ 5 2 ≤ n ≤ 10 "my_string"์€ ์˜์–ด ๋Œ€์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 "hello"์˜ ๊ฐ ๋ฌธ์ž๋ฅผ ์„ธ ๋ฒˆ์”ฉ ๋ฐ˜๋ณตํ•œ "hhheeellllllooo"๋ฅผ return ํ•ฉ๋‹ˆ๋‹ค. My solution function solution(my_string, n) { return (my_string.split("").map((x) => x.repeat(n))).join('') } Anot..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ํŠน์ • ๋ฌธ์ž ์ œ๊ฑฐํ•˜๊ธฐ

Problem Description ๋ฌธ์ž์—ด my_string๊ณผ ๋ฌธ์ž letter์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. my_string์—์„œ letter๋ฅผ ์ œ๊ฑฐํ•œ ๋ฌธ์ž์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions 1 ≤ my_string์˜ ๊ธธ์ด ≤ 100 letter์€ ๊ธธ์ด๊ฐ€ 1์ธ ์˜๋ฌธ์ž์ž…๋‹ˆ๋‹ค. my_string๊ณผ letter์€ ์•ŒํŒŒ๋ฒณ ๋Œ€์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. ๋Œ€๋ฌธ์ž์™€ ์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•ฉ๋‹ˆ๋‹ค. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 "abcdef" ์—์„œ "f"๋ฅผ ์ œ๊ฑฐํ•œ "abcde"๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 "BCBdbe" ์—์„œ "B"๋ฅผ ๋ชจ๋‘ ์ œ๊ฑฐํ•œ "Cdbe"๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. My solution function solution(my_string..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๋ฐฐ์—ด ๋‘๋ฐฐ ๋งŒ๋“ค๊ธฐ

Problem Description ์ •์ˆ˜ ๋ฐฐ์—ด numbers๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. numbers์˜ ๊ฐ ์›์†Œ์— ๋‘๋ฐฐํ•œ ์›์†Œ๋ฅผ ๊ฐ€์ง„ ๋ฐฐ์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions -10,000 ≤ numbers์˜ ์›์†Œ ≤ 10,000 1 ≤ numbers์˜ ๊ธธ์ด ≤ 1,000 Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 [1, 2, 3, 4, 5]์˜ ๊ฐ ์›์†Œ์— ๋‘๋ฐฐ๋ฅผ ํ•œ ๋ฐฐ์—ด [2, 4, 6, 8, 10]์„ returnํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 [1, 2, 100, -99, 1, 2, 3]์˜ ๊ฐ ์›์†Œ์— ๋‘๋ฐฐ๋ฅผ ํ•œ ๋ฐฐ์—ด [2, 4, 200, -198, 2, 4, 6]์„ returnํ•ฉ๋‹ˆ๋‹ค. My solution function solution(numbers) {..

๋ฐ˜์‘ํ˜•