LeetCode solutions

2159. Two Out of Three

My accepted Python solution to LeetCode problem 2159, Two Out of Three, running in 4ms.

  • Difficulty: Easy
  • Python
  • Runtime 4ms
  • Memory 17.7MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 4ms, memory 17.7MB, accepted 2025-12-31.

python
class Solution:
    def twoOutOfThree(self, nums1: List[int], nums2: List[int], nums3: List[int]) -> List[int]:
        s1, s2, s3 = set(nums1), set(nums2), set(nums3)
        return list((s1 & s2) | (s1 & s3) | (s2 & s3))

Source