leetcode/notes/src/linked-list.md

23 lines
387 B
Markdown
Raw Normal View History

2022-12-02 08:29:51 +00:00
# 总结
2022-12-02 09:24:26 +00:00
首先考虑递归 (e.g. s0206, s0024)
其次考虑双指针 (e.g. s0206, s0019, s0160)
递归遍历单链表:
```cpp
void iter(ListNode *node) {
if (node == nullptr) {
return;
}
/*
your
condition
*/
iter(node->next);
}
```
递归遍历的意义在于让回溯单链表,也就是先遍历到结尾,然后从后往前遍历到某个 condition 。