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. 简述Spring容器与SpringMVC的容器的联系与区别

    简述Spring容器与SpringMVC的容器的联系与区别 2017年07月04日 10:55:07 阅读数:6260 摘要: 在Spring整体框架的核心概念中,容器的核心思想是管理Bean的整个生 ...

  2. Cmd管理员运行

    Cmd管理员运行     C:\Windows\System32  

  3. Java版本知识

    1zip是压缩包,而MSI文件是Windows Installer的数据包,它实际上是一个数据库,包含安装一种产品所需要的信息和在很多安装情形下安装(和卸载)程序所需的指令和数据,只要系统中包含win ...

  4. laravel模型表建立外键约束的使用:

    模型: //表->posts class Post extends Model { //关联用户: public function user(){ //belongsTo,第一个参数:外键表,第 ...

  5. laravel中当使用Elquent ORM中的模型作为参数进行传递时的方法:

    Controller中的函数: /* $modelArg:是调用模型的路径,以字符串的形式传递过来. $id:要查询当前模型的id号. $args:具体查询的字段 */ public function ...

  6. 机器学习---笔记----numpy和math包中的常用函数

    本文只是简单罗列一下再机器学习过程中遇到的常用的数学函数. 1. math.fabs(x): 返回x的绝对值.同numpy. >>> import numpy >>> ...

  7. linux系统管理 计划任务

    一次性计划任务 命令: at 语法: at [-f 文件名] 时间 绝对计时方法 HH:MM yyyy-MM-dd 相对计时方法 now + n minutes now+n hours now + n ...

  8. Unity中UI界面颤抖解决方法

    将Render Mode中属性改为Screen Space - Camera 摄像机挂在Canvas属性下会出现UI界面颤抖的效果. UI界面颤抖解决方式:将Render Mode中属性改为Scree ...

  9. 【资料收集】QT 环境安装配置

    (很详细,极力推荐) [OpenCV] -- win7下配置OpenCV的Qt开发环境 - 代码人生 - 博客频道 - CSDN.NET  http://blog.csdn.net/qiurisuix ...

  10. Python Django 之 基于JQUERY的AJAX 登录页面

    一.基于Jquery的Ajax的实现 1.url 2.vews 3.templates