[LeetCode&Python] Problem 447. Number of Boomerangs
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的更多相关文章
- [LeetCode&Python] Problem 476. Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits ...
- [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 ...
- 【LeetCode】447. Number of Boomerangs 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 [LeetCode] 题目地址:https:/ ...
- LeetCode 447. Number of Boomerangs (回力标的数量)
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- [LeetCode]447 Number of Boomerangs
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- 34. leetcode 447. Number of Boomerangs
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- 447. Number of Boomerangs
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- 447. Number of Boomerangs 回力镖数组的数量
[抄题]: Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple ...
- [LeetCode&Python] Problem 202. Happy Number
Write an algorithm to determine if a number is "happy". A happy number is a number defined ...
随机推荐
- Windows Server 2003添加防火墙策略教程
1.开始--控制面板--Windows防火墙 2.启用 选择启用即启动防火墙 3.添加例外 常常启用防火墙,还是希望某端口能被某些IP所访问,而防火墙默认是禁止所有IP访问本机的所有端口的,此时我们就 ...
- SpringBoot启动器
pom.xml文件1.父项目 <parent> <groupId>org.springframework.boot</groupId> <artifactId ...
- 移动端常用的 meta设置
<meta charset="utf-8"> <meta name="viewport" content="width=device ...
- .clearfix:after(清除浮动)中各个属性及值详细解说
清除浮动.clearfix:after一词,从事web前端的朋友们对此不会陌生吧,下面为大家介绍的是.clearfix:after中用到的所有属性及值的含义,对此感兴趣的朋友可以参考下哈想,希望对大家 ...
- bzoj4698
题解: 后缀数组 对所有序列差分一下 公共串的长度+1就是答案了 二分 扫一遍height即可,.. 代码: #include <bits/stdc++.h> using namespac ...
- 51nod1339飞行任务
首先按照收获从大到小排序. 然后01背包取或者不取即可. 至于为什么这样对的其实我也不知道.... 代码: #include<bits/stdc++.h> using namespace ...
- OO第四次课程总结分析
OO第四次课程总结分析 测试与正确性论证的效果差异及优缺点 测试,即使用测试样例来验证我们的程序是否能完成相应功能的过程.测试数据的产生基于前置条件和后置条件,通过执行测试数据检查方法输出是否满足需求 ...
- JS时间戳和时间之间转换
一.时间转换时间戳 var date = new Date(); //时间对象 var str = date.getTime(); //转换成时间戳 二.时间戳转换为时间 1.转换成形如 2018 ...
- mysql存储过程中使用游标
用户变量一般以@开头,作用于全局范围 局部变量需用 declare 定义格式为 declare 变量名 数据类型 [default value]; mysql 数据类型有 int ,float,dat ...
- 数控AGC实现(转)
相关链接: 一种混合式高动态范围AGC算法与FPGA实现 http://www.sohu.com/a/221438387_781333 基于FPGA的快速自动增益控制系统设计 ...