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

双指针 #68

Open
lovelmh13 opened this issue Jun 10, 2021 · 0 comments
Open

双指针 #68

lovelmh13 opened this issue Jun 10, 2021 · 0 comments

Comments

@lovelmh13
Copy link
Owner

lovelmh13 commented Jun 10, 2021

一般用于线性的数据结构中,比如 链表 和 数组

有「快慢指针」,「左右指针」,「碰撞指针」,「滑动窗口」等

左右指针

一般用在数组

只要是有序数组,就应该想到双指针方法。

一个数组:

一般初始化在数组的两头 left=0 right = arr.length-1

处理两个数组:

leetcode 88 合并两个有序数组 left=0 right = 0

二分查找

只要是在数组中找一个值,就可以把数组变成有序数组,用二分法查找。

左右指针去重

nums[i] 与 nums[i+1] 比较,相同就 i++
nums[r] 与 nums[r-1] 比较,相同就 r--

用 left right 和 mid

快慢指针

一般用在链表

滑动窗口

子字符串问题,leetcode 3 76 等

什么时候要让 right++,什么时候要让 left++,根据不同题的,有不同的条件

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

1 participant