2610.转换二维数组
方法一
class Solution:
def findMatrix(self, nums: List[int]) -> List[List[int]]:
# collections.Counter自动计数 :无需手动初始化字典,直接统计元素频率。
cnt = Counter(nums)
res = []
while cnt:
# temp = [cnt的key值],eg:[1,2,3]
temp = list(cnt)
res.append(temp)
for i in temp:
# 使用一次就将cnt字典中的该元素数量-1,
cnt[i] -= 1
# 当该元素数量为0时,删除元素
if cnt[i] == 0:
del cnt[i]
# 返回每次收集的cnt的key值
return res