코딩테스트 준비(kotlin)/정렬2 [프로그래머스, 코틀린] H-Index class Solution { fun solution(citations: IntArray): Int { // 인용 횟수를 내림차순으로 정렬 val sortedCitations = citations.sortedDescending() // H-Index를 찾기 위한 변수 var hIndex = 0 // 정렬된 배열을 순회하면서 조건에 맞는 최대 h를 찾음 for (i in sortedCitations.indices) { if (sortedCitations[i] >= i + 1) { hIndex = i + 1 } else { break .. 2025. 1. 10. [프로그래머스] 가장 큰 수 (with kotlin) class Solution { fun solution(numbers: IntArray): String { // 숫자 배열을 문자열로 변환하여 리스트에 저장 var number = mutableListOf() // IntArray의 각 요소를 문자열로 변환하여 리스트에 추가 for (i in 0 until numbers.size) { number.add(numbers[i].toString()) } // 커스텀 정렬: 두 숫자를 이어 붙였을 때 더 큰 결과를 기준으로 정렬 number.sortWith(Comparator { a, b -> (b + a).compareTo(a + .. 2025. 1. 10. 이전 1 다음