js

โœ… ์žฌ๊ท€ ํ’€์ด answer=0def dfs(numbers,target,cur_idx,cur_total): global answer # ํƒˆ์ถœ ์กฐ๊ฑด(๋ชจ๋“  ์ˆ˜ ์ˆœํšŒ) if cur_idx==len(numbers): if cur_total==target: answer+=1 return else: dfs(numbers,target,cur_idx+1,cur_total+numbers[cur_idx]) dfs(numbers,target,cur_idx+1,cur_total-numbers[cur_idx])def solution(numbers, target): global answer dfs(numbers,target,0,..
[Lv1] ํฐ์ผ“๋ชฌfunction solution(nums) { const map=new Map(); //ํฐ์ผ“๋ชฌ ์ข…๋ฅ˜ ๊ตฌํ•˜๊ธฐ for(const num of nums){ map.set(num,map.get(num)+1||1) } const type=map.size return Math.min(type,Math.floor(nums.length/2));}์ตœ๋Œ€ํ•œ ๋‹ค์–‘ํ•œ ์ข…๋ฅ˜์˜ ํฐ์ผ“๋ชฌ์„ ๊ฐ€์ ธ๊ฐ€๊ธธ ์›ํ•˜๊ณ , nums/2๋งŒํผ์˜ ํฐ์ผ“๋ชฌ์„ ๊ฐ€์ ธ๊ฐˆ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํฐ์ผ“๋ชฌ ์ข…๋ฅ˜์˜ ์ˆ˜์™€ nums/2์ค‘ ์ตœ์†Œ๊ฐ’์„ ๋ฆฌํ„ดํ•ด์ฃผ๋ฉด ๋œ๋‹ค.   ๐Ÿ›  Refactorfunction solution(nums) { //ํฐ์ผ“๋ชฌ ์ข…๋ฅ˜ ๊ตฌํ•˜๊ธฐ const set=new Set(nums); c..
keyDown/keyUp ์ด๋ฒคํŠธ๋ฅผ ์‚ฌ์šฉํ• ๋•Œ, ์˜์–ด๋Š” ๊ดœ์ฐฎ์ง€๋งŒ ํ•œ๊ตญ์–ด๋กœ ์ž…๋ ฅํ•˜๋ฉด ์ด๋Ÿฐ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. ๐Ÿค” Why? ์ด ๋ฌธ์ œ๋Š” ํ•œ๊ธ€์˜ ์กฐํ•ฉํ˜• ์ž…๋ ฅ ๋ฐฉ์‹ ๋•Œ๋ฌธ์ด๋ผ๊ณ ํ•œ๋‹ค. ํ•œ๊ธ€ ์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ ํ‚ค ์ž…๋ ฅ์ด ์กฐํ•ฉ๋˜์–ด ํ•˜๋‚˜์˜ ๊ธ€์ž๋ฅผ ์™„์„ฑํ•˜๋Š” ๊ณผ์ •์„ ๊ฑฐ์น˜๊ธฐ ๋•Œ๋ฌธ์—, key Event๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ์‹œ์ ์—๋Š” ์ž…๋ ฅ์ด ์™„์ „ํžˆ ์™„์„ฑ๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•œ๋‹ค.  e.nativeEvent.isComposing  ์ด ์†์„ฑ์€ ์‚ฌ์šฉ์ž๊ฐ€ ํ…์ŠคํŠธ ์ž…๋ ฅ ์ค‘์— ๋ฌธ์ž ์กฐํ•ฉ(์˜ˆ: ํ•œ๊ธ€ ์ž์Œ๊ณผ ๋ชจ์Œ ์กฐํ•ฉ)์ด ์ง„ํ–‰ ์ค‘์ธ์ง€ ์—ฌ๋ถ€๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. ์ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํ‚ค ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•  ๋•Œ ์ž…๋ ฅ์ด ์™„์„ฑ๋œ ์ƒํƒœ์ธ์ง€๋ฅผ ํ™•์ธํ•˜์—ฌ, ์ž…๋ ฅ์˜ ์™„์„ฑ์ด ๋œ ๊ฒฝ์šฐ์—๋งŒ ๊ฒ€์ƒ‰์ฒ˜๋ฆฌ๋ฅผ ์‹คํ–‰ํ•˜๋„๋ก ํ•œ๋‹ค. const handleKeyDown: Keyboar..
Yuuuki
'js' ํƒœ๊ทธ์˜ ๊ธ€ ๋ชฉ๋ก