2610.转换二维数组

2610. 转换二维数组

方法一

python 复制代码
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
相关推荐
安妮的小熊呢7 小时前
CRMEB开源商城系统 & 标准版系统(PHP)开发规范
开发语言·javascript·php
子榆.7 小时前
CANN ATC编译器:模型从Python到达芬奇指令走了多远
开发语言·python·neo4j
lookaroundd7 小时前
llm-compressor 普通量化调用链分析
python·算法
Loo国昌7 小时前
从 Agent 编排到 Skill Runtime:企业 AI 工程化的下一层抽象
大数据·人工智能·后端·python·自然语言处理
Dontla8 小时前
Multi-Agent多智能体项目如何从MVP过渡到生产项目?
开发语言
编码者卢布8 小时前
【Azure Service Bus】Azure Service Bus Java SDK 中 Token 刷新异常的排查思路
java·python·azure
兰令水8 小时前
topcode【随机算法题】【2026.5.20打卡-java版本】
java·开发语言·算法
liuyunshengsir8 小时前
PyTorch 最小模型转 ONNX 完整样例
人工智能·pytorch·python
我还记得那天8 小时前
C语言递归实现汉诺塔问题
c语言·开发语言
不吃土豆的马铃薯8 小时前
Spdlog 入门:日志记录器与日志槽基础详解
服务器·开发语言·c++·c·日志·spdlog