본문 바로가기

분류 전체보기

(39)
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..
2024.06.05 TIL 코트카타 73번(공원 산책) fun solution(park: Array, routes: Array): IntArray { val directionX = intArrayOf(0,1,0,-1) // N,E,S,W val directionY = intArrayOf(-1,0,1,0) var currentX = -1 var currentY = -1 for(parkI in park.indices) { for(parkJ in park[parkI].indices) { if(park[parkI][parkJ] == 'S') { currentX = parkJ currentY ..
2024.06.04 TIL 코트카타 72번(달리기 경주) fun solution(players: Array, callings: Array): Array { val playerToRank = mutableMapOf() val rankToPlayer = mutableMapOf() for(playersIndex in players.indices) { playerToRank[players[playersIndex]] = playersIndex rankToPlayer[playersIndex] = players[playersIndex] } for(calling in callings) { val callingPlayerRank = playerToRank[..
2024.06.03 TIL 코트카타 71번(개인정보 수집 유효기간) fun solution(today: String, terms: Array, privacies: Array): IntArray { var answer = mutableListOf() var termToExpiration = mutableMapOf() for(term in terms) { val splitedTerm = term.split(" ") termToExpiration.put(splitedTerm[0], splitedTerm[1].toInt()) } val todayToAmount = calculateDateToAmount(today) for(privacyIndex in privacie..
2024.05.31 TIL 코트카타 68번(햄버거 만들기) fun solution(ingredient: IntArray): Int { var answer = 0 val ingredientStack = Stack() val burgerSequence = mutableListOf() for(element in ingredient) { if(element == 1 && ingredientStack.size >= 3) { burgerSequence.add(1) burgerSequence.add(ingredientStack.pop()) burgerSequence.add(ingredientStack.pop()) ..
2024.05.30 TIL 코트카타 67번(둘만의 암호) fun solution(s: String, skip: String, index: Int): String { var answer = StringBuilder() var isSkipAlphabets = BooleanArray(26) for(skipAlphabet in skip) { isSkipAlphabets[skipAlphabet.code-97] = true } for(sChar in s) { var endIndex = sChar.code - 97 var numSkip = index while(numSkip > 0) { var startIn..
2024.05.29 TIL 코트카타 66번(대충만든자판) fun solution(keymap: Array, targets: Array): IntArray { var minPushs = IntArray(26) for(minPushsIndex in 0..minPushs.size-1) { minPushs[minPushsIndex] = Integer.MAX_VALUE } for (keySequence in keymap) { for(keySequenceIndex in 0..keySequence.length-1) { val currentAlphabet = keySequence[keySequenceIndex] val minPushs..
2024.05.28 TIL 코트카타 65번(문자열나누기) fun solution(s: String): Int { var answer: Int = 0 var startChar = s[0] var numStartChar = 1 var numUnStartChar = 0 for(sIndex in 1..s.length-1) { if(numStartChar == 0) { startChar = s[sIndex] numStartChar = 1 continue } if(startChar == s[sIndex]) numStartChar++ ..