Skip to content

Conversation

seokchain
Copy link
Collaborator

#193 문제풀이

2022-05-18
@seokchain

관련 이슈

코드

  • 코드
class Solution {
    public int solution(String s) {
        int answer = s.length();
        
        for(int i=1; i<= s.length()/2; i++){
            int pos = 0;
            int len = s.length();
            
            for(; pos+i <= s.length();){
                String unit = s.substring(pos, pos + i);
                pos += i;
                
                int cnt = 0;
                for(; pos +i <= s.length();){
                    if(unit.equals(s.substring(pos, pos + i))) {
                        cnt ++;
                        pos += i;
                    } else { 
                        break;
                    }
                }  
                
                if(cnt >0){
                    len -= i * cnt;
                    if(cnt < 9) len += 1;
                    else if(cnt <99) len +=2;
                    else if(cnt < 999) len +=3;
                    else len += 4;
                }
            }
            answer = Math.min(answer, len);
        }
        return answer;
    }
}

참고

아래 유튜브 참고하여 풀이했습니다...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant