码迷,mamicode.com
首页 > 其他好文 > 详细

查找表_leetcode447

时间:2019-03-17 15:44:41      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:距离   code   tco   工作   etc   return   fbo   思路   col   

# 解题思路:字典先存距离信息 20190302 找工作期间
# n2

class Solution:
def numberOfBoomerangs(self, points):
"""
:type points: List[List[int]]
:rtype: int
"""

def dis( point1, point2):
return (point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2

result = 0
for i in points:
record = {}
for j in points:
if j != i:
distance = dis(i, j)
record[distance] = record.get(distance, 0) + 1

for val in record.values():
if val >= 2:
result += (val - 1)* val
return result


查找表_leetcode447

标签:距离   code   tco   工作   etc   return   fbo   思路   col   

原文地址:https://www.cnblogs.com/lux-ace/p/10546960.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!