코딩테스트 준비(kotlin)61 [kotlin] 제일 작은 수 제거하기 fun solution(arr: IntArray): IntArray { var answer = intArrayOf() answer=arr.filter { it!=arr.minOrNull() }.toIntArray() // 최소값과 다르면 filter후 int배열로 형 변환 후 answer에 담기 if(answer.count()==0){ // 리턴하려는 배열이 빈 배열인 경우 answer=answer+(-1) // 배열에 -1을 담아서 리턴 } return answer //최신버전에선 min() 안됨 } 2024. 4. 22. kotlin - filter filter 함수는 컬렉션을 iteration 하면서 주어진 람다에 각 원소를 넘겨서 람다가 true를 반환하는(조건에 맞는) 원소만 필터링하는 기능을 합니다. filter의 결과는, 입력 컬렉션의 원소 중에서 주어진 조건문에 만족하는 원소만으로 이루어진 새로운 컬렉션 입니다. inline fun Array.filter( predicate: (T) -> Boolean ): List inline fun Array.filterIndexed( predicate: (index: Int, T) -> Boolean ): List inline fun Array.filterIndexedTo( destination: C, predicate: (index: Int, T) -> Boolean ): C fun Array.fi.. 2024. 4. 22. (kotlin) 나누어 떨어지는 숫자 배열 package com.example.codingtest_practice1.programmers.basicproblems fun solution(arr: IntArray, divisor: Int): IntArray { var answer = intArrayOf() var mutableList = mutableListOf() var arrindex = 0 while (arr.size > arrindex) { if (arr[arrindex] % divisor == 0) { mutableList.add(arr[arrindex]) } arrindex++ } if (mutableList.isEmpty()) { mutableList.add(-1) } mutableList.sort() answer = mutableLi.. 2024. 4. 18. [kotlin] 백준 1280 DFS와 BFS package com.example.codingtestimport java.io.BufferedReaderimport java.io.InputStreamReaderimport java.util.LinkedListimport java.util.Queueimport java.util.Stackfun main() { val br = BufferedReader(InputStreamReader(System.`in`)) val (n, m,v) = readLine()!!.split(" ").map { it.toInt() } val graph = Array(1001, { IntArray(10001, { 0 }) }) // Array(크기, {IntArray(크기, {초기화 값})} val v.. 2023. 10. 27. 이전 1 ··· 11 12 13 14 15 16 다음