From 3f683bcbf7d024607326ab5d1350bb82cb3ba9a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Khoa=20Hu=E1=BB=B3nh=20=28Daniel=29?= Date: Mon, 18 Mar 2024 23:42:55 +0700 Subject: [PATCH] Create main.go --- solution/452/main.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 solution/452/main.go diff --git a/solution/452/main.go b/solution/452/main.go new file mode 100644 index 0000000..564074c --- /dev/null +++ b/solution/452/main.go @@ -0,0 +1,22 @@ +package main +func findMinArrowShots(points [][]int) int { + sort.Slice(points, func(i, j int) bool { + if points[i][1] == points[j][1] { + return points[i][0] < points[j][0] + } + return points[i][1] < points[j][1] + }) + + res := 1 + pos := points[0][1] + for _, point := range points { + if point[0] <= pos { + continue + } + + res++ + pos = point[1] + } + + return res +}