We have a list of points on the plane.  Find the K closest points to the origin (0, 0).

(Here, the distance between two points on a plane is the Euclidean distance.)

You may return the answer in any order.  The answer is guaranteed to be unique (except for the order that it is in.)

Example 1:

Input: points = [[1,3],[-2,2]], K = 1
Output: [[-2,2]]
Explanation:
The distance between (1, 3) and the origin is sqrt(10).
The distance between (-2, 2) and the origin is sqrt(8).
Since sqrt(8) < sqrt(10), (-2, 2) is closer to the origin.
We only want the closest K = 1 points from the origin, so the answer is just [[-2,2]].

Example 2:

Input: points = [[3,3],[5,-1],[-2,4]], K = 2
Output: [[3,3],[-2,4]]
(The answer [[-2,4],[3,3]] would also be accepted.)

Note:

  1. 1 <= K <= points.length <= 10000
  2. -10000 < points[i][0] < 10000
  3. -10000 < points[i][1] < 10000

没啥好说的,写的差劲了

struct P{
double dis;
int adr;
}H[];
bool cmd(P x,P y){
if(x.dis <= y.dis){
return ;
}
return ;
}
class Solution {
public:
vector<vector<int>> kClosest(vector<vector<int>>& points, int K) {
vector<vector<int>> x;
vector<int>y; int Len = points.size();
for(int i=;i<Len;i++){
int a = points[i][];
int b = points[i][];
//cout<<a<<" "<<b<<endl;
double result = sqrt(a*a+b*b);
H[i].dis = result;
H[i].adr = i;
}
sort(H,H+Len,cmd);
for(int i=;i<K;i++){
x.push_back(points[H[i].adr]);
}
return x;
}
};

119th LeetCode Weekly Contest K Closest Points to Origin的更多相关文章

  1. 【LeetCode】973. K Closest Points to Origin 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 小根堆 日期 题目地址:https://leetco ...

  2. 【leetcode】973. K Closest Points to Origin

    题目如下: We have a list of points on the plane.  Find the Kclosest points to the origin (0, 0). (Here, ...

  3. LeetCode 973. K Closest Points to Origin

    原题链接在这里:https://leetcode.com/problems/k-closest-points-to-origin/ 题目: We have a list of points on th ...

  4. LeetCode 973 K Closest Points to Origin 解题报告

    题目要求 We have a list of points on the plane.  Find the K closest points to the origin (0, 0). (Here, ...

  5. [Swift]LeetCode973. 最接近原点的 K 个点 | K Closest Points to Origin

    We have a list of points on the plane.  Find the K closest points to the origin (0, 0). (Here, the d ...

  6. [Solution] 973. K Closest Points to Origin

    Difficulty: Easy Problem We have a list of points on the plane. Find the K closest points to the ori ...

  7. 973. K Closest Points to Origin

    We have a list of points on the plane.  Find the K closest points to the origin (0, 0). (Here, the d ...

  8. LC 973. K Closest Points to Origin

    We have a list of points on the plane.  Find the K closest points to the origin (0, 0). (Here, the d ...

  9. K Closest Points to Origin

    We have a list of points on the plane.  Find the K closest points to the origin (0, 0). (Here, the d ...

随机推荐

  1. iOS与HTML5交互方法总结(修正)

    摘要 看了不少别人写的博客或者论坛,关于iOS与HTML5交互方法大概主要有5种方式: 1. 利用WKWebView进行交互(系统API) 2. 利用UIWebView进行交互(系统API) 3. 苹 ...

  2. 面试题:String StringBufere StringBuilder 不用看

    一.String 使用 private final char value[]来实现字符串存储 所以String对象创建之后就不能再修改此对象中存储的字符串内容,所以说String本质是字符数组char ...

  3. Mips下交叉编译dropbear

    1. 编译zlib-1.2.8 在编译dropbear的时候,会遇到“configure: error: *** zlib missing - install first or check confi ...

  4. 21. Date 函数

    SQL 日期 当我们处理日期时,最难的任务恐怕是确保所插入的日期的格式,与数据库中日期列的格式相匹配. 只要数据包含的只是日期部分,运行查询就不会出问题.但是,如果涉及时间,情况就有点复杂了. 在讨论 ...

  5. Shiro——概述

    Apache Shiro 是 Java 的一个安全(权限)框架. Shiro 可以非常容易的开发出足够好的应用,其不仅可以用在JavaSE 环境,也可以用在 JavaEE 环境. Shiro 可以完成 ...

  6. 实践作业3:白盒测试----findbugs介绍及使用DAY7

    本小组选择的是一个开源的Java静态代码分析工具----Findbugs. 与其他静态分析工具(如Checkstyle和PMD)不同,FindBugs 不注重样式或者格式,它专注于寻找真正的缺陷或者潜 ...

  7. 备忘录(Memento)模式

    *备忘录模式(Memento):在不破坏封装性的前提下,捕获一个对戏的内部状态, * 并在该对象之外保存这个状态.这样以后就能恢复到原来保存的状态 *Originator(发起人): 负责创建一个备忘 ...

  8. WebService 天气预报webservice接口

    WebService  天气预报webservice接口 地址:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx 常用接口: 1. ...

  9. git Problem with the SSL CA cert (path? access rights?)

    问题: [root@localhost opt]# git clone https://github.com/docker/docker.git 正克隆到 'docker'...fatal: unab ...

  10. 51 nod 1350 斐波那契表示

    每一个正整数都可以表示为若干个斐波那契数的和,一个整数可能存在多种不同的表示方法,例如:14 = 13 + 1 = 8 + 5 + 1,其中13 + 1是最短的表示(只用了2个斐波那契数).定义F(n ...