All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g2001_2100.s2032_two_out_of_three.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package g2001_2100.s2032_two_out_of_three

// #Easy #Array #Hash_Table #2023_06_23_Time_251_ms_(83.33%)_Space_38_MB_(100.00%)

class Solution {
    fun twoOutOfThree(nums1: IntArray, nums2: IntArray, nums3: IntArray): List {
        val ans: MutableSet = HashSet()
        val set1: MutableSet = HashSet()
        for (i in nums1) {
            set1.add(i)
        }
        val set2: MutableSet = HashSet()
        for (i in nums2) {
            set2.add(i)
        }
        val set3: MutableSet = HashSet()
        for (i in nums3) {
            set3.add(i)
        }
        for (j in nums1) {
            if (set2.contains(j) || set3.contains(j)) {
                ans.add(j)
            }
        }
        for (j in nums2) {
            if (set1.contains(j) || set3.contains(j)) {
                ans.add(j)
            }
        }
        for (j in nums3) {
            if (set1.contains(j) || set2.contains(j)) {
                ans.add(j)
            }
        }
        val result: MutableList = ArrayList()
        result.addAll(ans)
        return result
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy