![JAR search and dependency download from the Maven repository](/logo.png)
g0301_0400.s0349_intersection_of_two_arrays.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 g0301_0400.s0349_intersection_of_two_arrays
// #Easy #Array #Hash_Table #Sorting #Binary_Search #Two_Pointers
// #2022_11_18_Time_346_ms_(66.99%)_Space_38.3_MB_(72.82%)
class Solution {
fun intersection(nums1: IntArray, nums2: IntArray): IntArray {
val occ = BooleanArray(1001)
for (k in nums1) {
occ[k] = true
}
val res: MutableList = ArrayList()
for (j in nums2) {
if (occ[j]) {
occ[j] = false
res.add(j)
}
}
val result = IntArray(res.size)
for (i in res.indices) {
result[i] = res[i]
}
return result
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy