Skip to content

Feat:Add solution of #193 #199

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 2 commits into
base: main
Choose a base branch
from
Open

Feat:Add solution of #193 #199

wants to merge 2 commits into from

Conversation

sa11k
Copy link
Member

@sa11k sa11k commented May 17, 2022

#193 문제풀이

2022-05-17
@sa11k

관련 이슈

코드

  • 구글링한 정답 코드
class Solution {
	static int answer = 0;
	public int solution(String s) {
		int len = s.length();
		answer = len;

		for(int i = 1; i<=len; i++){
			cut(i, s);
		}

		return answer;
	}

	static void cut(int len, String s){
		String compareA = "";
		String compareB = "";
		String makeS = "";
		int idx = 0;
		int same = 1;
		for(int j = 0; j<len; j++){
			compareA += s.charAt(idx++);
		}
		if(s.length()/len>=2){
			while(idx<=s.length()-len){
				compareB = "";
				for(int j = 0; j<len; j++){
					compareB += s.charAt(idx++);
				}
				// System.out.println(compareB);
				if(compareA.equals(compareB)){
					if(idx<s.length()){
						same++;
					}else{
						same++;
						// if(same>10) same %= same;
						makeS += same+"";
					}
				}else{
					if(same!=1){
						// if(same>10) same %= same;
						makeS += same + compareA;
						same = 1;
						compareA = "";
					}else if(same == 1){
						makeS += compareA;
						compareA = "";
					}
					compareA = compareB;
				}
			}

			makeS += compareB;

			for(int i = idx; i<s.length(); i++){
				makeS += s.charAt(i);
			}
		}

		else{
			makeS = s;
		}

		// System.out.println(len + " : " +makeS);

		if(makeS.length()<answer) answer = makeS.length();

	}
}
  • 직접 푼 틀린 코드
class Solution_오답 {
	static int answer = 0;
	public int solution(String s) {
		int len = s.length();
		answer = len;

		for(int i = 1; i<=len; i++){
			cut(i, s);
		}

		return answer;
	}

	static void cut(int len, String s){
		String compareA = "";
		String compareB = "";
		String makeS = "";
		int idx = 0;
		int same = 1;
		for(int j = 0; j<len; j++){
			compareA += s.charAt(idx++);
		}
		if(s.length()/len>=2){
			while(idx<=s.length()-len){
				compareB = "";
				for(int j = 0; j<len; j++){
					compareB += s.charAt(idx++);
				}
				// System.out.println(compareB);
				if(compareA.equals(compareB)){
					if(idx<s.length()){
						same++;
					}else{
						same++;
						// if(same>10) same %= same;
						makeS += same+"";
					}
				}else{
					if(same!=1){
						// if(same>10) same %= same;
						makeS += same + compareA;
						same = 1;
						compareA = "";
					}else if(same == 1){
						makeS += compareA;
						compareA = "";
					}
					compareA = compareB;
				}
			}

			makeS += compareB;

			for(int i = idx; i<s.length(); i++){
				makeS += s.charAt(i);
			}
		}

		else{
			makeS = s;
		}

		// System.out.println(len + " : " +makeS);

		if(makeS.length()<answer) answer = makeS.length();

	}
}

-테케는 맞는데 제출하면 틀려서 구글링했습니다 ㅜㅡㅜ

  • 두 코드 다 업로드 합니다.

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