K Smallest In Unsorted Array
1 | // min heap: offline算法 |
Rainbow Sort
1 | public class Solution { |
Overview
Array and Sorting Algorithms
4. Selection Sort
1 | // 4. Selection Sort |
279. Sort With 3 Stacks
1 | // 279. Sort With 3 Stacks |
280. Sort With 2 Stacks
1 | // 280. Sort With 2 Stacks |
9. Merge Sort
1 | // 9. Merge Sort |
29. Merge Sort Linked List
1 | // 29. Merge Sort Linked List |
10. Quick Sort
1 | // 10. Quick Sort |
10. Quick Sort (jiuzhang solution)
1 | // 10. Quick Sort |
258. Move 0s To The End I
1 | // 258. Move 0s To The End I |
259. Move 0s To The End II
1 | // 259. Move 0s To The End II |
519. Move zeros
1 | // 519. Move zeros |
395. Remove Certain Characters
1 | // 395. Remove Certain Characters |
281. Remove Spaces
1 | // 281. Remove Spaces |
549. Partition
1 | // 549. Partition |
Recursion I
12. Fibonacci Number
1 | // 12. Fibonacci Number |
538. Calculate a to the power of b (naive)
1 | // 538. Calculate a to the power of b (naive) |
Binary Search
14. Classical Binary Search
1 | public class Solution { |
15. First Occurrence
1 | public class Solution { |
16. Last Occurrence
1 | public class Solution { |
17. Closest In Sorted Array
1 | public class Solution { |
19. K Closest In Sorted Array
1 | public class Solution { |
636. Smallest Element Larger than Target
1 | public class Solution { |
20. Search In Unknown Sized Sorted Array
1 | /* |
267. Search In Sorted Matrix I
1 | // 267. Search In Sorted Matrix I |
267. Search In Sorted Matrix I (M2)
1 | // 267. Search In Sorted Matrix I |
Queue & Stack
31. Queue By Two Stacks
1 | // 31. Queue By Two Stacks |
32. Stack With min()
1 | // 32. Stack With min() |
32. Stack With min() (M2)
1 | // 32. Stack With min() |
8. Evaluate Reverse Polish Notation
1 | public class Solution { |
LinkedList
36. Middle Node Of Linked List
1 | public class Solution { |
37. Check If Linked List Has A Cycle
1 | public class Solution { |
38. Cycle Node In Linked List
题解:
- 使用双指针判断链表中是否有环,慢指针每次走一步,快指针每次走两步,若链表中有环,则两指针必定相遇。
- 假设环的长度为l,环上入口距离链表头距离为a,两指针第一次相遇处距离环入口为b,则另一段环的长度为c=l-b,由于快指针走过的距离是慢指针的两倍,则有a+l+b=2 * (a+b),又有l=b+c,可得a=c,故当判断有环时(slow==fast)时,移动头指针,同时移动慢指针,两指针相遇处即为环的入口。
1 | public class Solution { |
39. Insert In Sorted Linked List
1 | // Good taste! |
29. Merge Sort Linked List
1 | public class Solution { |
\42. Partition Linked List
\41. ReOrder Linked List
Binary Tree & Binary Search Tree
Heap
Breadth-First Search (BFS-1):
Best First Search (BFS-2)
Depth First Search
62. All Subsets I
1 | // 62. All Subsets I |
63. All Subsets II
1 | // 63. All Subsets II |
nowcoder subsets
1 | // input: [1, 2, 3] |
64. All Permutations I
1 | // 64. All Permutations I |
65. All Permutations II
1 | // 65. All Permutations II |