Two Pointers
in Coding Interview on Topics, Two Pointers
Two Pointers
배열이 정렬되어 있으면 Two Pointer 를 사용할 수 있는지 생각해 본다.
reverse array
public void reverse(int[] nums, int start, int end) {
while (start < end) {
int temp = nums[start];
nums[start] = nums[end];
nums[end] = temp;
start++;
end--;
}
}
[Easy]
- 26. Remove Duplicates from Sorted Array
- 28. Find the Index of the First Occurrence in a String
- 88. Merge Sorted Array
- 121. Best Time to Buy and Sell Stock
- 125. Valid Palindrome
- 141. Linked List Cycle
- 283. Move Zeroes
- 344. Reverse String
- 345. Reverse Vowels of a String
- 350. Intersection of Two Arrays II
- 392. Is Subsequence
- 557. Reverse Words in a String III
- 643. Maximum Average Subarray I
- 876. Middle of the Linked List
- 1768. Merge Strings Alternately
[Medium]
- 5. Longest Palindromic Substring
- 11. Container With Most Water
- 15. 3Sum
- 16. 3Sum Closest
- 18. 4Sum
- 19. Remove Nth Node From End of List
- 28. Find the Index of the First Occurrence in a String
- 31. Next Permutation
- 61. Rotate List
- 75. Sort Colors
- 80. Remove Duplicates from Sorted Array II
- 82. Remove Duplicates from Sorted List II
- 86. Partition List
- 131. Palindrome Partitioning
- 148. Sort List
- 167. Two Sum II - Input Array Is Sorted
- 186. Reverse Words in a String II
- 209. Minimum Size Subarray Sum
- 253. Meeting Rooms II
- 281. Zigzag Iterator
- 287. Find the Duplicate Number
- 438. Find All Anagrams in a String
- 443. String Compression
- 532. K-diff Pairs in an Array
- 658. Find K Closest Elements
- 723. Candy Crush
- 986. Interval List Intersections
- 1004. Max Consecutive Ones III
- 1100. Find K-Length Substrings With No Repeated Characters
- 1229. Meeting Scheduler
- 1498. Number of Subsequences That Satisfy the Given Sum Condition
- 1868. Product of Two Run-Length Encoded Arrays
- 1877. Minimize Maximum Pair Sum in Array
- 2095. Delete the Middle Node of a Linked List
- 2130. Maximum Twin Sum of a Linked List
- 2422. Merge Operations to Turn Array Into a Palindrome
[Hard]