Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of the tuple matters).

Find the number of boomerangs. You may assume that n will be at most 500 and coordinates of points are all in the range [-10000, 10000] (inclusive).

Example:

Input:
[[0,0],[1,0],[2,0]] Output:
2 Explanation:
The two boomerangs are [[1,0],[0,0],[2,0]] and [[1,0],[2,0],[0,0]]

class Solution(object):
def numberOfBoomerangs(self, points):
"""
:type points: List[List[int]]
:rtype: int
"""
ans=0
for i in points:
a={}
for j in points:
c=(i[0]-j[0])**2+(i[1]-j[1])**2
if c not in a:
a[c]=1
else:
ans+=a[c]
a[c]+=1
return ans*2

  

[LeetCode&Python] Problem 447. Number of Boomerangs的更多相关文章

  1. [LeetCode&Python] Problem 476. Number Complement

    Given a positive integer, output its complement number. The complement strategy is to flip the bits ...

  2. [LeetCode&Python] Problem 806. Number of Lines To Write String

    We are to write the letters of a given string S, from left to right into lines. Each line has maximu ...

  3. 【LeetCode】447. Number of Boomerangs 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 [LeetCode] 题目地址:https:/ ...

  4. LeetCode 447. Number of Boomerangs (回力标的数量)

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  5. [LeetCode]447 Number of Boomerangs

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  6. 34. leetcode 447. Number of Boomerangs

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  7. 447. Number of Boomerangs

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  8. 447. Number of Boomerangs 回力镖数组的数量

    [抄题]: Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple ...

  9. [LeetCode&Python] Problem 202. Happy Number

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

随机推荐

  1. python3使用requests模块完成get/post/代理/自定义header/自定义Cookie

    一.背景说明 http请求的难易对一门语言来说是很重要的而且是越来越重要,但对于python一是urllib一些写法不太符合人的思维习惯文档也相当难看,二是在python2.x和python3.x中写 ...

  2. 包--json 与 pickle 模块

    一. 包 一个含有__init__.py 文件的文件夹(将py 文件中的内容划分成不同的部分放在不同的py 文件中,在将这些py 文件放在一个文件夹中) 是模块,不做执行文件,仅做调用 m1.py 和 ...

  3. matlab 调试日志

    debug=; diary off if debug delete('log.txt'); !del log.txt diary('log.txt'); diary ON end diary OFF

  4. 学习笔记-AngularJs(三)

    学习笔记-AngularJs(二)写了个所有程序语言入门时都必须要写的Hello World,那么从现在开始做那个之前说过的互联网大佬介绍的学习例子,当然这里开始会慢慢按照之前说过的目录来搭建这个学习 ...

  5. Consecutive Subsequence CodeForces - 977F(dp)

    Consecutive Subsequence CodeForces - 977F 题目大意:输出一序列中的最大的连续数列的长度和与其对应的下标(连续是指 7 8 9这样的数列) 解题思路: 状态:把 ...

  6. 【框架】selenium运行失败后自动截图(三)

    思路: 1.写一个类继承TestListenerAdapter,覆写onTestFailure()方法 2.在onTestFailure方法里,调用selenium的TakesScreenShot的g ...

  7. 【环境】新建Maven工程步骤及报错解决方法

    新建Maven工程步骤: 1.打开eclipse,File-New-Other-Maven-Maven project 点击Finish,即可创建一个Maven工程.Maven是内置的,不需要额外下载 ...

  8. UVA 11990 `Dynamic'' Inversion CDQ分治, 归并排序, 树状数组, 尺取法, 三偏序统计 难度: 2

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  9. 高效方便的IO库: System.IO.Pipelines

    我们在编写网络程序的时候,经常会进行如下操作: 申请一个缓冲区 从数据源中读入数据至缓冲区 解析缓冲区的数据 重复第2步 表面上看来这是一个很常规而简单的操作,但实际使用过程中往往存在如下痛点: 数据 ...

  10. JSP页面间的传值方法总结

    JSP 页面间传递参数是项目中经常需要的,这应该算是 web 基本功吧.试着将各种方式总结下来,需要时可以进行权衡利弊选择最合适的方式.下面来一起看看详细的介绍: 1. URL 链接后追加参数 ? 1 ...