[LeetCode&Python] Problem 447. Number of Boomerangs
2024-08-28 15:44:40
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
最新文章
- Acadia Lab 6 轮盘游戏机
- Loadrunner上传与下载文件脚本
- C/C++ http协议加载sessionID
- MyScript 手写识别数学公式、图形 自动计算
- java笔记--使用事件分配线程更新Swing控件
- Kalendar server Beijing Tiandiyuandian Technology Limited 果然是木马
- Centos tar命令
- Visual Studio 2012 update3 安装后的问题及解决
- PHP中超全局变量$GLOBALS和global的区别
- [转载]Python实现浏览器自动化操作
- 十、VueJs 填坑日记之在项目中使用Amaze UI
- C++学习-9
- Charles 使用
- ionic3 表单输入元素input的三种事件
- 使用现有的appid和appsecret无法打开二维码
- 自动化测试-1.selenium简介
- CASE WHEN 及 SELECT CASE WHEN的用法(写了一坨烂代码发现两条sql就行了, 哎)
- VULKAN学习笔记-inter教学四篇
- PHP采集库-Snoopy.class.php
- VHF、UHF的频率范围