Leetcode 973. K Closest Points to Origin

送分题

class Solution(object):
    def kClosest(self, points, K):
        """
        :type points: List[List[int]]
        :type K: int
        :rtype: List[List[int]]
        """
        dst, ret = {}, []
        for i, val in enumerate(points):
            dst[i] = val[0] ** 2 + val[1] ** 2
        dst = sorted(dst.items(), key=lambda d:d[1])
        for key,val in dst:
            ret.append(points[key])
        return ret[:K]
原文地址:https://www.cnblogs.com/zywscq/p/10543956.html