You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -277,13 +277,13 @@ Your ideas/fixes/algorithms are more than welcome!
277
277
|187|[Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences/)|[Solution](../master/src/main/java/com/stevesun/solutions/_187.java)| O(n)|O(n) | Medium
278
278
|186|[Reverse Words in a String II](https://leetcode.com/problems/reverse-words-in-a-string-ii/)|[Solution](../master/src/main/java/com/stevesun/solutions/_186.java)| O(n)|O(1)| Medium
|170|[Two Sum III - Data structure design](https://leetcode.com/problems/two-sum-iii-data-structure-design/)|[Solution](../master/src/main/java/com/stevesun/solutions/_170.java)| O(n)|O(n)| Easy
|167|[Two Sum II - Input array is sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/)|[Solution](../master/src/main/java/com/stevesun/solutions/_167.java)| O(logn)|O(1) | Easy|
288
288
|165|[Compare Version Numbers](https://leetcode.com/problems/compare-version-numbers/)|[Solution](../master/src/main/java/com/stevesun/solutions/CompareVersionNumbers.java)| O(n)|O(1) | Easy|
@@ -302,7 +302,7 @@ Your ideas/fixes/algorithms are more than welcome!
302
302
|150|[Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/)|[Solution](../master/src/main/java/com/stevesun/solutions/EvaluateReversePolishNotation.java)| O(?)|O(?) | Medium
303
303
|149|[Max Points on a Line](https://leetcode.com/problems/max-points-on-a-line/)|[Solution](../master/src/main/java/com/stevesun/solutions/MaxPointsonaLine.java)| O(?)|O(?) | Hard|
304
304
|147|[Insertion Sort List](https://leetcode.com/problems/insertion-sort-list/)|[Solution](../master/src/main/java/com/stevesun/solutions/InsertionSortList.java) O(n^2)|O(1) | Medium| Linked List
|145|[Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal/)|[Solution](../master/src/main/java/com/stevesun/solutions/BinaryTreePostOrderTraversal.java)| O(n)|O(h) | Hard| Binary Tree
307
307
|144|[Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal/)|[Solution](../master/src/main/java/com/stevesun/solutions/BinaryTreePreorderTraversal.java)| O(n)|O(h) | Medium| Binary Tree
@@ -341,7 +341,7 @@ Your ideas/fixes/algorithms are more than welcome!
341
341
|103|[Binary Tree Zigzag Level Order Traversal](https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/)|[Solution](../master/src/main/java/com/stevesun/solutions/_103.java)| O(n)|O(h) | Medium| BFS,DFS
342
342
|102|[Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/)|[Solution](../master/src/main/java/com/stevesun/solutions/BinaryTreeLevelOrderTraversal.java)| O(n)|O(h) | Easy| BFS
343
343
|99|[Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree/)|[Solution](../master/src/main/java/com/stevesun/solutions/RecoverBinarySearchTree.java)| O(?) | O(?) | Hard |
|45|[Jump Game II](https://leetcode.com/problems/jump-game-ii/)|[Solution](../master/src/main/java/com/stevesun/solutions/JumpGameII.java)|O(?)|O(?)|Hard|
@@ -407,20 +407,20 @@ Your ideas/fixes/algorithms are more than welcome!
407
407
|24|[Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/)|[Solution](../master/src/main/java/com/stevesun/solutions/SwapNodesinPairs.java)|O(n)|O(1)|Easy| Recursion, LinkedList
408
408
|23|[Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/)|[Solution](../master/src/main/java/com/stevesun/solutions/MergeKSortedList.java)|O(n*logk)|O(logk)|Hard|Heap
|21|[Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/)|[Solution](../master/src/main/java/com/stevesun/solutions/_21.java)|O(n)|O(1)|Easy|
|21|[Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/)|[Solution](../master/src/main/java/com/stevesun/solutions/_21.java)|O(n)|O(h)|Easy| Recursion
|19|[Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/)|[Solution](../master/src/main/java/com/stevesun/solutions/_19.java)|O(n)|O(1)|Medium| Linked List
|17|[Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)|[Solution](../master/src/main/java/com/stevesun/solutions/LetterCombinationsofaPhoneNumber.java)|O(n*4^n)|O(n)|Medium|Backtracking
|14|[Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/)|[Solution](../master/src/main/java/com/stevesun/solutions/LongestCommonPrefix.java)| O(n*min(wordLength in this array)) | O(1) | Easy
418
-
|13|[Roman to Integer](https://leetcode.com/problems/roman-to-integer)|[Solution](../master/src/main/java/com/stevesun/solutions/RomantoInteger.java)| O(1) | O(1) | Easy
418
+
|13|[Roman to Integer](https://leetcode.com/problems/roman-to-integer)|[Solution](../master/src/main/java/com/stevesun/solutions/_13.java)| O(1) | O(1) | Easy
419
419
|12|[Integer to Roman](https://leetcode.com/problems/integer-to-roman/)|[Solution](../master/src/main/java/com/stevesun/solutions/IntegertoRoman.java)|O(1)|O(1)|Medium|
420
420
|11|[Container With Most Water](https://leetcode.com/problems/container-with-most-water/)|[Solution](../master/src/main/java/com/stevesun/solutions/ContainerWithMostWater.java)|O(n)|O(1)|Medium|
|8|[String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/)|[Solution](../master/src/main/java/com/stevesun/solutions/StringToInteger.java)| O(n) | O(1) | Easy
423
+
|8|[String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/)|[Solution](../master/src/main/java/com/stevesun/solutions/_8.java)| O(n) | O(1) | Medium
* Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.
8
+
9
+
get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1.
10
+
put(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item.
11
+
12
+
Follow up:
13
+
Could you do both operations in O(1) time complexity?
14
+
15
+
Example:
16
+
17
+
LRUCache cache = new LRUCache(2);//capacity
18
+
19
+
cache.put(1, 1);
20
+
cache.put(2, 2);
21
+
cache.get(1); // returns 1
22
+
cache.put(3, 3); // evicts key 2
23
+
cache.get(2); // returns -1 (not found)
24
+
cache.put(4, 4); // evicts key 1
25
+
cache.get(1); // returns -1 (not found)
26
+
cache.get(3); // returns 3
27
+
cache.get(4); // returns 4
28
+
*/
29
+
30
+
/**
31
+
* The shortest implementation is to use LinkedHashMap:
32
+
* specify a size of the linkedHashMap;
33
+
* override the removeEldestEntry method when its size exceeds max size: https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html#removeEldestEntry-java.util.Map.Entry-
34
+
* in the constructor, set the last boolean variable to be true: it means the ordering mode, if we set it to be true, it means
35
+
* in access order, false, means it's in insertion order: https://docs.oracle.com/javase/8/docs/api/java/util/LinkedHashMap.html#LinkedHashMap-int-float-boolean-*/
0 commit comments