Skip to content

Commit f0bf980

Browse files
authored
Update probability-of-a-two-boxes-having-the-same-number-of-distinct-balls.py
1 parent d2ee543 commit f0bf980

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Python/probability-of-a-two-boxes-having-the-same-number-of-distinct-balls.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ def getProbability(self, balls):
1010
:type balls: List[int]
1111
:rtype: float
1212
"""
13-
def nCrs(n): # Time: O(n), Space: O(n)
14-
cs = []
13+
def nCrs(n): # Time: O(n), Space: O(1)
1514
c = 1
16-
cs.append(c)
15+
yield c
1716
for k in xrange(1, n+1):
1817
c *= n-k+1
1918
c //= k
20-
cs.append(c)
21-
return cs
19+
yield c
2220

2321
def nCr(n, r): # Time: O(n), Space: O(1)
2422
if n-r < r:

0 commit comments

Comments
 (0)