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 ...
随机推荐
- C# 退出应用程序的几种方法
Application.Exit();//好像只在主线程可以起作用,而且当有线程,或是阻塞方法的情况下,很容易失灵 this.Close();//只是关闭当前窗体. Application.ExitT ...
- 批量插入实体类转化DataTable
/// <summary> /// 根据实体类得到表结构 /// </summary> /// <param name="model">实体类& ...
- wordpress更新出现Briefly unavailable for scheduled maintenance. Check back in a minute.
今天ytkah在更新wordpress插件时出现了Briefly unavailable for scheduled maintenance. Check back in a minute.查找了相关 ...
- Refactoring open source business models
https://opensource.com/business/16/4/refactoring-open-source-business-models They say you never forg ...
- Partition HDU - 4602 (不知道为什么被放在了FFT的题单里)
题目链接:Vjudge 传送门 相当于把nnn个点分隔为若干块,求所有方案中大小为kkk的块数量 我们把大小为kkk的块,即使在同一种分隔方案中的块 单独考虑,它可能出现的位置是在nnn个点的首.尾. ...
- 【洛谷P5050】 【模板】多项式多点求值
code: #include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define set ...
- jsDOM分享1
java scrip-DOM概念分享 在java script中有三大核心分别为:javascript语法,DOM,BOM. 今天分享一下在学习dom后的一些理解,希望大家支持. 绑定事件 之前学习过 ...
- JVM内存的划分
JVM内存的划分有五片: 1. 寄存器: 2. 本地方法区: 3. 方法区: 4. 栈内存: 5. 堆内存.
- EasyEarth三维可视化解决方案——智慧河长
EasyEarth—— 为河长装上“千里眼.顺风耳” 为各级河长办应急指挥.任务指派. 实绩考核提供快速直观的 高效.精准.智能化决策平台. 河长制背景 我国治水工作呈现出新老问题交织态势,河湖管理保 ...
- hdoj - 2602 Bone Collector
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...