Skip to content

Feat:Add solution of #193 #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Feat:Add solution of #193 #201

wants to merge 1 commit into from

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