Deep_Dev
article thumbnail

https://school.programmers.co.kr/learn/courses/30/lessons/155652

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 


skip์— ํ•ด๋‹นํ•˜๋Š” ๋ฌธ์ž๊ฐ€ ์žˆ๊ณ , z๊ฐ€ ๋„˜์–ด๊ฐ€๋ฉด a๋กœ ๋Œ์•„์˜ค๋Š”๊ฒƒ๋งŒ ์‹ ๊ฒฝ์“ฐ๋ฉด ๋œ๋‹ค.

 

 

class Solution {
    public String solution(String s, String skip, int index) {
        String answer = "";

        char[] ch = s.toCharArray();
        for(int i=0; i<ch.length; i++) {
            for (int j = 0; j < index; j++) {
                ch[i]++;
                if (ch[i] > 'z') {
                    ch[i] -= 26;
                }
                while (skip.contains(String.valueOf(ch[i]))) {
                    ch[i]++;
                    if (ch[i] > 'z') {
                        ch[i] -= 26;
                    }
                }
            }
        }
        answer = String.valueOf(ch);
        return answer;
    }
}