这篇文章是程序自动发表的,详情可以见
这里
href="http://ounix1xcw.bkt.clouddn.com/github.markdown.css" rel="stylesheet">
href="http://ounix1xcw.bkt.clouddn.com/github.markdown.css" rel="stylesheet">
这是leetcode的第454题--4Sum II
题目 我想的使用counter再sort后,用4个for, 再加一点判断,可是本质上还是O(N4),对于随机数来说,都是很差的算法。下面的代码是别人写的O(N2),就两行,啊,我好菜呀T_T 思路
show me the code
def fourSumCount(self, A, B, C, D): AB = collections.Counter(a b for a in A for b in B) return sum(AB[-c-d] for c in C for d in D)