当前位置: 首页 > news >正文

网站开发w亿玛酷1流量订制郑州专业seo首选

网站开发w亿玛酷1流量订制,郑州专业seo首选,贵州网站制作公司电话,wordpress教程 下载LeetCode 回旋镖的数量 447. 回旋镖的数量 - 力扣(LeetCode) 题目描述 给定平面上 n 对 互不相同 的点 points ,其中 points[i] [xi, yi] 。回旋镖 是由点 (i, j, k) 表示的元组 ,其中 i 和 j 之间的距离和 i 和 k 之间的欧式…

LeetCode

回旋镖的数量

447. 回旋镖的数量 - 力扣(LeetCode)

题目描述

给定平面上 n互不相同 的点 points ,其中 points[i] = [xi, yi]回旋镖 是由点 (i, j, k) 表示的元组 ,其中 ij 之间的距离和 ik 之间的欧式距离相等(需要考虑元组的顺序)。

返回平面上所有回旋镖的数量。

示例 1:

输入:points = [[0,0],[1,0],[2,0]]
输出:2
解释:两个回旋镖为 [[1,0],[0,0],[2,0]] 和 [[1,0],[2,0],[0,0]]

示例 2:

输入:points = [[1,1],[2,2],[3,3]]
输出:2

示例 3:

输入:points = [[1,1]]
输出:0

提示:

  • n == points.length
  • 1 <= n <= 500
  • points[i].length == 2
  • -104 <= xi, yi <= 104
  • 所有点都 互不相同

思路

枚举 + 哈希表

代码

C++
#include <vector>
#include <unordered_map>class Solution {
public:// 计算回旋镖的数量int numberOfBoomerangs(std::vector<std::vector<int>>& points) {int length = points.size();if (length < 3) return 0;int ans = 0;// 遍历所有点for (int i = 0; i < length; i++) {std::unordered_map<int, int> counter;// 计算距离并统计相同距离的点for (int j = 0; j < length; j++) {int 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]);int same = counter[dist];ans += same;counter[dist]++;}}// 每组回旋镖的数量乘以2,因为可以交换点的顺序return ans * 2;}
};
Java
class Solution {public int numberOfBoomerangs(int[][] points) {int length = points.length;if(length < 3) return 0;int ans = 0;for(int i = 0; i < length; i++){Map<Integer,Integer> counter = new HashMap<>();for(int j = 0; j < length; j++){int 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]);int smae = counter.getOrDefault(dist,0);ans += smae;counter.put(dist, smae + 1);}}return ans * 2;}
}

image-20240108190336005

http://www.mmbaike.com/news/100914.html

相关文章:

  • 学校网站建设目的东莞百度seo排名
  • 上海高中生做课题的网站seo资讯网
  • 大连自媒体公司seo问答
  • 软件大全链接网站网页推广平台
  • 网站怎么做动效seo需要掌握哪些技术
  • 网上做代卖的网站球队积分排名
  • 比较好的 网站统计系统 php源码培训心得简短200字
  • 郑州直播网站建设抖音seo公司
  • 视频代做网站外贸推广网站
  • 单页网站下载网站优化策略
  • 检测网站速度今天最新的新闻头条
  • 医院病房建设网站足球排行榜前十名
  • 做网站要准备哪些精准广告投放
  • 佛山网站建设外包今天济南刚刚发生的新闻
  • 阿里云 万网 网站最火的推广软件
  • vps怎么做网站外贸seo是什么意思
  • 辽阳企业网站建设服务营销网络营销
  • dw做网站实例网络营销方式有哪些分类
  • 网站诊断案例石家庄房价
  • 自己随便玩玩的网站怎么建设网络营销师工作内容
  • 京东可以免费做特效的网站最近新闻热点国家大事
  • b2b网站的特点seo 的作用和意义
  • ps做的网站首页seo站长工具 论坛
  • 提供网站建设服务的网站域名服务器ip地址查询
  • 上海金工建设集团有限公司网站怎么在百度发布免费广告
  • 如何建设机器人教育网站站长统计 网站统计
  • 有每天做任务赚钱的网站吗考研比较厉害的培训机构
  • 链家做网站和手机app花了多少钱哈尔滨网站制作软件
  • xampp 查看wordpress模板无锡seo网络推广
  • 淄博政府网站建设公司哪家专业投稿网