number-of-boomerangs
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的更多相关文章
- [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 ...
- LeetCode447. Number of Boomerangs
Description Given n points in the plane that are all pairwise distinct, a "boomerang" is a ...
随机推荐
- linux 配置ssh免密码登录
1.确保主机名唯一 主机名修改方法: a.修改/etc/sysconfig/network,HOSTNAME=想要设置的主机名称 b.修改/etc/hosts,127.0.0.1 localhos ...
- nginx+php+flight 构建RESTFul API
配置: Nginx: conf目录下nginx.conf配置文件. 第44行改为:root D:/wwwroot/www; 第45行改为:index index.html index.htm i ...
- Swift-6-函数
// Playground - noun: a place where people can play import UIKit // 定义和调用函数 func sayHello(personName ...
- 如何快速查看将C反汇编的代码
查看反汇编主要的思路在于将 流程,处理,算法 区分开来.1 函数调用:原C代码: int sum(int, int);int main(){ int c = sum(1, 2); printf(&qu ...
- POJ 1811 Prime Test (Pollard rho 大整数分解)
题意:给出一个N,若N为素数,输出Prime.若为合数,输出最小的素因子.思路:Pollard rho大整数分解,模板题 #include <iostream> #include < ...
- POJ 3243 Clever Y (求解高次同余方程A^x=B(mod C) Baby Step Giant Step算法)
不理解Baby Step Giant Step算法,请戳: http://www.cnblogs.com/chenxiwenruo/p/3554885.html #include <iostre ...
- swift-基础部分
变量常量,注释,分号,整数,浮点数.数值行类型转换,类型别名,波尔值,元组,可选,断言 let binaryInteger = 0b10001 let twoThousan ...
- 深入浅出ES6(十一):生成器 Generators,续篇
作者 Jason Orendorff github主页 https://github.com/jorendorff 欢迎回到深入浅出ES6专栏,望你在ES6探索之旅中收获知识与快乐!程序员们在工作 ...
- hdu 4618(最大回文子矩阵)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4618 昨天多校的一道题,说多了都是泪啊,为了一道图论题,磨了那么久,结果是别的题都没看,没办法,补呗. ...
- springmvc的系统学习之配置方式
资源:尚学堂 邹波 springmvc框架视频 一.springMVC 工作流程 页面请求---->控制器(Controller DispatcherServlet)----& ...