본문 바로가기
반응형

2023년 이전/프로그래머스 코딩 테스트3

위장 import java.util.* class Solution { fun solution(clothes: Array): Int { var answer = 0 val category = HashMap() for (i in clothes.indices ){ if( category.get(clothes[i][1]) == null) { category.put(clothes[i][1],1) }else{ var lenght : Int = category.get(clothes[i][1]) as Int lenght++ category.put(clothes[i][1],lenght) } } if (category.size == 1 ){ return clothes.size }else{ val values = category... 2020. 8. 9.
전화번호 목록 import java.util.*; class Solution { public boolean solution(String[] phone_book) { Arrays.sort(phone_book); for(int i = 1; i < phone_book.length; i++){ if(phone_book[i].startsWith(phone_book[0])){ return false; } } return true; } } 정렬해서 제일 작은 수를 찾고 이를 비교하여 접두어에 그 숫자가 있으면 false, 없으면 true 그런데 위의 코드로 할 경우 첫번째 번호가 접두어가될 수 있는게 없는데 두번째 번호를 접두어로 가지는 번호가 있을 경우 성립하지 않습니다. (프로그래머스 채점이 쫌 이상한것 같습니다. 성립되지 않.. 2020. 8. 9.
완주하지 못한 사람 import java.util.*; class Solution { public String solution(String[] participant, String[] completion) { Arrays.sort(participant); Arrays.sort(completion); int i = 0; for( i = 0; i < completion.length ; i++){ if (!participant[i].equals(completion[i])){ return participant[i]; } } return participant[i]; } } 간단하다. 사람이름을 정렬해서 비교한 다음에 없는 사람이면 반환하면 된다. 2020. 8. 9.
반응형