본문 바로가기

Kotlin147

[LeetCode][Kotlin] 1963. Minimum Number of Swaps to Make the String Balanced 1963. Minimum Number of Swaps to Make the String BalancedYou are given a 0-indexed string s of even length n. The string consists of exactly n / 2 opening brackets '[' and n / 2 closing brackets ']'.A string is called balanced if and only if:It is the empty string, orIt can be written as AB, where both A and B are balanced strings, orIt can be written as [C], where C is a balanced string.You may.. 2024. 8. 28.
[LeetCode][Kotlin] 1930. Unique Length-3 Palindromic Subsequences 1930. Unique Length-3 Palindromic SubsequencesGiven a string s, return the number of unique palindromes of length three that are a subsequence of s. Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once. A palindrome is a string that reads the same forwards and backwards. A subsequence of a string is a new string generated from the original strin.. 2024. 8. 28.
[Kotlin][String] substring startIndex 에서 시작하여 endIndex 바로 앞에서 끝나는 이 문자열의 하위 문자열을 반환합니다.public fun String.substring(range: IntRange): String = substring(range.start, range.endInclusive + 1)val s = "hello World"println(s.substring(1, 3)) // el substring - Kotlin Programming Language kotlinlang.org 2024. 8. 28.
[Kotlin][Collection] dropWhile / dropLastWhile 주어진 조건을 만족하는 첫 번째 요소를 제외한 모든 요소를 ​​포함하는 목록을 반환합니다.public inline fun Iterable.dropWhile(predicate: (T) -> Boolean): List { var yielding = false val list = ArrayList() for (item in this) if (yielding) list.add(item) else if (!predicate(item)) { list.add(item) yielding = true } return list}val chars = ('a'..'z').toList()println(char.. 2024. 8. 28.
[Kotlin][Collection] takeWhile / takeLastWhile 주어진 조건자를 만족하는 첫 번째 요소를 포함하는 목록을 반환합니다.public inline fun Iterable.takeWhile(predicate: (T) -> Boolean): List { val list = ArrayList() for (item in this) { if (!predicate(item)) break list.add(item) } return list}val chars = ('a'..'z').toList()println(chars.takeWhile { it  주어진 조건자를 만족하는 마지막 요소를 포함하는 목록을 반환합니다.public inline fun List.takeLastWhile(predicate: (T.. 2024. 8. 28.
[LeetCode][Kotlin] 347. Top K Frequent Elements 347. Top K Frequent ElementsGiven an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.정수 배열 nums와 정수 k가 주어지면 가장 자주 사용되는 k개의 요소를 반환합니다. 어떤 순서로든 답변을 반환할 수 있습니다. Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2] Example 2:Input: nums = [1], k = 1Output: [1] Constraints:1 -10^4 k is in the range [1, the number of unique elements.. 2024. 8. 27.
[Kotlin][String] replaceRange 주어진 범위의 부분이 대체 문자 시퀀스로 대체되는 이 문자 시퀀스의 내용이 포함된 문자 시퀀스를 반환합니다.public fun CharSequence.replaceRange(startIndex: Int, endIndex: Int, replacement: CharSequence): CharSequence { if (endIndex  replaceRange - Kotlin Programming Language kotlinlang.org 2024. 8. 27.