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 分钟前
iframe的属性获取
开发语言·javascript·ecmascript
一个处女座的程序猿O(∩_∩)O14 分钟前
Python基础知识大全:从零开始掌握Python核心语法
开发语言·python
小陈工18 分钟前
Python Web开发入门(十一):RESTful API设计原则与最佳实践——让你的API既优雅又好用
开发语言·前端·人工智能·后端·python·安全·restful
计算机安禾30 分钟前
【数据结构与算法】第28篇:平衡二叉树(AVL树)
开发语言·数据结构·数据库·线性代数·算法·矩阵·visual studio
deephub44 分钟前
ADK 多智能体编排:SequentialAgent、ParallelAgent 与 LoopAgent 解析
人工智能·python·大语言模型·agent
csbysj20201 小时前
网站主机技术概述
开发语言
FL16238631291 小时前
基于yolov26+pyqt5的混凝土墙面缺陷检测系统python源码+pytorch模型+评估指标曲线+精美GUI界面
python·qt·yolo
froginwe111 小时前
jQuery 事件方法详解
开发语言
cxr8281 小时前
GPU 加速声场求解器 CUDA Kernel 实现细节 —— 高频超声传播仿真并行计算引擎
人工智能·python·目标跟踪
echome8882 小时前
JavaScript Promise 与 async/await 实战:5 个高频异步编程场景的优雅解决方案
开发语言·javascript·ecmascript