From ab7ac03e8ef167215d4b97b71b0a13e952341bde Mon Sep 17 00:00:00 2001 From: Ali Date: Sun, 10 Mar 2024 13:08:03 +0100 Subject: [PATCH] Create 0349-intersection-of-two-arrays.kt --- kotlin/0349-intersection-of-two-arrays.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 kotlin/0349-intersection-of-two-arrays.kt diff --git a/kotlin/0349-intersection-of-two-arrays.kt b/kotlin/0349-intersection-of-two-arrays.kt new file mode 100644 index 000000000..37a7d47b4 --- /dev/null +++ b/kotlin/0349-intersection-of-two-arrays.kt @@ -0,0 +1,13 @@ +class Solution { + fun intersection(nums1: IntArray, nums2: IntArray): IntArray { + val seen = nums1.toSet() + + val res = mutableSetOf () + for (n in nums2) { + if (n in seen) + res.add(n) + } + + return res.toIntArray() + } +}