public class POINT
    {
        public int X;
        public int Y;
        public int Z;
    }
    public class Solution
    {
        public int[][] KClosest(int[][] points, int K)
        {
            var list = new List<POINT>();
            foreach (var p in points)
            {
                var x = p[0];
                var y = p[1];
                var pow2_z = x * x + y * y;
                var P = new POINT();
                P.X = x;
                P.Y = y;
                P.Z = pow2_z;
                list.Add(P);
            }

            var list2 = list.OrderBy(a => a.Z).Take(K).ToList();
            var list3 = new List<int[]>();
            foreach (var l in list2)
            {
                list3.Add(new int[] { l.X, l.Y });
            }

            return list3.ToArray();
        }
    }

 

posted on 2019-01-22 09:55  Sempron2800+  阅读(114)  评论(0编辑  收藏  举报