https://leetcode.com/problems/number-of-boomerangs/

package com.company;

import java.util.*;

class Solution {
public int numberOfBoomerangs(int[][] points) {
int ret = 0; for (int i=0; i<points.length; i++) {
Map<Long, Integer> dMap = new HashMap<>();
long dist;
int count; for (int j=0; j<points.length; j++) {
if (i == j) {
continue;
}
dist = (points[i][0]-points[j][0])*(points[i][0]-points[j][0]) +
(points[i][1]-points[j][1])*(points[i][1]-points[j][1]); count = 0;
if (dMap.containsKey(dist)) {
count = dMap.get(dist);
}
count++;
dMap.put(dist, count);
}
Iterator<Map.Entry<Long, Integer>> iter = dMap.entrySet().iterator();
while (iter.hasNext()) {
int val = iter.next().getValue();
ret += val * (val-1);
}
}
return ret;
}
} public class Main { public static void main(String[] args) throws InterruptedException { System.out.println("Hello!");
Solution solution = new Solution(); // Your Codec object will be instantiated and called as such:
int[][] points = {{0,0},{1,0},{2,0}};
int ret = solution.numberOfBoomerangs(points);
System.out.printf("ret:%d\n", ret); System.out.println(); } }

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

  10. LeetCode447. Number of Boomerangs

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

随机推荐

  1. QGraphics

    QGraphicsView和QGraphicsScene QGraphicsScene提供一个场景,可以添加各种item,QGraphicsView用于将元素显示,并支持旋转和缩放:可以将QGraph ...

  2. javascript实现数据结构与算法系列:循环链表与双向链表

    循环链表(circular linked list) 是另一种形式的链式存储结构.它的特点是表中最后一个结点的指针域指向头结点,整个表形成一个环. 循环链表的操作和线性链表基本一致,仅有细微差别. w ...

  3. Chapter 3

    1.序列类型可以使用成员操作符in,大小计算函数(len()),分片([]),都可以迭代.Python内置的序列类型:str,list,tuple,bytearray,bytes.标准库中的序列类型: ...

  4. 全7 天玩转 ASP.NET MVC — 第 2 天

    0. 前言 我相信在开始第 2 天的学习时,你已经顺利地完成了第 1 天的课程. 我们回顾一下第 1 天的主要关注点: 为什么选择 ASP.NET MVC ? ASP.NET Webforms 和 A ...

  5. 【一】php 操作符

    1.php单引号和双引号的区别 单引号和双引号都能表示字符串,但是单引号不能识别里面带有转义字符'/'和变量的字符串,所以需要""去表示这种字符串.或者使用<<< ...

  6. 最常用的javascript方法函数

    字符串长度截取 function cutstr(str, len) { var temp, icount = 0, patrn = /[^\x00-\xff]/, strre = "&quo ...

  7. Linux基础--例行工作

    1.仅进行一次的工作排程--at at的工作情况其实是这样的: 1)先找寻/etc/at.allow这个档案,写在这个档案中的使用者才能使用at,没有在这个档案中的使用者则不能使用at(即使没有写在a ...

  8. Java-J2SE学习笔记-树状展现文件结构

    1.利用java.io相关类树状展现文件结构 2.判定给定路径是否为dir,是则递归,每一递归一层缩进一次 3.代码 package Test; import java.io.File; public ...

  9. 开放api设计资料收藏

    REST设计 api设计范例http://www.ibm.com/developerworks/cn/web/1103_chenyan_restapi/index.html?ca=drs http:/ ...

  10. CentOS中通过stat查看文件的元数据

    CentOS中可以通过stat查看文件的元数据 [baby@xiaoxiao abc]$ stat honey  File: `honey'  Size: 25         Blocks: 8   ...