Skip to content

Conversation

wonsyn
Copy link
Collaborator

@wonsyn wonsyn commented May 17, 2022

#193 문제풀이

2022-05-18
@wonsyn

관련 이슈

코드

  • 코드
class Solution {
    
    public int solution(String s) {
        int answer = s.length();
        
        for(int i = 1; i <= s.length() / 2; i++) {
            String temp = s.substring(0, i);
            int count = 1;
            String stack = "";
            String remain = "";
            
            for(int j = i; j < s.length(); j += i) {
            	if(i + j > s.length()) {
            		remain = s.substring(j);
            		break;
            	}
            	
            	if(temp.equals(s.subSequence(j, j + i))) {
            		count++;
            	} else {
            		if(count == 1) stack += temp;
            		else stack += count + temp;
            		temp = s.substring(j, j + i);
            		count = 1;
            	}
            }
            
            if(count == 1) stack += temp + remain;
            else stack += count + temp + remain;
            
            answer = Math.min(answer, stack.length());
        }
        
        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