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

TwoPointers #27

Open
wants to merge 1 commit into
base: docsify
Choose a base branch
from
Open

Conversation

DukeEnglish
Copy link

add two pointer

@liweiwei1419 liweiwei1419 self-requested a review June 10, 2020 22:00

针对以上的三种类型,都给出了模版。可是就像weiwei大佬说的[link](https://ojeveryday.github.io/AlgoWiki/#/BinarySearch/01-introduction?id=%e4%ba%8c%e5%88%86%e6%9f%a5%e6%89%be%e7%9a%84%e4%b8%89%e4%b8%aa%e6%a8%a1%e6%9d%bf),仅供参考哈。模版的意义在于可以帮助减少对某些边界条件的考虑以及对于某些问题的多想,节约脑细胞。

一般来说我们都需要用到两个变量,分别表示两个idx,一般是数组或者字符串中的idx。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idx 这种缩写不知道是不是规范,可以说两个下标(索引),或者就说两个变量,问题都不大。

因为双指针就是在解决问题的过程中,使用的两个变量。


NOTE:

滑动窗口应该算是双指针的一种应用,同时还可以用queue来实现。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 同上,「应该算」建议删去;
    +「同时还可以用queue来实现。」建议删去。

return head.next

slow = head
quick = head
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

前面快慢指针命名用 fast,这里命名也需要统一用成 fast。

right+=1
if flag==flag_t:
if right-left<res[0]:
print(source[left:right])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print 这样的语句需要从示例代码中删除。

@@ -0,0 +1,152 @@
+ # 相向双指针

相向双指针主要是指两个指针面对面走,常见需要掌握的题目一般有下列:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「指针对撞」的问题例题建议的顺序是:

  • 第 167 题
  • 第 11 题
  • 第 15 题
  • (前 3 题是典型问题)其它相关问题

并且建议尽量通俗地讲清楚,是怎么想到指针一头一尾相向,然后简单说明合理性。


#### [658. 找到 K 个最接近的元素](https://leetcode-cn.com/problems/find-k-closest-elements/)

```python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个题目没有说思路,建议简单说明一下。

@liweiwei1419
Copy link
Contributor

知识点和例题上面没有太多问题,反馈意见如下:

  • 手写格式和代码规范需要加强,例如:数字和字母头尾需要加空格,代码书写规范有些题目不是很到位;
  • 双指针的问题不太好写,主要难在讲清楚是怎么想到可以用双指针做,这一点讲解清楚,可以简化一些例题,把问题留在练习里,可能会更好。

@zerotrac
Copy link

zerotrac commented Jun 26, 2020

要在 sidebar 里面添加一下自己的 markdown 文件哈

@liweiwei1419
Copy link
Contributor

我以前为了看预览,自己加了上去,不知道是不是对原作者有用。

- TwoPointers
    - [README](/TwoPointers/README.md)
    - [01-introduction](/TwoPointers/01-introduction.md)
    - [02-同向双指针](/TwoPointers/02-同向双指针.md)
    - [03-相向双指针](/TwoPointers/03-相向双指针.md)
    - [04-背向双指针](/TwoPointers/04-背向双指针.md)
    - [05-practices](/TwoPointers/05-practices.md)

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

Successfully merging this pull request may close these issues.

3 participants