blob: 585549058f03cbb2e60ae9e5262a5348464e60df (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#!/usr/bin/env python
import typing
class Solution:
def findMatrix(self, nums: typing.List[int]) -> typing.List[typing.List[int]]:
dicts = {}
for num in nums:
if num in dicts:
dicts[num] += 1
else:
dicts[num] = 1
row = 0
results = []
for i in range(max(dicts.values())):
results.append([])
while max(dicts.values()) > 0:
for k, v in dicts.items():
if v >= 1:
results[row].append(k)
dicts[k] -= 1
row += 1
return results
def main():
s = Solution()
print(s.findMatrix([1, 3, 4, 1, 2, 3, 1]))
print(s.findMatrix([1, 2, 3, 4]))
if __name__ == "__main__":
main()
|