๐Ÿงก๋ฌธ์ œ ์„ค๋ช…

๋จธ์“ฑ์ด๋Š” ํƒœ์–ด๋‚œ ์ง€ 11๊ฐœ์›” ๋œ ์กฐ์นด๋ฅผ ๋Œ๋ณด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์กฐ์นด๋Š” ์•„์ง "aya", "ye", "woo", "ma" ๋„ค ๊ฐ€์ง€ ๋ฐœ์Œ๊ณผ ๋„ค ๊ฐ€์ง€ ๋ฐœ์Œ์„ ์กฐํ•ฉํ•ด์„œ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ๋ฐœ์Œ๋ฐ–์— ํ•˜์ง€ ๋ชปํ•˜๊ณ  ์—ฐ์†ํ•ด์„œ ๊ฐ™์€ ๋ฐœ์Œ์„ ํ•˜๋Š” ๊ฒƒ์„ ์–ด๋ ค์›Œํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด ๋ฐฐ์—ด babbling์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, ๋จธ์“ฑ์ด์˜ ์กฐ์นด๊ฐ€ ๋ฐœ์Œํ•  ์ˆ˜ ์žˆ๋Š” ๋‹จ์–ด์˜ ๊ฐœ์ˆ˜๋ฅผ returnํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”.


๐Ÿ’›์ œํ•œ์‚ฌํ•ญ

  • 1 โ‰ค babbling์˜ ๊ธธ์ด โ‰ค 100
  • 1 โ‰ค babbling[i]์˜ ๊ธธ์ด โ‰ค 30
  • ๋ฌธ์ž์—ด์€ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ’š์ž…์ถœ๋ ฅ ์˜ˆ

babblingresult
["aya", "yee", "u", "maa"]1
["ayaye", "uuu", "yeye", "yemawoo", "ayaayaa"]2

๐Ÿ’™์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช…

์ž…์ถœ๋ ฅ ์˜ˆ #1

  • ["aya", "yee", "u", "maa"]์—์„œ ๋ฐœ์Œํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์€ "aya"๋ฟ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ 1์„ returnํ•ฉ๋‹ˆ๋‹ค.

์ž…์ถœ๋ ฅ ์˜ˆ #2

  • ["ayaye", "uuuma", "yeye", "yemawoo", "ayaayaa"]์—์„œ ๋ฐœ์Œํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์€ "aya" + "ye" = "ayaye", "ye" + "ma" + "woo" = "yemawoo"๋กœ 2๊ฐœ์ž…๋‹ˆ๋‹ค. "yeye"๋Š” ๊ฐ™์€ ๋ฐœ์Œ์ด ์—ฐ์†๋˜๋ฏ€๋กœ ๋ฐœ์Œํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ 2๋ฅผ returnํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ’œ์œ ์˜์‚ฌํ•ญ

๋„ค ๊ฐ€์ง€๋ฅผ ๋ถ™์—ฌ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ๋ฐœ์Œ ์ด์™ธ์—๋Š” ์–ด๋–ค ๋ฐœ์Œ๋„ ํ•  ์ˆ˜ ์—†๋Š” ๊ฒƒ์œผ๋กœ ๊ทœ์ •ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด "woowo"๋Š” "woo"๋Š” ๋ฐœ์Œํ•  ์ˆ˜ ์žˆ์ง€๋งŒ "wo"๋ฅผ ๋ฐœ์Œํ•  ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— ํ•  ์ˆ˜ ์—†๋Š” ๋ฐœ์Œ์ž…๋‹ˆ๋‹ค.


๐ŸคŽ๋‚˜์˜ ํ’€์ด

function solution(babbling) {
    // ํ•ด๋‹น ํ’€์ด๋Š” StarBlitz๋‹˜์˜ ํ’€์ด๋ฅผ ํ•ด์„ํ•˜์˜€์Œ์„ ๋ฏธ๋ฆฌ ๋ฐํž™๋‹ˆ๋‹ค.
    let count = 0;
    // ์—ฐ์†๋˜๋Š” ๊ฒฝ์šฐ
    let dup = ['ayaaya', 'yeye', 'woowoo', 'mama'];
    while (babbling.length) {
        let b = babbling.pop();
        // ์—ฐ์†๋˜๋Š” ๋ฐœ์Œ์€ ํŒจ์Šค
        if (dup.some(v=>b.includes(v))) continue;
        // ๊ฐ€๋Šฅํ•œ ๋ฐœ์Œ์„ ๋ชจ๋‘ ์ˆซ์ž๋กœ ๋ฐ”๊พธ์–ด
        b = b.replaceAll('aya','1').replaceAll('ye','2').replaceAll('woo','3').replaceAll('ma','4');
        // ์ˆซ์ž๋Š” ๊ณต๋ฐฑ์œผ๋กœ ๋ณ€ํ™˜
        b = b.replace(/[1234]/g, '');
        // ๋ชจ๋‘ ๊ฐ€๋Šฅํ•œ ๋ฐœ์Œ์˜ ๊ฒฝ์šฐ count++
        if (b.length === 0) count++;
    }

    return count;
}
profile
๋‚ด ์ง€์‹์„ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋Š” ๋Œ€๋‹ดํ•จ

0๊ฐœ์˜ ๋Œ“๊ธ€