博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode题解(1128):等价多米诺骨牌对的数量(Python)
阅读量:1900 次
发布时间:2019-04-26

本文共 436 字,大约阅读时间需要 1 分钟。

题目:(简单)

解法 时间复杂度 空间复杂度 执行用时
Ans 1 (Python) O ( N ) O(N) O(N) O ( 1 ) O(1) O(1) 276ms (95.19%)
Ans 2 (Python)
Ans 3 (Python)

LeetCode的Python执行用时随缘,只要时间复杂度没有明显差异,执行用时一般都在同一个量级,仅作参考意义。

解法一:

def numEquivDominoPairs(self, dominoes: List[List[int]]) -> int:    count = collections.Counter((d[0], d[1]) if d[0] < d[1] else (d[1], d[0]) for d in dominoes)    ans = 0    for val in count.values():        ans += val * (val - 1) / 2    return ans

转载地址:http://zqgdf.baihongyu.com/

你可能感兴趣的文章
luvcview摄像头程序到Cortex A8的移植
查看>>
static方法和非static方法的区别(java)
查看>>
Robolectric 测试你的Android代码
查看>>
Google Voice、Voice Search 安装
查看>>
android studio 使用lint工具 - 代码检视
查看>>
在Android Studio中进行单元测试和UI测试
查看>>
qt-embedded-linux移植要点qt
查看>>
Linux设备文件简介
查看>>
java单例模式
查看>>
移植了Qt4.5
查看>>
DM3730触摸屏校验
查看>>
在子线程中new Handler报错--Can't create handler inside thread that has not called Looper.prepare()
查看>>
移植Qt4.7.3
查看>>
Qt移植对USB鼠标键盘、触摸屏的支持
查看>>
LCD驱动移植
查看>>
驱动开发小结
查看>>
Qt Creator创建纯C、c++工程
查看>>
Android单元测试之 Robolectric3.0+
查看>>
qt configure参数解释
查看>>
Git Push 避免用户名和密码方法
查看>>