👍Runtime 851 ms Beats 100.00% of users with Scala
Code\n\nimport scala.collection.mutable.HashSet\n\nobject Solution {\n    def maximumSetSize(nums1: Array[Int], nums2: Array[Int]): Int = {\n        val set1 = 
# Code\n```\nimport scala.collection.mutable.HashSet\n\nobject Solution {\n    def maximumSetSize(nums1: Array[Int], nums2: Array[Int]): Int = {\n        val set1 = HashSet[Int]()\n        val set2 = HashSet[Int]()\n        val set3 = HashSet[Int]()\n        \n        nums1.foreach(x => {\n            set1.add(x)\n            set3.add(x)\n        })\n        \n        nums2.foreach(x => {\n            set2.add(x)\n            set3.add(x)\n        })\n        \n        val common = set1.size + set2.size - set3.size\n        val n1 = set1.size\n        val n2 = set2.size\n        \n        var ans = math.min(nums1.length / 2, n1 - common)\n        ans += math.min(nums1.length / 2, n2 - common)\n        ans += common\n        ans = math.min(nums1.length, ans)\n        \n        ans\n    }\n}\n```
['Scala']