From c760afc0f76f0713a55c1cb0b4870edb9713a670 Mon Sep 17 00:00:00 2001 From: MH Hung Date: Tue, 2 Sep 2025 13:31:22 +0800 Subject: [PATCH] [#3025] feat(numberOfPairs): add golang solution --- .../go/go.mod | 3 + .../go/main.go | 70 +++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 problems/3025-find-the-number-of-ways-to-place-people-i/go/go.mod create mode 100644 problems/3025-find-the-number-of-ways-to-place-people-i/go/main.go diff --git a/problems/3025-find-the-number-of-ways-to-place-people-i/go/go.mod b/problems/3025-find-the-number-of-ways-to-place-people-i/go/go.mod new file mode 100644 index 0000000..3879058 --- /dev/null +++ b/problems/3025-find-the-number-of-ways-to-place-people-i/go/go.mod @@ -0,0 +1,3 @@ +module leetcode-3025 + +go 1.18 diff --git a/problems/3025-find-the-number-of-ways-to-place-people-i/go/main.go b/problems/3025-find-the-number-of-ways-to-place-people-i/go/main.go new file mode 100644 index 0000000..b48d086 --- /dev/null +++ b/problems/3025-find-the-number-of-ways-to-place-people-i/go/main.go @@ -0,0 +1,70 @@ +// LeetCode 3025: Find The Number Of Ways To Place People I +// 難度: Medium +// 日期: 2025-09-02 + +package main + +import "fmt" + +// TODO: 實作解法 +func numberOfPairs(points [][]int) int { + n := len(points) + count := 0; + + for i:= 0; i < n; i++{ + for j := 0; j < n; j++{ + if i == j { + continue + } + + pointA := points[i] + pointB := points[j] + + if pointA[0] <= pointB[0] && pointA[1] >= pointB[1] { + hasOtherPoint := false; + minX := pointA[0] + maxX := pointB[0] + minY := pointB[1] + maxY := pointA[1] + + for k := 0; k < n; k++{ + if i == k || j == k{ + continue + } + + pointC := points[k] + + if minX <= pointC[0] && pointC[0] <= maxX && minY <= pointC[1] && pointC[1] <= maxY{ + hasOtherPoint = true + break + } + } + + if !hasOtherPoint{ + count++ + } + } + } + } + return count; +} + +func main() { + testCase() +} + +// 測試案例模板 +func testCase() { + // Input: + points := [][]int{ + {6, 2}, + {4, 4}, + {2, 6}, + } + // Expected: + fmt.Printf("Test Case: [[6,2],[4,4],[2,6]]\n") + fmt.Printf("Expected: 2\n") + // Actual: + result := numberOfPairs(points) + fmt.Printf("Result: %d\n", result) +}