LeetCode_447. Number of Boomerangs
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]]
package leetcode.easy;
public class NumberOfBoomerangs {
public int numberOfBoomerangs(int[][] points) {
int res = 0;
java.util.HashMap<Integer, Integer> map = new java.util.HashMap<Integer, Integer>();
for (int[] i : points) {
for (int[] j : points) {
if (i == j) {
continue;
}
Integer dist = (i[0] - j[0]) * (i[0] - j[0]) + (i[1] - j[1]) * (i[1] - j[1]);
Integer prev = map.get(dist);
if (prev != null) {
res += 2 * prev;
}
map.put(dist, (prev == null) ? 1 : prev + 1);
}
map.clear();
}
return res;
}
@org.junit.Test
public void test() {
int[][] points = { { 0, 0 }, { 1, 0 }, { 2, 0 } };
System.out.println(numberOfBoomerangs(points));
}
}
LeetCode_447. Number of Boomerangs的更多相关文章
- [LeetCode] 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 ...
- Leetcode: 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 ...
- [Swift]LeetCode447. 回旋镖的数量 | Number of Boomerangs
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- [LeetCode&Python] Problem 447. Number of Boomerangs
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
- LeetCode——Number of Boomerangs
LeetCode--Number of Boomerangs Question Given n points in the plane that are all pairwise distinct, ...
- 447. Number of Boomerangs 回力镖数组的数量
[抄题]: Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple ...
随机推荐
- mongodb移除分片和添加分片(转)
首先我们要移除的分片之后再次添加此分片时会出现添加失败的情况,需要在添加的分片上登录进行删除此分片之前数据库的历史数据比如testdb,删除分片上的数据库之后就可重新添加此分片到mongos中 1.执 ...
- [转]sqlserver判断字符串是否是数字
sql2005有个函数ISNUMERIC(expression)函数:当expression为数字时,返回1,否则返回0.这只是一个菜鸟级的解决办法,大多数情况比较奏效. eg: 1 select I ...
- selenium+python自动化99-清空输入框clear()失效问题解决
前言 在使用selenium做UI自动化的时候,发现有些弹出窗上的输入框,输入文本后,使用clear()方法无效. 这样会导致再次输入时,字符串不是清空后输入,而是跟着后面输入一长串,导致结果不准. ...
- 8、Python简单数据类型(int、float、complex、bool、str)
一.数据类型分类 1.按存值个数区分 单个值:数字,字符串 多个值(容器):列表,元组,字典,集合 2.按可变不可变区分 可变:列表[],字典{},集合{} 不可变:数字,字符串,元组().bool, ...
- 常用Maven插件介绍(转载)
我们都知道Maven本质上是一个插件框架,它的核心并不执行任何具体的构建任务,所有这些任务都交给插件来完成,例如编译源代码是由maven- compiler-plugin完成的.进一步说,每个任务对应 ...
- STM32L4R9使用HAL库调试IIC注意事项
STM32使用Cubemx生成的代码中,用到IIC的驱动,但是始终不能读写,因此使用逻辑分析仪,发现原本地址为0x58的写成了0x20,因此肯定是地址错了.因此,总结如下: 1.需要逻辑分析仪分析II ...
- java代码操作word模板并生成PDF
这个博客自己现在没时间写,等后面有时间了,自己再写. 这中需求是在实际的项目开发中是会经常遇到的. 下面我们先从简单入手一步一步开始. 1.首先,使用word创建一个6行两列的表格. 点击插入-6行2 ...
- git和bootstrap
在linux系统中某种类型的服务有没有启动:ps -ef|grep 对应的服务名称 然后修改gitlab中的两个配置文件的信息 一般情况下是先创建组,然后在创建项目 常见的协议有http协议 ss ...
- 6、Hadoop 2.6.0 运行
运行方式 Local (Standalone) Mode Pseudo-Distributed Mode Fully-Distributed Mode Standalone Operation $ s ...
- 做勇敢女孩 https://www.bilibili.com/video/av14346123?from=search&seid=14078047355739050009
So a few years ago, I did something really brave, or some would say really stupid. I ran for congres ...