MapleStory Finger Point Cute Line Smiley Blinking Hello Kitty Angel MapleStory Finger Point

๐Ÿƒ‍โ™€๏ธprogrammers/Java

หšโ‚Šโœฉโ€งโ‚Š ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค java - ์™ธ๊ณ„์–ด ์‚ฌ์ „ หšโ‚Šโœฉโ€งโ‚Š

HYEJU01 2024. 5. 31. 16:05
์ฒด๊ฐ Level : โ˜… โ˜… โ˜… 
Review: ์ •๊ทœํ‘œํ˜„์‹์œผ๋กœ ์ž‘์„ฑํ•˜๋ฉด ์ •๋ง ์‰ฌ์šด ์ฝ”๋“œ๊ณ , ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ํ•œ๋‹ค๋ฉด ๋‚œ์ด๋„๊ฐ€ ์žˆ๋‹ค ใ… ใ… 

 

๐Ÿ’ก๋ฐฐ์—ด spell๊ณผ ์™ธ๊ณ„์–ด ์‚ฌ์ „ dic์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. spell์— ๋‹ด๊ธด ์•ŒํŒŒ๋ฒณ์„ ํ•œ๋ฒˆ์”ฉ๋งŒ ๋ชจ๋‘ ์‚ฌ์šฉํ•œ ๋‹จ์–ด๊ฐ€ dic์— ์กด์žฌํ•œ๋‹ค๋ฉด 1, ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด 2๋ฅผ return

 

 

 

1.  dic ๋ฐฐ์—ด์„ ๋Œ๋ฉด์„œ

2.  dic[i] ์— spell ์˜ ๋ฌธ์ž์—ด์ด ํฌํ•จ๋˜์–ด์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  cnt ํ•œ๋‹ค.

3. dic [i] ์˜ cnt ๊ฐ€ 3๊ฐœ๋ณด๋‹ค ํฌ๋ฉด (spell ์˜ ๋ฌธ์ž๋“ค์ด ์ „๋ถ€ ๋“ค์–ด์žˆ๋‹ค๋ฉด) cnt 2๋ฅผ ์ฆ๊ฐ€์‹œ์ผœ์ค€๋‹ค (์ด๊ฒŒ ์ตœ์ข… ๊ฒฐ๊ณผ๊ฐ’)

4. ์ดํ›„ cnt2 ๊ฐ€ 1์ด๋ฉด dic ์— ํ•˜๋‚˜๋งŒ ์กด์žฌํ•˜๋ฏ€๋กœ 1 , cnt2 ๊ฐ€ 1์ด ์•„๋‹ˆ๋ผ๋ฉด ์—†๊ฑฐ๋‚˜, 2๊ฐœ ์ด์ƒ ์กด์žฌํ•˜๋Š” ๊ฒƒ์ด๋ฏ€๋กœ 2 ์ถœ๋ ฅ

 

 

 

[์„ฑ๊ณต]
๋ฉ์ฒญํ•œ ์‹ค์ˆ˜๋ฅผ ํ•˜๋‹ค ใ…œใ…œ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์—์„  ์ „๋ถ€ ํ†ต๊ณผํ•˜๊ณ  ์˜ค๋ฅ˜๋„ ์•ˆ๋‚˜์„œ ๋ญ์ง€ ์‹ถ์—ˆ๋Š”๋ฐ

์ฒซ๋ฒˆ์งธ for ๋ฌธ ๋ฒ”์œ„๋ฅผ ์ž˜๋ชป์žก์•˜์—ˆ๋‹ค... ๊ทธ๊ฑฐ ์ œ์™ธํ•˜๋ฉด ๋‹ค ๋งž์•˜๋‹ค๋Š” !

 

๋ฐ˜๋ก€ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค ) ์ด๊ฑฐ ๋‘๊ฐœ ์ถ”๊ฐ€ํ•ด์„œ ํ’€์–ด๋ณด์‹œ๋ฉด ์›ฌ๋งŒํ•œ ๊ฑด ๋‹ค ๋  ๋“ฏ ํ•ฉ๋‹ˆ๋‹ค *-*

class Solution {
    public int solution(String[] spell, String[] dic) {
        int answer = 0;
        int cnt = 0;
        int cnt2 = 0;
        
        for(int i =0; i < dic.length; i++){
            cnt = 0;
            for (String s : spell){     
                if(dic[i].contains(s)){
                    cnt++;
                }        
            }
             if (cnt >= spell.length){
                cnt2++;
            }
           
        }
        return cnt2 == 1 ? 1 : 2;
    }
}

 

 

 

 

 

 

[์‹คํŒจ]

class Solution {
    public int solution(String[] spell, String[] dic) {
        int answer = 0;
        int cnt = 0;
        int cnt2 = 0;
        
        for(int i =0; i < spell.length; i++){
            cnt = 0;
            for (String s : spell){     
                if(dic[i].contains(s)){
                    cnt++;
                }        
            }
            if (cnt >= spell.length){
                cnt2++;
            }
        }
        return cnt2 == 1 ? 1 : 2;
    }
}