๋ฐ˜์‘ํ˜•

์ฝ”๋”ฉํ…Œ์ŠคํŠธ์—ฐ์Šต 13

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

Problem Description ์˜์–ด ๋Œ€์†Œ๋ฌธ์ž๋กœ ์ด๋ฃจ์–ด์ง„ ๋ฌธ์ž์—ด my_string์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, my_string์„ ๋ชจ๋‘ ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พธ๊ณ  ์•ŒํŒŒ๋ฒณ ์ˆœ์„œ๋Œ€๋กœ ์ •๋ ฌํ•œ ๋ฌธ์ž์—ด์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. 0

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

Problem Description ์ •์ˆ˜ num๊ณผ k๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, num์„ ์ด๋ฃจ๋Š” ์ˆซ์ž ์ค‘์— k๊ฐ€ ์žˆ์œผ๋ฉด num์˜ ๊ทธ ์ˆซ์ž๊ฐ€ ์žˆ๋Š” ์ž๋ฆฌ ์ˆ˜๋ฅผ returnํ•˜๊ณ  ์—†์œผ๋ฉด -1์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. 0 < num < 1,000,000 0 ≤ k Number(el)).indexOf(k) + 1 || -1 } Array ์ธ์Šคํ„ด์Šค์˜ indexOf() ๋ฉ”์„œ๋“œ๋Š” ๋ฐฐ์—ด์—์„œ ์ฃผ์–ด์ง„ ์š”์†Œ๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ๋Š” ์ฒซ ๋ฒˆ์งธ ์ธ๋ฑ์Šค๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ณ , ์ฐพ์„ ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ -1์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. https://school.programmers.co.kr/learn/courses/30/lessons/120904 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] 369 ๊ฒŒ์ž„

Problem Description ๋จธ์“ฑ์ด๋Š” ์นœ๊ตฌ๋“ค๊ณผ 369๊ฒŒ์ž„์„ ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. 369๊ฒŒ์ž„์€ 1๋ถ€ํ„ฐ ์ˆซ์ž๋ฅผ ํ•˜๋‚˜์”ฉ ๋Œ€๋ฉฐ 3, 6, 9๊ฐ€ ๋“ค์–ด๊ฐ€๋Š” ์ˆซ์ž๋Š” ์ˆซ์ž ๋Œ€์‹  3, 6, 9์˜ ๊ฐœ์ˆ˜๋งŒํผ ๋ฐ•์ˆ˜๋ฅผ ์น˜๋Š” ๊ฒŒ์ž„์ž…๋‹ˆ๋‹ค. ๋จธ์“ฑ์ด๊ฐ€ ๋งํ•ด์•ผํ•˜๋Š” ์ˆซ์ž order๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ๋จธ์“ฑ์ด๊ฐ€ ์ณ์•ผํ•  ๋ฐ•์ˆ˜ ํšŸ์ˆ˜๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. 1 ≤ order ≤ 1,000,000 Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 3์€ 3์ด 1๊ฐœ ์žˆ์œผ๋ฏ€๋กœ 1์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 29423์€ 3์ด 1๊ฐœ, 9๊ฐ€ 1๊ฐœ ์žˆ์œผ๋ฏ€๋กœ 2๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. My solution function solution(order) { const array = order.toS..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/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 ๊ฐ€์œ„๋Š” 2 ๋ฐ”์œ„๋Š” 0 ๋ณด๋Š” 5๋กœ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€์œ„ ๋ฐ”์œ„ ๋ณด๋ฅผ ๋‚ด๋Š” ์ˆœ์„œ๋Œ€๋กœ ๋‚˜ํƒ€๋‚ธ ๋ฌธ์ž์—ด rsp๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, rsp์— ์ €์žฅ๋œ ๊ฐ€์œ„ ๋ฐ”์œ„ ๋ณด๋ฅผ ๋ชจ๋‘ ์ด๊ธฐ๋Š” ๊ฒฝ์šฐ๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋‚˜ํƒ€๋‚ธ ๋ฌธ์ž์—ด์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. 0 < rsp์˜ ๊ธธ์ด ≤ 100 rsp์™€ ๊ธธ์ด๊ฐ€ ๊ฐ™์€ ๋ฌธ์ž์—ด์„ return ํ•ฉ๋‹ˆ๋‹ค. rsp๋Š” ์ˆซ์ž 0, 2, 5๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 "2"๋Š” ๊ฐ€์œ„์ด๋ฏ€๋กœ ๋ฐ”์œ„๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” "0"์„ return ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 "205"๋Š” ์ˆœ์„œ๋Œ€๋กœ ๊ฐ€์œ„, ๋ฐ”์œ„, ๋ณด์ด๊ณ  ์ด๋ฅผ ๋ชจ๋‘ ์ด๊ธฐ๋ ค๋ฉด ๋ฐ”์œ„, ๋ณด, ๊ฐ€์œ„๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ๋‚ด์•ผํ•˜๋ฏ€๋กœ “052”๋ฅผ returnํ•ฉ..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/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 ์ •์ˆ˜ 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 ๋‘ ๋ฐฐ์—ด์ด ์–ผ๋งˆ๋‚˜ ์œ ์‚ฌํ•œ์ง€ ํ™•์ธํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด ๋ฐฐ์—ด s1๊ณผ s2๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ๊ฐ™์€ ์›์†Œ์˜ ๊ฐœ์ˆ˜๋ฅผ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.๋จธ์“ฑ์ด๋Š” ํ•™๊ต์—์„œ ํ‚ค ์ˆœ์œผ๋กœ ์ค„์„ ์„ค ๋•Œ ๋ช‡ ๋ฒˆ์งธ๋กœ ์„œ์•ผ ํ•˜๋Š”์ง€ ๊ถ๊ธˆํ•ด์กŒ์Šต๋‹ˆ๋‹ค. ๋จธ์“ฑ์ด๋„ค ๋ฐ˜ ์นœ๊ตฌ๋“ค์˜ ํ‚ค๊ฐ€ ๋‹ด๊ธด ์ •์ˆ˜ ๋ฐฐ์—ด array์™€ ๋จธ์“ฑ์ด์˜ ํ‚ค height๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ๋จธ์“ฑ์ด๋ณด๋‹ค ํ‚ค ํฐ ์‚ฌ๋žŒ ์ˆ˜๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions 1 ≤ array์˜ ๊ธธ์ด ≤ 100 1 ≤ height ≤ 200 1 ≤ array์˜ ์›์†Œ ≤ 200 Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 149, 180, 192, 170 ์ค‘ ๋จธ์“ฑ์ด๋ณด๋‹ค ํ‚ค๊ฐ€ ํฐ ์‚ฌ๋žŒ์€ 1..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/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] ์‚ผ๊ฐํ˜•์˜ ์™„์„ฑ์กฐ๊ฑด (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์ด ๋‚˜๋จธ์ง€ ๋‘ ..

๋ฐ˜์‘ํ˜•