Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash #9

Open
TomaChen513 opened this issue Oct 12, 2022 · 1 comment
Open

Hash #9

TomaChen513 opened this issue Oct 12, 2022 · 1 comment
Assignees

Comments

@TomaChen513
Copy link
Contributor

三数之和和四数之和 太难辣

@TomaChen513 TomaChen513 self-assigned this Oct 12, 2022
@xavier-hou
Copy link
Member

@TomaChen513 @CarlChenXueYi
发现了,两种思路

  1. 排序+双指针; 关键点是后面的循环如何写,如三数和
third := xxx
for second:=first+1;second<third;second++ {
    for second<third; 判断值是否不等 {
        third--
    }
    if second == third {
        break // 这个很关键,不然会有问题   
    }
    // 判断值是否等
}
  1. 分而治之,8分成4,4分成2
    四数之和就可以利用这种思路,先两个二重循环,将4个数组合并成2个数组,然后2数之和

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants