Skip to content

Commit cccf59e

Browse files
authored
Create maximum-number-of-balls-in-a-box.py
1 parent d537a9d commit cccf59e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(nlogm)
2+
# Space: O(logm)
3+
4+
import collections
5+
import itertools
6+
7+
8+
class Solution(object):
9+
def countBalls(self, lowLimit, highLimit):
10+
"""
11+
:type lowLimit: int
12+
:type highLimit: int
13+
:rtype: int
14+
"""
15+
count = collections.Counter()
16+
for i in xrange(lowLimit, highLimit+1):
17+
count[sum(itertools.imap(int, str(i)))] += 1
18+
return max(count.itervalues())

0 commit comments

Comments
 (0)