Skip to content

Commit 2184186

Browse files
committed
add sol
1 parent 3988358 commit 2184186

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

leetcode/daily/1726/sol.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func tupleSameProduct(nums []int) int {
6+
productCount := make(map[int]int)
7+
count := 0
8+
n := len(nums)
9+
for i := 0; i < n; i++ {
10+
for j := i + 1; j < n; j++ {
11+
product := nums[i] * nums[j]
12+
if val, ok := productCount[product]; ok {
13+
count += val
14+
}
15+
productCount[product]++
16+
}
17+
}
18+
19+
return count * 8
20+
}
21+
22+
func tupleSameProduct1(nums []int) int {
23+
productCount := make(map[int]int)
24+
n := len(nums)
25+
26+
for i := 0; i < n; i++ {
27+
for j := i + 1; j < n; j++ {
28+
product := nums[i] * nums[j]
29+
productCount[product]++
30+
fmt.Println(productCount)
31+
}
32+
33+
}
34+
35+
count := 0
36+
for _, v := range productCount {
37+
count += v * (v - 1) * 8
38+
}
39+
40+
return count / 2
41+
}
42+
43+
func main() {
44+
nums := []int{1, 2, 4, 5, 10}
45+
println(tupleSameProduct1(nums))
46+
}

0 commit comments

Comments
 (0)