![JAR search and dependency download from the Maven repository](/logo.png)
g2201_2300.s2295_replace_elements_in_an_array.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
package g2201_2300.s2295_replace_elements_in_an_array
// #Medium #Array #Hash_Table #Simulation #2023_06_28_Time_913_ms_(100.00%)_Space_101.1_MB_(100.00%)
class Solution {
fun arrayChange(nums: IntArray, operations: Array): IntArray {
val map = HashMap()
for (i in nums.indices) {
map[nums[i]] = i
}
for (operation in operations) {
val index = map[operation[0]]!!
nums[index] = operation[1]
map[operation[1]] = index
}
return nums
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy