447. Number of Boomerangs

Easy

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的更多相关文章

  1. [LeetCode] Number of Boomerangs 回旋镖的数量

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  2. [LeetCode]447 Number of Boomerangs

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  3. Leetcode: Number of Boomerangs

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  4. 34. leetcode 447. Number of Boomerangs

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  5. 447. Number of Boomerangs

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  6. [Swift]LeetCode447. 回旋镖的数量 | Number of Boomerangs

    Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...

  7. [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 ...

  8. LeetCode——Number of Boomerangs

    LeetCode--Number of Boomerangs Question Given n points in the plane that are all pairwise distinct, ...

  9. 447. Number of Boomerangs 回力镖数组的数量

    [抄题]: Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple ...

随机推荐

  1. IDA7.0安装findcrypt插件

    效果图附上 安装成功的话,快捷键Ctrl+Alt+F可以调出上图的窗口,识别一些常见的算法,上面识别出是Base64加密 插件链接放上:https://github.com/polymorf/find ...

  2. JMeter压测时报“内存不足”故障的9个简单解决方案

    Test failed! java.lang.OutOfMemoryError: Java heap space 测试失败了!java.lang.OutOfMemoryError:Java堆空间 在不 ...

  3. Educational Codeforces Round 64 (Rated for Div. 2)题解

    Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...

  4. 微信小程序~模板template引用

    当您的项目需要多次使用同一个布局和样式的时候,您就可以考虑使用template(模板)来减少冗余代码. 使用方式: 1.新建一个template文件夹来存放您的通用模板: 2.在文件夹里面新建一个wx ...

  5. java通过JDBC连接Oracle并调用存储过程和存储方法

    初始配置:电脑安装oracle 11g(这里也可使是其它版本也可,此教程演示为11g),java环境,eclipse,oracle关于jdbc的jar包. 一,在scott用户下首先要有存储过程和存储 ...

  6. 数据库jdbc链接:mysql, oracle, postgresql

    #db mysql#jdbc.driver=com.mysql.jdbc.Driver#jdbc.url=jdbc:mysql://localhost:3306/mysql?&useUnico ...

  7. canvas绚丽的随机曲线

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyMAAAHECAIAAAClb2KBAAAgAElEQVR4nOyd+VsaV/v/Pz/UpW3abJ ...

  8. 微信小程序——选择某个区间的数字

    很久没有更新文章啦~~记录下今天弄的一个小功能. 先上图: 需求很简单: 第1列改变的时候,第2列也随着改变,并且比第1列大1k. 这里用到了微信的picker 组件,对于不太熟练这个组件的小伙伴可以 ...

  9. [CodeForces 663E] - Binary Table(FWT)

    题目 Codeforces 题目链接 分析 大佬博客,写的很好 本蒟蒻就不赘述了,就是一个看不出来的异或卷积 精髓在于 mask对sta的影响,显然操作后的结果为mask ^ sta AC code ...

  10. volatile 关键词

    volatile 关键字指示一个字段可以由多个同时执行的线程修改. 出于性能原因,编译器,运行时系统甚至硬件都可能重新排列对存储器位置的读取和写入. 声明了 volatile 的字段不进行这些优化.这 ...