Kotlin147 [Kotlin][String] trim / trimStart / trimEnd 술어와 일치하는 선행 및 후행 문자가 제거된 이 문자 시퀀스의 하위 시퀀스를 반환합니다.public inline fun CharSequence.trim(predicate: (Char) -> Boolean): CharSequence { var startIndex = 0 var endIndex = length - 1 var startFound = false while (startIndex 술어와 일치하는 선행 문자가 제거된 문자열을 반환합니다.public inline fun CharSequence.trimStart(predicate: (Char) -> Boolean): CharSequence { for (index in this.indices) if (!predica.. 2024. 8. 30. [Kotlin][Collection] toTypedArray 이 컬렉션의 모든 요소를 포함하는 형식화된 배열을 반환합니다. 이 컬렉션의 크기와 동일한 크기를 갖는 런타임 유형 T 의 배열을 할당하고 이 컬렉션의 요소로 배열을 채웁니다.public actual inline fun Collection.toTypedArray(): Array { val thisCollection = this as java.util.Collection return thisCollection.toArray(arrayOfNulls(0)) as Array}val collection = listOf(1, 2, 3)val array = collection.toTypedArray()println(array.contentToString()) // [1, 2, 3] toTypedArra.. 2024. 8. 30. [LeetCode][Kotlin] 28. Find the Index of the First Occurrence in a String 28. Find the Index of the First Occurrence in a StringGiven two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.needle과 haystack이라는 두 문자열이 주어지면 haystack에서 needle이 처음 나타나는 인덱스를 반환하거나, needle이 haystack의 일부가 아닌 경우 -1을 반환합니다. Example 1:Input: haystack = "sadbutsad", needle = "sad"Output: 0Explanation: "sad" occurs a.. 2024. 8. 29. [Kotlin][Collection] joinToString 구분 기호를 사용하고 제공된 접두사와 접미사를 사용하여 구분된 모든 요소에서 문자열을 만듭니다. 컬렉션이 클 수 있는 경우 음수가 아닌 값을 지정할 수 있습니다. 이 경우 첫 번째 제한 요소만 추가되고 그 뒤에는 잘린 문자열(기본값은 "...")이 추가됩니다.public fun Iterable.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: ((T) -> CharSequence)? = null): String { return joinTo(StringBuilder.. 2024. 8. 29. [Kotlin][Iterable] chunked 이 컬렉션을 각각 주어진 크기를 초과하지 않는 목록의 목록으로 분할합니다. 결과 목록의 마지막 목록에는 지정된 크기보다 적은 수의 요소가 있을 수 있습니다.public fun Iterable.chunked(size: Int): List> { return windowed(size, size, partialWindows = true)}public fun CharSequence.windowed(size: Int, step: Int = 1, partialWindows: Boolean = false, transform: (CharSequence) -> R): List { checkWindowSizeStep(size, step) val thisSize = this.length val res.. 2024. 8. 29. [Kotlin][String] startsWith / endsWith 이 문자 시퀀스가 지정된 접두사로 시작하면 true 를 반환합니다.public fun CharSequence.startsWith(prefix: CharSequence, ignoreCase: Boolean = false): Boolean { if (!ignoreCase && this is String && prefix is String) return this.startsWith(prefix) else return regionMatchesImpl(0, prefix, 0, prefix.length, ignoreCase)}print("HelloWorld".startsWith("Hello")) // trueprint("HelloWorld".startsWith("World").. 2024. 8. 29. [LeetCode][Kotlin] 2002. Maximum Product of the Length of Two Palindromic Subsequences 2002. Maximum Product of the Length of Two Palindromic SubsequencesGiven a string s, find two disjoint palindromic subsequences of s such that the product of their lengths is maximized. The two subsequences are disjoint if they do not both pick a character at the same index. Return the maximum possible product of the lengths of the two palindromic subsequences. A subsequence is a string that can.. 2024. 8. 28. 이전 1 ··· 9 10 11 12 13 14 15 ··· 21 다음