From 9ffe7643672465aaebdc0f2bff1cd1d6225b2e41 Mon Sep 17 00:00:00 2001 From: isaiahliu Date: Fri, 27 Dec 2024 00:15:15 +0800 Subject: [PATCH] 1 --- src/main/kotlin/p31xx/Problem3159.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/kotlin/p31xx/Problem3159.kt diff --git a/src/main/kotlin/p31xx/Problem3159.kt b/src/main/kotlin/p31xx/Problem3159.kt new file mode 100644 index 00000000..ae53b1d7 --- /dev/null +++ b/src/main/kotlin/p31xx/Problem3159.kt @@ -0,0 +1,19 @@ +package p31xx + +import util.expect + +fun main() { + class Solution { + fun occurrencesOfElement(nums: IntArray, queries: IntArray, x: Int): IntArray { + return nums.indices.filter { nums[it] == x }.let { indices -> + queries.map { indices.getOrNull(it - 1) ?: -1 } + }.toIntArray() + } + } + + expect { + Solution().occurrencesOfElement( + intArrayOf(), intArrayOf(), 1 + ) + } +}