aboutsummaryrefslogtreecommitdiff
path: root/divide_array_equal_pair.py
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-03-16 23:10:20 -0600
committerJack Sangdahl <[email protected]>2025-03-16 23:10:20 -0600
commit5b627305f75df05f28670508f2e7b30f094000d0 (patch)
tree58cc8c12722bd807188706e16ce764dde8ff7b0d /divide_array_equal_pair.py
parent27d29594b7a1211d863f38133148842a3285d9e0 (diff)
downloadleetcode-5b627305f75df05f28670508f2e7b30f094000d0.tar.gz
leetcode-5b627305f75df05f28670508f2e7b30f094000d0.zip
2206. divide array into equal pairs
Diffstat (limited to 'divide_array_equal_pair.py')
-rw-r--r--divide_array_equal_pair.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/divide_array_equal_pair.py b/divide_array_equal_pair.py
new file mode 100644
index 0000000..7555627
--- /dev/null
+++ b/divide_array_equal_pair.py
@@ -0,0 +1,26 @@
+# 2206. Divide Array Into Equal Pairs
+
+"""
+you are given an integer array 'nums' consisting of '2 n' integers. you
+need to divide 'nums' into 'n' pairs such that: each element belongs to
+exactly one pair, and the elements present in a pair are equal. return true
+if 'nums' can be divided into 'n' pairs, otherwise return false.
+"""
+
+
+class Solution(object):
+ def divideArray(self, nums):
+ """
+ :type nums: List[int]
+ :rtype: bool
+ """
+ vis = set()
+ for i in nums:
+ vis ^= {i}
+ return not vis
+
+
+if __name__ == "__main__":
+ obj = Solution()
+ print(obj.divideArray(nums=[3, 2, 3, 2, 2, 2]))
+ print(obj.divideArray(nums=[1, 2, 3, 4]))