๋ฐ˜์‘ํ˜•

๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ 293

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

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

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/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] ํ”ผ์ž ๋‚˜๋ˆ  ๋จน๊ธฐ (3)

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

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

Problem Description ์ค‘์•™๊ฐ’์€ ์–ด๋–ค ์ฃผ์–ด์ง„ ๊ฐ’๋“ค์„ ํฌ๊ธฐ์˜ ์ˆœ์„œ๋Œ€๋กœ ์ •๋ ฌํ–ˆ์„ ๋•Œ ๊ฐ€์žฅ ์ค‘์•™์— ์œ„์น˜ํ•˜๋Š” ๊ฐ’์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 1, 2, 7, 10, 11์˜ ์ค‘์•™๊ฐ’์€ 7์ž…๋‹ˆ๋‹ค. ์ •์ˆ˜ ๋ฐฐ์—ด array๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ์ค‘์•™๊ฐ’์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. array์˜ ๊ธธ์ด๋Š” ํ™€์ˆ˜์ž…๋‹ˆ๋‹ค. 0 0) { return 1 } else if (dot[0] < 0 && dot[1] < 0) { return 3 } else { return 4 } } Another solutions function solution(dot) { const [num,num2] = dot; con..

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์ค‘์•™๊ฐ’ ๊ตฌํ•˜๊ธฐ

Problem Description ์ค‘์•™๊ฐ’์€ ์–ด๋–ค ์ฃผ์–ด์ง„ ๊ฐ’๋“ค์„ ํฌ๊ธฐ์˜ ์ˆœ์„œ๋Œ€๋กœ ์ •๋ ฌํ–ˆ์„ ๋•Œ ๊ฐ€์žฅ ์ค‘์•™์— ์œ„์น˜ํ•˜๋Š” ๊ฐ’์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 1, 2, 7, 10, 11์˜ ์ค‘์•™๊ฐ’์€ 7์ž…๋‹ˆ๋‹ค. ์ •์ˆ˜ ๋ฐฐ์—ด array๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ์ค‘์•™๊ฐ’์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด๋ณด์„ธ์š”. Restrictions. array์˜ ๊ธธ์ด๋Š” ํ™€์ˆ˜์ž…๋‹ˆ๋‹ค. 0 < array์˜ ๊ธธ์ด < 100 -1,000

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค/JS] ์™ธ๊ณ„ํ–‰์„ฑ์˜ ๋‚˜์ด

Problem Description. ์šฐ์ฃผ์—ฌํ–‰์„ ํ•˜๋˜ ๋จธ์“ฑ์ด๋Š” ์—”์ง„ ๊ณ ์žฅ์œผ๋กœ PROGRAMMERS-962 ํ–‰์„ฑ์— ๋ถˆ์‹œ์ฐฉํ•˜๊ฒŒ ๋์Šต๋‹ˆ๋‹ค. ์ž…๊ตญ์‹ฌ์‚ฌ์—์„œ ๋‚˜์ด๋ฅผ ๋งํ•ด์•ผ ํ•˜๋Š”๋ฐ, PROGRAMMERS-962 ํ–‰์„ฑ์—์„œ๋Š” ๋‚˜์ด๋ฅผ ์•ŒํŒŒ๋ฒณ์œผ๋กœ ๋งํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. a๋Š” 0, b๋Š” 1, c๋Š” 2, ..., j๋Š” 9์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 23์‚ด์€ cd, 51์‚ด์€ fb๋กœ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค. ๋‚˜์ด age๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ PROGRAMMER-962์‹ ๋‚˜์ด๋ฅผ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions. age๋Š” ์ž์—ฐ์ˆ˜์ž…๋‹ˆ๋‹ค. age ≤ 1,000 PROGRAMMERS-962 ํ–‰์„ฑ์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋งŒ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. Input/Output Example. age result 23 "cd" 51 "fb" 100..

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

Problem Description ์ •์ˆ˜ ๋ฐฐ์—ด numbers๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. numbers์˜ ์›์†Œ ์ค‘ ๋‘ ๊ฐœ๋ฅผ ๊ณฑํ•ด ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ“๊ฐ’์„ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. Restrictions. -10,000 ≤ numbers์˜ ์›์†Œ ≤ 10,000 2 ≤ numbers ์˜ ๊ธธ์ด ≤ 100. Input/Output Example ์ž…์ถœ๋ ฅ ์˜ˆ #1 ๋‘ ์ˆ˜์˜ ๊ณฑ์ค‘ ์ตœ๋Œ“๊ฐ’์€ -3 * -5 = 15 ์ž…๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 ๋‘ ์ˆ˜์˜ ๊ณฑ์ค‘ ์ตœ๋Œ“๊ฐ’์€ 10 * 24 = 240 ์ž…๋‹ˆ๋‹ค. My solution function solution(numbers) { numbers.sort((a, b) => a - b); const length = numbers.length; const posi..

[React] React Hook "useSelector" cannot be called inside a callback ์—๋Ÿฌ ๋ฐ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

Intro ์•ˆ๋…•ํ•˜์„ธ์š”. react hook useSelector ๋ฅผ ์‚ฌ์šฉํ•˜๋˜ ๋„์ค‘ ์•„๋ž˜์˜ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. React Hook "useSelector" cannot be called inside a callback function YourComponent() { useEffect(() => { useSelector((state: RootState) => state.code[SOME_DATA]) }, []) } Why? react hook์„ ์‚ฌ์šฉํ•  ๋•Œ๋Š” ์ค‘์š”ํ•œ 2๊ฐ€์ง€ ๊ทœ์น™์ด ์žˆ์Šต๋‹ˆ๋‹ค. 1๏ธโƒฃ Only Call Hooks at the Top Level ๋ฃจํ”„ ์กฐ๊ฑด ๋˜๋Š” ์ค‘์ฒฉ๋œ ํ•จ์ˆ˜ ๋‚ด์—์„œ Hooks๋ฅผ ํ˜ธ์ถœํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ํ•ญ์ƒ React ํ•จ์ˆ˜์˜ Top Level์—์„œ Hooks๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ทœ์น™์„..

Framework/React 2023.09.18
๋ฐ˜์‘ํ˜•