2022-06-14 23:33:35 +08:00
# Two pointers approach
#### 2022-06-14 23:06
2022-09-03 15:41:36 +08:00
---
2022-06-14 23:33:35 +08:00
##### Algorithms:
2022-09-03 15:41:36 +08:00
#algorithm #two_pointers
2022-06-14 23:33:35 +08:00
##### Data structures:
2022-09-03 15:41:36 +08:00
#array #linked_list
2022-06-14 23:33:35 +08:00
##### Difficulty:
2022-09-03 15:41:36 +08:00
2022-09-05 16:10:30 +08:00
#CS_analysis
2022-09-03 15:41:36 +08:00
2022-06-14 23:33:35 +08:00
##### Related problems:
2022-09-03 15:41:36 +08:00
2022-06-14 23:33:35 +08:00
##### Links:
2022-09-03 15:41:36 +08:00
2022-06-14 23:33:35 +08:00
- [leetcode ](https://leetcode.com/explore/learn/card/fun-with-arrays/511/in-place-operations/ )
2022-09-05 16:10:30 +08:00
- [Two-pointers and sliding windows ](https://leetcode.com/problems/subarray-sum-equals-k/discuss/301242/General-summary-of-what-kind-of-problem-can-cannot-solved-by-Two-Pointers )
2022-09-03 15:41:36 +08:00
---
2022-06-14 23:33:35 +08:00
### What is Two pointers approach?
2022-09-03 15:41:36 +08:00
2022-06-14 23:33:35 +08:00
By using two pointers, to in place modify array elements.
2022-09-03 15:41:36 +08:00
2022-06-14 23:33:35 +08:00
- One fast and one slow [[Leetcode Best-Time-To-Buy-And-Sell-Stock]] or [[Leetcode Linked-List-Cycle]]
- The two are unordered [[Leetcode Merge-Two-Sorted-Lists]]
### Why and when to use it?
2022-09-03 15:41:36 +08:00
2022-06-14 23:33:35 +08:00
- There are two arrays, or linked lists
2022-09-03 15:41:36 +08:00
- They are sorted, or operation in place will not interfere elements after.
2022-09-05 16:10:30 +08:00
### When not use it?
Refer to [this link ](https://leetcode.com/problems/subarray-sum-equals-k/discuss/301242/General-summary-of-what-kind-of-problem-can-cannot-solved-by-Two-Pointers )
2022-09-06 20:22:48 +08:00
#TODO: complete this section