題型
1. 排序:兩個(gè)或多個(gè)array(一般是sorted)按照某規(guī)則排序
88. Merge Sorted Array
283. Move Zeroes
56. Merge Intervals
57. Insert Interval
2. 窗口內(nèi)最大被饿,最小或sum
209. Minimum Size Subarray Sum
42. Trapping Rain Water
11. Container With Most Water
3. 在字符串或數(shù)組中找substring或者subarray
344.Reverse String
186.Reverse Words in a String II
3. Longest Substring Without Repeating Characters
28. Implement strStr()
345. Reverse Vowels of a String
76. Minimum Window Substring
30. Substring with Concatenation of All Words
159. Longest Substring with At Most Two Distinct Characters
487. Max Consecutive Ones II
567. Permutation in String
4.在字符串或數(shù)組中找組合
167. Two Sum II - Input array is sorted
15. 3Sum
259. 3Sum Smaller
16. 3Sum Closest
18. 4Sum
5.建立map(array map or bitmap)苏携,查詢要求結(jié)果
383. Ransom Note
532. K-diff Pairs in an Array
6. 快慢指針
? Find the Middle of Linked List
141. Linked List Cycle I
142. Linked List Cycle II
234. Palindrome Linked List
19.Remove Nth Node From End of List
86. Partition List
7.線性掃描找目標(biāo)
27. Remove Element
26. Remove Duplicates from Sorted Array
80. Remove Duplicates from Sorted Array II
349. Intersection of Two Arrays
350. Intersection of Two Arrays II
126. Valid Palindrome
75. Sort Colors
61. Rotate List
143. Reorder List
632. Smallest Range
360. Sort Transformed Array
524. Longest Word in Dictionary through Deleting
套路
Scanner
注意
舊的練習(xí)
88.merge two sorted array
public void merge(int[] nums1, int m, int[] nums2, int n) {
while(n > 0){
nums1[n + m - 1] = (m == 0 || nums2[n - 1] > nums1[m - 1]) ? nums2[--n] : nums1[--m];
}
}
167.Two Sum II - Input array is sorted
public int[] twoSum(int[] nums, int target) {
// write your code here
int[] res = new int[2];
HashMap<Integer, Integer> map = new HashMap<>();
int left = 0;
int right = nums.length - 1;
while (left < right){
int cur = nums[left] + nums[right];
if (cur == target){
return new int[]{left + 1, right + 1};
} else if (cur < target){
left++;
} else {
right--;
}
}
return res;
}