From e9790e25ab9ba6056e1c8927feec90fed2a5ddd9 Mon Sep 17 00:00:00 2001 From: Lam Haoyin Date: Sun, 26 Dec 2021 15:07:36 +0800 Subject: [PATCH] feat: simplify 211226 --- 2112/211226.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/2112/211226.cpp b/2112/211226.cpp index 53bf434..58442f1 100644 --- a/2112/211226.cpp +++ b/2112/211226.cpp @@ -1,16 +1,12 @@ #include #include -struct EuclideanDistanceCompare { - bool operator()(const std::vector& lhs, const std::vector& rhs) const { - return lhs[0] * lhs[0] + lhs[1] * lhs[1] < rhs[0] * rhs[0] + rhs[1] * rhs[1]; - } -}; - class Solution { public: static std::vector> kClosest(std::vector>& points, int k) { - std::sort(points.begin(), points.end(), EuclideanDistanceCompare{}); + std::sort(points.begin(), points.end(), [](const std::vector& lhs, const std::vector& rhs){ + return lhs[0] * lhs[0] + lhs[1] * lhs[1] < rhs[0] * rhs[0] + rhs[1] * rhs[1]; + }); return {points.begin(), points.begin() + k}; } };