当前位置:网站首页>November 15, 2021: add four numbers II. Here are four integer arrays nums1, num
November 15, 2021: add four numbers II. Here are four integer arrays nums1, num
2022-06-24 01:43:00 【Fuda scaffold constructor's daily question】
2021-11-15: Add four numbers II. Here are four integer arrays nums1、nums2、nums3 and nums4 , The length of the array is n , Please calculate how many tuples there are (i, j, k, l) To meet the :0 <= i, j, k, l < n;nums1i + nums2j + nums3k + nums4l == 0. Power button 454.
answer 2021-11-15:
nums1+nums2 save map. Then seek nums3 +nums4 , stay map Find the opposite number in , Just add it to the results .
Time complexity :O(N**2).
Extra space complexity :O(N**2).
The code to use golang To write . The code is as follows :
package main
import "fmt"
func main() {
nums1 := []int{1, 2}
nums2 := []int{-2, -1}
nums3 := []int{-1, 2}
nums4 := []int{0, 2}
ret := fourSumCount(nums1, nums2, nums3, nums4)
fmt.Println(ret)
}
func fourSumCount(A, B, C, D []int) int {
map0 := make(map[int]int)
sum := 0
for i := 0; i < len(A); i++ {
for j := 0; j < len(B); j++ {
sum = A[i] + B[j]
map0[sum]++
}
}
ans := 0
for i := 0; i < len(C); i++ {
for j := 0; j < len(D); j++ {
sum = C[i] + D[j]
if _, ok := map0[-sum]; ok {
ans += map0[-sum]
}
}
}
return ans
}The results are as follows :
边栏推荐
- Qu'est - ce que le financement des pensions? Quels sont les produits financiers pour les personnes âgées?
- Comparison between rule engine and ML model - xlaszlo
- Can the server be restarted through the fortress machine? How are the fortress machines connected to the server
- A marriage app_ T signature analysis
- Why promote steam education?
- Activity Registration - Tencent cloud digital intelligence driven SME transformation and upgrading series salon · Zhuhai station
- [new secsha!] Have you got the 22 year new seckill activity of Tencent cloud?
- How to learn website construction does website construction need code
- Ppt layout design how to make pages not messy
- [dry goods] four tools linkage of automated batch hole digging process
猜你喜欢
![[SQL injection 12] user agent injection foundation and Practice (based on burpsuite tool and sqli labs LESS18 target machine platform)](/img/c8/f6c2a62b8ab8fa88bd2b3d8f35f592.jpg)
[SQL injection 12] user agent injection foundation and Practice (based on burpsuite tool and sqli labs LESS18 target machine platform)

I, a 27 year old female programmer, feel that life is meaningless, not counting the accumulation fund deposit of 430000

It's too difficult for me. Ali has had 7 rounds of interviews (5 years of experience and won the offer of P7 post)
![[SQL injection 13] referer injection foundation and Practice (based on burpseuite tool and sqli labs less19 target platform)](/img/b5/a8c4bbaf868dd20b7dc9449d2a4378.jpg)
[SQL injection 13] referer injection foundation and Practice (based on burpseuite tool and sqli labs less19 target platform)
随机推荐
[dry goods] four tools linkage of automated batch hole digging process
Troubleshooting and repair of easygbs docking with universal video equipment to broadcast message 487
Flink weapon: introduction to the open source platform streamx
[SQL injection 12] user agent injection foundation and Practice (based on burpsuite tool and sqli labs LESS18 target machine platform)
How to realize court face recognition / flow statistics based on easycvr technology?
DCOM horizontal movement of Intranet penetration
Common e-commerce data index system
Eight common errors in programming
How to use voice synthesis? Can voice synthesis modify the voice?
Dart series: using packages in dart
Go language core 36 lectures (go language practice and application VII) -- learning notes
2、 Shell position variable
What does fortress server mean? What are the benefits of Fortress server installation
NFS operations and deployment
How to choose a website construction company self-study website or website construction company
Virtual currency mining detection and defense
Easynvr background channel list timing request touchstreamclient interface optimization
How to build a high-quality website
Zoom supports automatic generation of subtitles; Shareplay goes online; Safari update leads to a large number of bugs | webrtc wind direction
Application analysis of video edge computing gateway easynvr in video overall monitoring solution