카카오 블라인드 채용 신입 공채 3차 코딩 테스트) 5번 문제
문제 출처 : http://tech.kakao.com/2017/11/14/kakao-blind-recruitment-round-3/
역시나 테스트케이스가 적어서 답이 맞는지 모르겠네요.
2018년 3월 8일 public class kakao_3_5 { public static void main(String[] args) { solution(new String[]{"go","gone","guild"}); solution(new String[]{"abc","def","ghi","jklm"}); solution(new String[]{"word","war","warrior","world"}); }
static void solution(String[] words) { ArrayList<String> input = new ArrayList<>(); for (int i = 0; i < words.length; i++) { input.add(words[i]); } Collections.sort(input);
int compareNum = 0, comparePreValue = -1, compareNextValue = -1; for (int i = 0; i < words.length; i++) { if ( i == words.length - 1) { compareNextValue = -1; } else { compareNextValue = compareString(input.get(i), input.get(i+1)); } compareNum += comparePreValue >= compareNextValue ? comparePreValue : compareNextValue;
comparePreValue = compareNextValue; if (isContain) { comparePreValue += 1; } } System.out.println(compareNum + "\n"); }
static boolean isContain = false; static int compareString(String string1, String string2) { if (string2.contains(string1)) { isContain = true; return string1.length(); } else { isContain = false; int i = 0; for (; ; i++) { char temp1 = string1.charAt(i); char temp2 = string2.charAt(i); if (temp1 != temp2) { break; } } return i + 1; } } } |