본문 바로가기

TLI

(38)
2024.06.15 TIL 코트카타 83번 (귤고르기) fun solution(k: Int, tangerine: IntArray): Int { val sizeToCount = mutableMapOf() for (size in tangerine) { val numSize = sizeToCount[size]?:0 sizeToCount[size] = numSize+1 } val iterator = sizeToCount.values.iterator() val sizeCounts = mutableListOf() while (iterator.hasNext()) { val count = iterator.next() si..
2024.06.14 TIL 코트카타 82번(멀리뛰기) fun solution(n: Int): Long { if(n == 1) return 1 val numJumpWay = LongArray(n+1) numJumpWay[1] = 1 numJumpWay[2] = 2 for(numJumpWayIndex in 3..numJumpWay.size-1) { numJumpWay[numJumpWayIndex] = (numJumpWay[numJumpWayIndex-1] + numJumpWay[numJumpWayIndex-2]) % 1234567 } return numJumpWay[n] } 풀이 과정- 문제에서의 경우의 수를 n이 8일 때까지 손..
2024.06.13 TIL 코트카타 81번(N개의 최소공배수) fun solution(arr: IntArray): Int { var lcm = arr[0] for(arrIndex in 1..arr.size-1) { val number2 = arr[arrIndex] val biggerNumber = Math.max(lcm, number2) val smallerNumber = Math.min(lcm, number2) var operand1 = 2 var operand2 = 2 var result1 = smallerNumber var result2 = biggerNumber while (re..
2024.06.11 TIL 코트카타 79번(카펫) fun solution(brown: Int, yellow: Int): IntArray { var lengthYellowRow = yellow var lengthYellowColumn = 1 while (lengthYellowRow >= lengthYellowColumn) { val divideToDouble = yellow / lengthYellowColumn.toDouble() if(divideToDouble % 1 == 0.0) { lengthYellowRow = divideToDouble.toInt() val numBrown = (lengthYellowRow * 2) +..
2024.06.10 TIL 코트카타 78번(피보나치수) fun solution(n: Int): Int { val fibonacci = IntArray(n+1) fibonacci[0] = 0 fibonacci[1] = 1 for(fibonacciIndex in 2..n) { fibonacci[fibonacciIndex] = (fibonacci[fibonacciIndex-2] + fibonacci[fibonacciIndex-1]) % 1234567 } return fibonacci[n] } 풀이 과정- 현재 값 = 이전 + 2개전- n까지 반복문
2024.06.08 TIL 코트카타 76번(JadenCase 문자열 만들기) fun solution(s: String): String { val sStringBuilder = StringBuilder(s) if(s[0].code in 97..122) sStringBuilder[0] = Character.toUpperCase(s[0]) var beforeChar = s[0] for(sIndex in 1.. s.length-1) { val currentChar = s[sIndex] if(beforeChar == ' ' && currentChar.code in 97..122) sStringBuilder[sIndex] = Character.toUpper..
2024.06.07 TIL 코트카타 75번(최댓값과 최솟값) fun solution(s: String): String { val splitS = s.split(" ") var minNumber = Int.MAX_VALUE var maxNumber = Int.MIN_VALUE for(number in splitS) { val numberToInt = number.toInt() minNumber = Integer.min(minNumber, numberToInt) maxNumber = Integer.max(maxNumber, numberToInt) } return "${minNumber} ${maxNumber}" } 풀이과정- 공백..
2024.06.06 TIL 코트카타 74번(신고 결과 받기) fun solution(id_list: Array, report: Array, k: Int): IntArray { val reporterToTarget = mutableMapOf>() for(complaint in report) { val splitComplaint = complaint.split(" ") val reporter = splitComplaint[0] val target = splitComplaint[1] val targetSet = reporterToTarget[reporter] if(targetSet == null) reporterToTar..