본문 바로가기

전체 글114

[프로그래머스 kotlin] 롤케이크 자르기 시간 초과 발생 코드 fun solution(topping: IntArray): Int { var count=0 for(i in topping.indices){ val set1 = mutableSetOf() val set2 = mutableSetOf() for(j in 0.. i){ set1.add(topping[j]) } for(k in i+1 until topping.size){ set2.add(topping[k]) } if(set1.size==set2.size){ count++ } } println(count) .. 2024. 7. 1.
[프로그래머스, kotlin] 타겟넘버 재귀를 이용한 문제 풀이 fun solution(numbers: IntArray, target: Int): Int { var answer=0 fun dfs(index: Int, currentSum: Int) { if (index == numbers.size) { if (currentSum == target) { answer = answer + 1 } } else { val add = dfs(index + 1, currentSum + numbers[index]) val subtract = dfs(index + 1, currentSum - numbers[index]) .. 2024. 6. 28.
[TIL] 06.27 https://1chanhue1.tistory.com/57 [프로그래머스 , kotlin] 피로도연결리스트를 이용한 풀이 ( 스택과 같은 기능으로)fun solution_ff(k: Int, dungeons: Array): Int { val stack = mutableListOf(Triple(k, 0, BooleanArray(dungeons.size))) var maxCount = 0 while (stack.isNotEmpty()) { val (currentK, count, vis1chanhue1.tistory.com 2024. 6. 27.
[프로그래머스 , kotlin] 피로도 연결리스트를 이용한 풀이 ( 스택과 같은 기능으로)fun solution_ff(k: Int, dungeons: Array): Int { val stack = mutableListOf(Triple(k, 0, BooleanArray(dungeons.size))) var maxCount = 0 while (stack.isNotEmpty()) { val (currentK, count, visited) = stack.removeAt(stack.lastIndex) maxCount = maxOf(maxCount, count) for (i in dungeons.indices) { if (!visited[i] && currentK >= dungeo.. 2024. 6. 27.