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 ...
随机推荐
- 【ASP.Net MVC】AspNet Mvc一些总结
AspNet Mvc一些总结 RestaurantReview.cs using System; using System.Collections.Generic; using System.Comp ...
- 如何让360、遨游、猎豹等双核浏览器默认以webkit内核渲染网页?
众知目前国内不少浏览器都自称双核,一般是 IE(Trident)+Webkit.因为 webkit 急速的体验和对 HTML5 的支持,有些情况下开发者可能希望用户优先甚至只使用 webkit 内核渲 ...
- 《JavaScript高级程序设计》
第二章在html中使用Javascript2.1<script>在使用<script>嵌入JS代码时,不要再代码中的任何地方出现"</script>&qu ...
- Apache CXF实现Web Service(3)——Tomcat容器和不借助Spring的普通Servlet实现JAX-RS(RESTful) web service
起步 参照这一系列的另外一篇文章: Apache CXF实现Web Service(2)——不借助重量级Web容器和Spring实现一个纯的JAX-RS(RESTful) web service 首先 ...
- maven 常用5个命令
1. mvn help:describe 你是否因为记不清某个插件有哪些goal而痛苦过,你是否因为想不起某个goal有哪些参数而苦恼,那就试试这个命令吧,它会告诉你一切的. 参数: 1. -Dplu ...
- Android开发者:你真的会用AsyncTask吗?
[导读]在Android应用开发的过程中,我们需要时刻注意保证应用程序的稳定和UI操作响应及时,因为不稳定或响应缓慢的应用将给应用带来不好的印象,严重的用户卸载你的APP,这样你的努力就没有体现的价值 ...
- vs2008 wince 通过字符串对控件操作
例如:我们知道控件名为"textbox1"需要对textbox1进行赋值:通常我们只要textbox1.text = "你好";即可 此处我们是通过" ...
- iOS警告-Warning: Error creating LLDB target at path(模拟器警告)
Warning: Error creating LLDB target at path '/Users/apple/Library/Developer/Xcode/DerivedData/Observ ...
- java 如何连接MySql数据库
利用jdbc方式连接数据库. 1.添加mysql驱动jar包 我用的是这个驱动包mysql-connector-java-5.1.26-bin.jar 添加方式: 2.加载MySql驱动类 priva ...
- Linux :Can't start up: not enough memory
http://stackoverflow.com/questions/9634577/linux-cant-start-up-not-enough-memory