[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 ...
随机推荐
- ISO/OSI七层网络参考模型、TCP/IP四层网络模型和教学五层网络模型
一.说明 直接的原因是昨晚<计算机网络(自顶向下方法)>到货了,以为能讲得有些不一样,但看完整本也就是老调地讲过来讲应用层.传输层.网络层.网络接口层.感觉比之谢希仁的<计算机网络& ...
- vs 编译库文件 Qt编译库文件
QT 库能不能用 需要关注是minGW 还是MSVC编译的 Qt MinGW与MSVC对比 转:https://blog.csdn.net/u013185164/article/details/48 ...
- anglar cli的 rxjs_1.of is not a function
按照官网敲例子遇到 rxjs_1.of is not a function import { Observable,of } from 'rxjs'; 改为 import { Observable} ...
- 解决win10打开组策略弹出管理模板对话框问题
今天win10企业版更新完系统,打开组策略编辑器时弹出管理模板对话框问题 1.问题描述 打开组策略编辑器时弹出管理模板对话框问题 2.解决方法 1)window+x 打开命令提示符(管理员) 2)输入 ...
- char和varchar、浮点数和定点数
cmd连接mysql数据库:找到mysql目录,进入到bin目录,然后在命令行中输入 mysql -hlocalhost -uroot -ppass ,连接mysql数据库成功. 1.char和var ...
- java倒计时使用ScheduledExecutor实现,使用两个线程,以秒为单位
public class Countdown2 { private volatile int lin; private int curSec; public Countdown2(int lin) t ...
- Java中数据类型相互转化
1 将String 转换成int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([String], ...
- mysql插入中文乱码
https://www.cnblogs.com/zhchoutai/p/7364835.html 最简单的一招,不用修改my.ini文件: 1.停掉mysql服务 2.启动:X:\%path%\MyS ...
- compile openjdk7 in ubuntu OS
success: openjdk version "1.7.0-internal"OpenJDK Runtime Environment (build 1.7.0-internal ...
- day25 模块04_模块和包
休养生息--模块04 1.导入模块的执行的步骤 2.自定义模块 3.自定义包 一.导入模块的执行步骤 1).判断当前正在导入的模块是否已经导入过 2).如果已经导入过,不会重新导入该模块 3).如果没 ...