ํ์ ๊ณต๋ถ/๐ซง ์๊ณ ๋ฆฌ์ฆ ๊ณต๋ถ
[์๊ณ ๋ฆฌ์ฆ || ํ๋ก๊ทธ๋๋จธ์ค] ์์ฃผํ์ง ๋ชปํ ์ ์
๋์๐
2023. 7. 17. 10:06
728x90
๋ฌธ์ ์์ฒด๋ ์ฌ์๋ณด์์ผ๋,
๊ทธ๋ ๊ทธ๋ผ ๊ทธ๋ ์ง! 10๋ง..????
์ด๋ป๊ฒ ํด์ผ ๊ฐ๋จํ๊ณ ์๊ฐ๋ ์ ๊ฒ ๊ฑธ๋ฆด๊น..............
includes ๋ฑ์ ๋ฐฐ์ด์ ์ ๋ถ ํ์ํ๊ฑฐ๋ ์ฌํ ๋น ์ํค๋ ๋ฑ์ ๋ก์ง์ ์๊ฐ์ด ๋๋ฌด ์ค๋ ๊ฑธ๋ฆฐ๋ค!
๊ฐ์๋ฅผ ์ธ์ ๋น๊ตํด๋ณด๊ธฐ๋ก ํ๋ค.
function solution(participant, completion) {
const pCount = {};
participant.map(v => pCount[v] = 0)
participant.map(v => pCount[v]++)
const cCount = {};
completion.map(v => cCount[v] = 0)
completion.map(v => cCount[v]++)
for (const name of Object.keys(pCount)) {
if (!cCount[name]) return name;
if (cCount[name] !== pCount[name]) return name;
}
}
์ค๋๋ ์ค๋ณต ์ฝ๋ ๋จ๋ฐํจ.
์ค๋์ ๋ด๋์ด๋ ๋์ด ํด์
๋ด๋ ์ฝ๋ ์ค์ ์ข์ ๋ถ๋ถ ์๋น์ง ํ๋คใ ใ ใ ใ ใ
function makeObj (arr,obj){
for(i of arr){
obj[i] = (obj[i] || 0) + 1;
}
}
ใ ใ ใ ใ ใ ใ ใ ํ๋ฝ ๋งก๊ณ ์๋น์ง
์๊ทธ๋๋ map ์ ๋๋ฒ ์ฐ๋ฉด์ ํ๋ฒ์ผ๋ก ์ด๋ป๊ฒ ์ค์ผ ์ ์๋ ๊ถ๊ธํ๋๋ฐ,
์์ด ์์ํ๋ค!
function solution(participant, completion) {
const count = (arr) => {
const count = {};
arr.map(v => {
count[v] = (count[v] || 0) + 1;
})
return count;
}
for (const name of Object.keys(count(participant))) {
if (!count(completion)[name]) return name;
if (count(completion) !== count(participant)[name]) return name;
}
}
๊ต์ฅํ ๊น๋ํด์ง ์ฝ๋!
์ค๋ ์๊ฐ ๋ด์ ํ์ด์ ๊ธฐ๋ถ ์ข๊ฒ ๋!
![](https://t1.daumcdn.net/keditor/emoticon/friends1/large/008.gif)
728x90
๋ฐ์ํ