Skip to content

Commit

Permalink
Add solution and test-cases for problem 1726
Browse files Browse the repository at this point in the history
  • Loading branch information
0xff-dev committed Dec 20, 2024
1 parent dbd4dda commit b5671db
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
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() {
}

0 comments on commit b5671db

Please sign in to comment.