๋ฐ˜์‘ํ˜•

์ฝ”ํ…Œ์—ฐ์Šต 18

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๋ฐฐ์—ด ํšŒ์ „์‹œํ‚ค๊ธฐ

Problem Description์ •์ˆ˜๊ฐ€ ๋‹ด๊ธด ๋ฐฐ์—ด numbers์™€ ๋ฌธ์ž์—ด direction๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ๋ฐฐ์—ด numbers์˜ ์›์†Œ๋ฅผ direction ๋ฐฉํ–ฅ์œผ๋กœ ํ•œ ์นธ์”ฉ ํšŒ์ „์‹œํ‚จ ๋ฐฐ์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions.3 ≤ numbers์˜ ๊ธธ์ด ≤ 20direction์€ "left" ์™€ "right" ๋‘˜ ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค. Input/Output Example์ž…์ถœ๋ ฅ ์˜ˆ #1 numbers ๊ฐ€ [1, 2, 3]์ด๊ณ  direction์ด "right" ์ด๋ฏ€๋กœ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ํ•œ ์นธ์”ฉ ํšŒ์ „์‹œํ‚จ [3, 1, 2]๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค.์ž…์ถœ๋ ฅ ์˜ˆ #2  numbers ๊ฐ€ [4, 455, 6, 4, -1, 45, 6]์ด๊ณ  direction์ด "left" ์ด๋ฏ€๋กœ ์™ผ์ชฝ์œผ..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์ฃผ์‚ฌ์œ„์˜ ๊ฐœ์ˆ˜

Problem Description ๋จธ์“ฑ์ด๋Š” ์ง์œก๋ฉด์ฒด ๋ชจ์–‘์˜ ์ƒ์ž๋ฅผ ํ•˜๋‚˜ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๋ฐ ์ด ์ƒ์ž์— ์ •์œก๋ฉด์ฒด ๋ชจ์–‘์˜ ์ฃผ์‚ฌ์œ„๋ฅผ ์ตœ๋Œ€ํ•œ ๋งŽ์ด ์ฑ„์šฐ๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. ์ƒ์ž์˜ ๊ฐ€๋กœ, ์„ธ๋กœ, ๋†’์ด๊ฐ€ ์ €์žฅ๋˜์–ด์žˆ๋Š” ๋ฐฐ์—ด box์™€ ์ฃผ์‚ฌ์œ„ ๋ชจ์„œ๋ฆฌ์˜ ๊ธธ์ด ์ •์ˆ˜ n์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ƒ์ž์— ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋Š” ์ฃผ์‚ฌ์œ„์˜ ์ตœ๋Œ€ ๊ฐœ์ˆ˜๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions. box์˜ ๊ธธ์ด๋Š” 3์ž…๋‹ˆ๋‹ค. box[0] = ์ƒ์ž์˜ ๊ฐ€๋กœ ๊ธธ์ด box[1] = ์ƒ์ž์˜ ์„ธ๋กœ ๊ธธ์ด box[2] = ์ƒ์ž์˜ ๋†’์ด ๊ธธ์ด Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 ์ƒ์ž์˜ ํฌ๊ธฐ๊ฐ€ ๊ฐ€๋กœ 1, ์„ธ๋กœ 1, ๋†’์ด 1์ด๋ฏ€๋กœ ๋ชจ์„œ๋ฆฌ์˜ ๊ธธ์ด๊ฐ€ 1์ธ ์ฃผ์‚ฌ์œ„๋Š” 1๊ฐœ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 ์ƒ์ž์˜ ํฌ๊ธฐ๊ฐ€..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๊ฐœ๋ฏธ ๊ตฐ๋‹จ โœ…

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

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๋ฌธ์ž์—ด ์ •๋ ฌํ•˜๊ธฐ (1)

Problem Description ๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, my_string ์•ˆ์— ์žˆ๋Š” ์ˆซ์ž๋งŒ ๊ณจ๋ผ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•œ ๋ฆฌ์ŠคํŠธ๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์ž‘์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. 1 ≤ my_string์˜ ๊ธธ์ด ≤ 100 my_string์—๋Š” ์ˆซ์ž๊ฐ€ ํ•œ ๊ฐœ ์ด์ƒ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. my_string์€ ์˜์–ด ์†Œ๋ฌธ์ž ๋˜๋Š” 0๋ถ€ํ„ฐ 9๊นŒ์ง€์˜ ์ˆซ์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. - - - Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 "hi12392"์— ์žˆ๋Š” ์ˆซ์ž 1, 2, 3, 9, 2๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•œ [1, 2, 2, 3, 9]๋ฅผ return ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 "p2o4i8gj2"์— ์žˆ๋Š” ์ˆซ์ž 2, 4, 8, 2๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•œ [2, 2, 4,..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ๊ฐ€์žฅ ํฐ ์ˆ˜ ์ฐพ๊ธฐ

Problem Description ์ •์ˆ˜ ๋ฐฐ์—ด array๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ๊ฐ€์žฅ ํฐ ์ˆ˜์™€ ๊ทธ ์ˆ˜์˜ ์ธ๋ฑ์Šค๋ฅผ ๋‹ด์€ ๋ฐฐ์—ด์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. 1 ≤ array์˜ ๊ธธ์ด ≤ 100 0 ≤ array ์›์†Œ ≤ 1,000 array์— ์ค‘๋ณต๋œ ์ˆซ์ž๋Š” ์—†์Šต๋‹ˆ๋‹ค. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 1, 8, 3 ์ค‘ ๊ฐ€์žฅ ํฐ ์ˆ˜๋Š” 8์ด๊ณ  ์ธ๋ฑ์Šค 1์— ์žˆ์Šต๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 9, 10, 11, 8 ์ค‘ ๊ฐ€์žฅ ํฐ ์ˆ˜๋Š” 11์ด๊ณ  ์ธ๋ฑ์Šค 2์— ์žˆ์Šต๋‹ˆ๋‹ค. My solution function solution(array) { var answer = []; answer.push(Math.max(...array)) answer.push(arra..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] n์˜ ๋ฐฐ์ˆ˜ ๊ณ ๋ฅด๊ธฐ

Problem Description ๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. my_string์•ˆ์˜ ๋ชจ๋“  ์ž์—ฐ์ˆ˜๋“ค์˜ ํ•ฉ์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.์ •์ˆ˜ n๊ณผ ์ •์ˆ˜ ๋ฐฐ์—ด numlist๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, numlist์—์„œ n์˜ ๋ฐฐ์ˆ˜๊ฐ€ ์•„๋‹Œ ์ˆ˜๋“ค์„ ์ œ๊ฑฐํ•œ ๋ฐฐ์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions. 1 ≤ n ≤ 10,000 1 ≤ numlist์˜ ํฌ๊ธฐ ≤ 100 1 ≤ numlist์˜ ์›์†Œ ≤ 100,000 Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 numlist์—์„œ 3์˜ ๋ฐฐ์ˆ˜๋งŒ์„ ๋‚จ๊ธด [6, 9, 12]๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 numlist์—์„œ 5์˜ ๋ฐฐ์ˆ˜๋งŒ์„ ๋‚จ๊ธด [10, 5]๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/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] ์ตœ๋Œ“๊ฐ’ ๋งŒ๋“ค๊ธฐ (1)

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(numbers) { const sortArray = numbers.sort((a, b) => b-a) return sortArray[0] * sortArray[1..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/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..

๋ฐ˜์‘ํ˜•