Skip to content

Commit

Permalink
[multiset] Fix isdisjoint function
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometheus3375 committed Jul 20, 2024
1 parent 22bf930 commit b636ce4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions solve/multiset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from collections import Counter
from collections.abc import Iterable, Iterator, Set
from itertools import product
from typing import Any, Self


Expand Down Expand Up @@ -101,8 +100,16 @@ def isdisjoint(self, other: Set, /) -> bool:
"""
Returns ``True`` if this set and other have no common elements.
"""
for _ in product(self, other):
return False
if len(self) < len(other):
shorter = self
longer = other
else:
shorter = other
longer = self

for e in shorter:
if e in longer:
return False

return True

Expand Down

0 comments on commit b636ce4

Please sign in to comment.