K Closest Points to Origin Solutions in GoNumber 973Difficulty MediumAcceptance 63.8%Link LeetCodeOther languages C++SolutionsGo solution by halfrost/LeetCode-Gopackage leetcode import "sort" // KClosest definefunc KClosest(points [][]int, K int) [][]int { sort.Slice(points, func(i, j int) bool { return points[i][0]*points[i][0]+points[i][1]*points[i][1] < points[j][0]*points[j][0]+points[j][1]*points[j][1] }) ans := make([][]int, K) for i := 0; i < K; i++ { ans[i] = points[i] } return ans}package leetcode import "sort" // KClosest define func KClosest(points [][]int, K int) [][]int { sort.Slice(points, func(i, j int) bool { return points[i][0]*points[i][0]+points[i][1]*points[i][1] < points[j][0]*points[j][0]+points[j][1]*points[j][1] }) ans := make([][]int, K) for i := 0; i < K; i++ { ans[i] = points[i] } return ans }