Notice
Recent Posts
Recent Comments
Link
ยซ   2025/05   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

eazyseon

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค (์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ) - ์™ธ๊ณ„์–ด ์‚ฌ์ „ ๋ณธ๋ฌธ

๐Ÿง์•Œ๊ณ ๋ฆฌ์ฆ˜?์•Œ๊ณ ์‹ถ์Œ!

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค (์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ) - ์™ธ๊ณ„์–ด ์‚ฌ์ „

eazyseon 2023. 3. 2. 16:35
๋ฐ˜์‘ํ˜•

- ๋ฌธ์ œ ์„ค๋ช… 

 

 

- ์ž…์ถœ๋ ฅ ์˜ˆ์‹œ

 

 

- ๋‚˜์˜ ํ’€์ด 

 

function solution(spell, dic) {
  let cnt = 0;
  let answer = []

  //dic ๋ฐ˜๋ณต๋ฌธ
  for(let i=0; i<dic.length; i++){
    cnt = 0;
    //spell์˜ ๊ธธ์ด๋งŒํผ ๋ฐ˜๋ณต๋ฌธ์„ ๋Œ๋ฉฐ
    for(let j=0; j<spell.length; j++){
  //dic[i]์•ˆ์— spell[j]์˜ ์š”์†Œ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธ
      if(dic[i].includes(spell[j])){
      //์žˆ๋‹ค๋ฉด cnt๋ฅผ ++ํ•œ๋‹ค
        cnt++;
      }
    }
    //cnt์™€ spell์˜ ๊ธธ์ด๊ฐ€ ๊ฐ™๋‹ค๋ฉด 
    if(cnt === spell.length){
      //answer์•ˆ์— ๋„ฃ๋Š”๋‹ค
      answer.push(dic[i])
    }
  }
  //answer์•ˆ์— ์•„๋ฌด๊ฒƒ๋„ ์—†๋‹ค๋ฉด(๊ธธ์ด๊ฐ€ 0์ด๋ฉด)
  //ํ•ด๋‹น๋˜๋Š” ๋‹จ์–ด๊ฐ€ ์—†๋‹ค๋Š” ๋œป์ด๋‹ˆ 2๋ฅผ ๋ฐ˜ํ™˜
  //์žˆ๋‹ค๋ฉด(๊ธธ์ด๊ฐ€ 1์ด๋ฉด) 1์„ ๋ฐ˜ํ™˜
return answer.length === 0? 2: 1;
}

 

- ๋‹ค๋ฅธ ์‚ฌ๋žŒ์˜ ํ’€์ด 

 

function solution(spell, dic) {
    return dic.filter(v=>spell.every(c=>v.includes(c))).length ? 1 : 2;
}

 

๋ฐ˜์‘ํ˜•
Comments