Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions leetcode/1701-1800/1726.Tuple-with-Same-Product/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
# [1726.Tuple with Same Product][title]

> [!WARNING|style:flat]
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)

## Description
Given an array `nums` of **distinct** positive integers, return the number of tuples `(a, b, c, d)` such that `a * b = c * d` where `a`, `b`, `c`, and `d` are elements of `nums`, and `a != b != c != d`.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: nums = [2,3,4,6]
Output: 8
Explanation: There are 8 valid tuples:
(2,6,3,4) , (2,6,4,3) , (6,2,3,4) , (6,2,4,3)
(3,4,2,6) , (4,3,2,6) , (3,4,6,2) , (4,3,6,2)
```

## 题意
> ...

## 题解
**Example 2:**

### 思路1
> ...
Tuple with Same Product
```go
```

Input: nums = [1,2,4,5,10]
Output: 16
Explanation: There are 16 valid tuples:
(1,10,2,5) , (1,10,5,2) , (10,1,2,5) , (10,1,5,2)
(2,5,1,10) , (2,5,10,1) , (5,2,1,10) , (5,2,10,1)
(2,10,4,5) , (2,10,5,4) , (10,2,4,5) , (10,2,5,4)
(4,5,2,10) , (4,5,10,2) , (5,4,2,10) , (5,4,10,2)
```

## 结语

Expand Down
16 changes: 14 additions & 2 deletions leetcode/1701-1800/1726.Tuple-with-Same-Product/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package Solution

func Solution(x bool) bool {
return x
func Solution(nums []int) int {
m := make(map[int]int)
l := len(nums)
for i := 0; i < l-1; i++ {
for j := i + 1; j < l; j++ {
cur := nums[i] * nums[j]
m[cur]++
}
}
ans := 0
for _, n := range m {
ans += (n - 1) * n / 2 * 8
}
return ans
}
13 changes: 6 additions & 7 deletions leetcode/1701-1800/1726.Tuple-with-Same-Product/Solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
expect bool
inputs []int
expect int
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", []int{2, 3, 4, 6}, 8},
{"TestCase2", []int{1, 2, 4, 5, 10}, 16},
}

// 开始测试
Expand All @@ -30,10 +29,10 @@ func TestSolution(t *testing.T) {
}
}

// 压力测试
// 压力测试
func BenchmarkSolution(b *testing.B) {
}

// 使用案列
// 使用案列
func ExampleSolution() {
}
Loading