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. js正则表达式 replace替换url的参数

    /* 定义替换对象键值 */var setReferArgs = function(){    var referArgs = new Object();    referArgs['#userID\ ...

  2. os模块-subprocess 模块- configpaser 模块

    一. os 模块 主要用于处理与操作系统相关操作,最常用文件操作 使用场景:当需要操作文件及文件夹(增,删,查,改) os.getcwd()  获取当前工作目录 os.chdir('dirname') ...

  3. linux 程序实现后台运行

    先上代码: getopt函数获取参数  -d 控制台控制运行  -D 后天运行  -h 调用show_help函数. 编译命令 gcc -g -W test.c -o test 注意后台运行 ./te ...

  4. Mysql 用户ip访问根据省份查询

    表名:shop_interview_customer 表结构:customerId空为游客模式 interviedId customerId interviewIP iPdetail 1 1001 1 ...

  5. 逆袭之旅DAY30.XIA.集合

    2018年7月26日 面试题:List和set的区别 ArrayList 遍历效率较高,但添加和删除较慢 遍历集合最高效的方法:迭代器 集合的遍历: 迭代器:Iterator 创建 为什么使用泛型: ...

  6. js编码函数一些区别

    s对文字进行编码涉及3个函数:escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decodeURIComponent 1、 ...

  7. learning at command AT+CSUB

    [Purpose] Learning how to get mobile module info [Eevironment] Shell terminal, base on gcom command ...

  8. java 的类型转换方式

    隐式转换 byte等整型转int,最高位(符号位保留),中间补0 byte bt=-13; bt 源码:1000 1101 反码:1111 0010 补码:1111 0011 int it=bt; i ...

  9. git教程(全)

    参考: http://blog.jobbole.com/78960/

  10. 什么是Java优先级队列(Priority Queue)?

    PriorityQueue是一个基于优先级堆的无界队列.它的元素是按照自然顺序排序的.在创建元素的时候,我们给它一个一个负责排序的比较器.PriorityQueue不允许null值,因为 它们没有自然 ...