반응형

개선할점

- 반복문 쓸 때 길이조건 변수 헷갈리지 말고 제대로 좀 넣어야한다.

- char 타입데이터에 int 더하면 int 나오니까 (char) 형변환 

class Solution {
    public String solution(String s, String skip, int index) {
        StringBuilder result = new StringBuilder();
        for(int i=0;i<s.length();i++){
           result.append(getAlphabet(s.charAt(i),skip,index));
        }
        return result.toString();
    }
    
    //index만큼 뒤에 있는 알파벳 찾기. skip에 있는거 빼고.
    public String getAlphabet(char c, String skip, int index){ 
        int count = 0 ;
        char standardChar = c; //standardChar = 'x' , count 4 
        while(true){
            char nextChar = standardChar == 'z' ?  'a' : (char)(standardChar + 1);//y
            standardChar = nextChar; //y
            //skip에 없으면
            if(skip.indexOf(Character.toString(nextChar)) == -1){
                count += 1;
            }
            
            if(count == index){
                break;
            }
        }
        
        return Character.toString(standardChar);
    }
}



//charAt(i) 문자 +1반복.. count index만큼 채울때까지..
//기준문자는 계속 바꾼다 
//문자가 z라면.. a로바꾸고..
반응형

+ Recent posts