Skip to content

Commit 2701166

Browse files
author
liwentian
committed
fd
1 parent 974245e commit 2701166

29 files changed

+2270
-210
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Tree](https://github.com/dingjikerbo/leetcode/blob/master/ebook/tree/leetcode-tree.pdf)
88
- [DP](https://github.com/dingjikerbo/leetcode/blob/master/ebook/dp/leetcode-dp.pdf)
99
- [Array](https://github.com/dingjikerbo/leetcode/blob/master/ebook/array/leetcode-array.pdf)
10+
- [List](https://github.com/dingjikerbo/leetcode/blob/master/ebook/list/leetcode-list.pdf)
1011

1112
<br/><br/>
1213

@@ -270,6 +271,7 @@
270271
|298|[Binary Tree Longest Consecutive Sequence](https://leetcode.com/problems/binary-tree-longest-consecutive-sequence/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/BinaryTreeLongestConsecutiveSequence.java)|70|多做三遍,尽可能简洁|
271272
|300|[Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/LongestIncreasingSubsequence.java)||
272273
|301|[Remove Invalid Parentheses](https://leetcode.com/problems/remove-invalid-parentheses/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/RemoveInvalidParentheses.java)|70|比较难,多做几遍|
274+
|302|[Smallest Rectangle Enclosing Black Pixels](https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/SmallestRectangleEnclosingBlackPixels.java)|||
273275
|303|[Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/NumArray.java)|100|
274276
|304|[Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/NumMatrix.java)|65|
275277
|305|[Number of Islands II](https://leetcode.com/problems/number-of-islands-ii/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/NumberOfIslandsII.java)|70|这题多做几遍,经典的UF|
@@ -279,6 +281,7 @@
279281
|310|[Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/MinimumHeightTrees.java)|60|这题多做几遍|
280282
|311|[Sparse Matrix Multiplication](https://leetcode.com/problems/sparse-matrix-multiplication/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/SparseMatrixMultiplication.java)|80|
281283
|312|[Burst Balloons](https://leetcode.com/problems/burst-balloons/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/BurstBalloons.java)|60|
284+
|313|[Super Ugly Number](https://leetcode.com/problems/super-ugly-number/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/SuperUglyNumber.java)|||
282285
|314|[Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/BinaryTreeVerticalOrderTraversal.java)|80|
283286
|315|[Count of Smaller Numbers After Self](https://leetcode.com/problems/count-of-smaller-numbers-after-self/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/CountOfSmallerNumbersAfterSelf.java)|60|
284287
|316|[Remove Duplicate Letters](https://leetcode.com/problems/remove-duplicate-letters/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/RemoveDuplicateLetters.java)|70|
@@ -302,18 +305,23 @@
302305
|345|[Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/ReverseVowelsOfaString.java)|100||
303306
|346|[Moving Average from Data Stream](https://leetcode.com/problems/moving-average-from-data-stream/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/MovingAverage.java)|95|
304307
|347|[Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/TopKFrequentElements.java)|85|
308+
|349|[Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/IntersectionOfTwoArrays.java)|||
309+
|350|[Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/IntersectionOfTwoArraysII.java)|||
305310
|351|[Android Unlock Patterns](https://leetcode.com/problems/android-unlock-patterns/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/AndroidUnlockPatterns.java)|70|这题多做几遍|
306311
|357|[Count Numbers with Unique Digits](https://leetcode.com/problems/count-numbers-with-unique-digits/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/CountNumberWithUniqueDigits.java)||
307312
|358|[Rearrange String k Distance Apart](https://leetcode.com/problems/rearrange-string-k-distance-apart/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/RearrangeStringKDistanceApart.java)||
308313
|359|[Logger Rate Limiter](https://leetcode.com/problems/logger-rate-limiter/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/LoggerRateLimiter.java)|100|这题如果不考虑空间消耗的话其实很简单|
309314
|361|[Bomb Enemy](https://leetcode.com/problems/bomb-enemy/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/BombEnemy.java)|65|这题多做几遍,开始没思路|
310315
|364|[Nested List Weight Sum II](https://leetcode.com/problems/nested-list-weight-sum-ii/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/NestedListWeightSumII.java)||
311316
|366|[Find Leaves of Binary Tree](https://leetcode.com/problems/find-leaves-of-binary-tree/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/FindLeavesOfBinaryTree.java)|60|这道题刚开始还没思路|
317+
|367|[Valid Perfect Square](https://leetcode.com/problems/valid-perfect-square)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/ValidPerfectSquare.java)|||
312318
|369|[Plus One Linked List](https://leetcode.com/problems/plus-one-linked-list/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/PlusOneLinkedList.java)|100||
313319
|370|[Range Addition](https://leetcode.com/problems/range-addition/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/RangeAddition.java)|80||
320+
|373|[Find K Pairs with Smallest Sums](https://leetcode.com/problems/find-k-pairs-with-smallest-sums/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/FindKPairsWithSmallestSums.java)|||
314321
|374|[Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/GuessNumberHigherOrLower.java)|100|
315322
|375|[Guess Number Higher or Lower II](https://leetcode.com/problems/guess-number-higher-or-lower-ii/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/GuessNumberHigherOrLowerII.java)|60|
316323
|377|[Combination Sum IV](https://leetcode.com/problems/combination-sum-iv/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/combinationSum4.java)|65|
324+
|378|[Kth Smallest Element in a Sorted Matrix](https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/KthSmallestElementInASortedMatrix.java)|||
317325
|380|[Insert Delete GetRandom O(1)](https://leetcode.com/problems/insert-delete-getrandom-o1/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/RandomizedSet.java)|75|这道题很有意思,多做几遍|
318326
|381|[Insert Delete GetRandom O(1) - Duplicates allowed](https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/RandomizedCollection.java)||
319327
|382|[Linked List Random Node](https://leetcode.com/problems/linked-list-random-node/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/LinkedListRandomNode.java)||
@@ -338,16 +346,19 @@
338346
|418|[Sentence Screen Fitting](https://leetcode.com/problems/sentence-screen-fitting/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/SentenceScreenFitting.java)|65|这题思路巧妙,多做几遍,常规思路超时|
339347
|422|[Valid Word Square](https://leetcode.com/problems/valid-word-square/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/ValidWordSquare.java)|90|
340348
|425|[Word Squares](https://leetcode.com/problems/word-squares/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/WordSquare.java)|70|这题很典型,多做几遍|
349+
|436|[Find Right Interval](https://leetcode.com/problems/find-right-interval/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/FindRightInterval.java)|||
341350
|437|[Path Sum III](https://leetcode.com/problems/path-sum-iii/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/PathSumIII.java)|60|这道题错了很多遍,要重点关注|
342351
|438|[Find All Anagrams in a String](https://leetcode.com/problems/find-all-anagrams-in-a-string/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/FindAllAnagramsInString.java)|75|这道题非常经典,最优解法需要多做几遍,保证once bug free|
343352
|442|[Find All Duplicates in an Array](https://leetcode.com/problems/find-all-duplicates-in-an-array/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/FindAllDuplicatesInAnArray.java)|80||
344353
|445|[Add Two Numbers II](https://leetcode.com/problems/add-two-numbers-ii/discuss/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/AddTwoNumbersII.java)|80||
345354
|448|[Find All Numbers Disappeared in an Array](https://leetcode.com/problems/find-all-numbers-disappeared-in-an-array)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/FindAllNumbersDisappearedInAnArray.java)|80||
346355
|449|[Serialize and Deserialize BST](https://leetcode.com/problems/serialize-and-deserialize-bst)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/SerializeAndDeserializeBST.java)|90|#297一样|
347356
|450|[Delete Node in a BST](https://leetcode.com/problems/delete-node-in-a-bst/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/DeleteNodeInBST.java)|60|这题非常经典,值得多做十遍|
357+
|451|[Sort Characters By Frequency](https://leetcode.com/problems/sort-characters-by-frequency/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/SortCharactersByFrequency.java)|||
348358
|477|[Total Hamming Distance](https://leetcode.com/problems/total-hamming-distance/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/TotalHammingDistance.java)||
349359
|480|[Sliding Window Median](https://leetcode.com/problems/sliding-window-median/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/SlidingWindowMedian.java)|70||
350360
|482|[License Key Formatting](https://leetcode.com/problems/license-key-formatting/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/LicenseKeyFormatting.java)|90||
361+
|483|[Smallest Good Base](https://leetcode.com/problems/smallest-good-base/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/SmallestGoodBase.java)|||
351362
|485|[Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/MaxConsecutiveOnes.java)|100||
352363
|487|[Max Consecutive Ones II](https://leetcode.com/problems/max-consecutive-ones-ii/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/MaxConsecutiveOnesII.java)|80||
353364
|501|[Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree/)| [Java](https://github.com/dingjikerbo/leetcode/blob/master/solution/src/main/java/com/inuker/solution/FindModeInBinarySearchTree.java)|70|不难,容易错,多做两次|

ebook/array/Array.tex

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -461,54 +461,6 @@ \subsubsection{Solution}
461461

462462
\newpage
463463

464-
\section{Plus One Linked List} %%%%%%%%%%%%%%%%%%%%%%


465-
466-
\subsubsection{Description}
467-
Given a non-negative integer represented as non-empty a singly linked list of digits, plus one to the integer.
468-
469-
You may assume the integer do not contain any leading zero, except the number 0 itself.
470-
471-
The digits are stored such that the most significant digit is at the head of the list.
472-
473-
\textbf{Example:}
474-
475-
\textbf{Input:}
476-
477-
1->2->3
478-
479-
\textbf{Output:}
480-
481-
1->2->4
482-
483-
\subsubsection{Solution}
484-
485-
\begin{Code}
486-
public ListNode plusOne(ListNode head) {
487-
if (head == null) {
488-
return head;
489-
}
490-
Stack<ListNode> stack = new Stack<ListNode>();
491-
for (ListNode node = head; node != null; node = node.next) {
492-
stack.push(node);
493-
}
494-
int k = 1;
495-
while (!stack.isEmpty()) {
496-
ListNode node = stack.pop();
497-
int val = node.val + k;
498-
node.val = val % 10;
499-
k = val / 10;
500-
if (k == 0) {
501-
return head;
502-
}
503-
}
504-
ListNode node = new ListNode(k);
505-
node.next = head;
506-
return node;
507-
}
508-
\end{Code}
509-
510-
\newpage
511-
512464
\section{Container With Most Water} %%%%%%%%%%%%%%%%%%%%%%


513465

514466
\subsubsection{Description}
@@ -1184,35 +1136,6 @@ \subsubsection{Solution}
11841136

11851137
\newpage
11861138

1187-
\section{Merge Two Sorted Lists} %%%%%%%%%%%%%%%%%%%%%%


1188-
1189-
\subsubsection{Description}
1190-
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
1191-
1192-
\subsubsection{Solution}
1193-
1194-
\begin{Code}
1195-
// 耗时15ms
1196-
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
1197-
ListNode dummy = new ListNode(0);
1198-
ListNode p = l1, q = l2, cur = dummy;
1199-
for ( ; p != null && q != null; ) {
1200-
if (p.val < q.val) {
1201-
cur.next = p;
1202-
p = p.next;
1203-
} else {
1204-
cur.next = q;
1205-
q = q.next;
1206-
}
1207-
cur = cur.next;
1208-
}
1209-
cur.next = p != null ? p : q;
1210-
return dummy.next;
1211-
}
1212-
\end{Code}
1213-
1214-
\newpage
1215-
12161139
\section{Rotate Image} %%%%%%%%%%%%%%%%%%%%%%


12171140

12181141
\subsubsection{Description}

ebook/backtracking/Backtracking.tex

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,32 +1761,6 @@ \subsubsection{Solution}
17611761

17621762
\newpage
17631763

1764-
\section{Count Numbers with Unique Digits} %%%%%%%%%%%%%%%%%%%%%%
1765-
1766-
\subsubsection{Description}
1767-
1768-
Given a non-negative integer n, count all numbers with unique digits, \code{x}, where 0 <= x < 10n.
1769-
1770-
\textbf{Example:}
1771-
1772-
Given n = 2, return 91. (The answer should be the total numbers in the range of 0 <= x < 100, excluding \code{[11,22,33,44,55,66,77,88,99]})
1773-
1774-
\subsubsection{Solution}
1775-
1776-
\begin{Code}
1777-
public int countNumbersWithUniqueDigits(int n) {
1778-
int[] result = new int[n + 1];
1779-
result[0] = 1;
1780-
for (int i = 1, t = 9; i <= n; i++) {
1781-
result[i] = result[i - 1] + t;
1782-
t *= 10 - i;
1783-
}
1784-
return result[n];
1785-
}
1786-
\end{Code}
1787-
1788-
\newpage
1789-
17901764
\section{Generalized Abbreviation} %%%%%%%%%%%%%%%%%%%%%%
17911765

17921766
\subsubsection{Description}

ebook/dp/Dp.tex

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -910,56 +910,6 @@ \subsubsection{Solution}
910910

911911
\newpage
912912

913-
\section{Maximum Size Subarray Sum Equals k} %%%%%%%%%%%%%%%%%%%%%%


914-
915-
\subsubsection{Description}
916-
Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If there isn't one, return 0 instead.
917-
918-
\textbf{Note:}
919-
920-
The sum of the entire nums array is guaranteed to fit within the 32-bit signed integer range.
921-
922-
\textbf{Example 1:}
923-
924-
Given nums = [1, -1, 5, -2, 3], k = 3,
925-
return 4. (because the subarray [1, -1, 5, -2] sums to 3 and is the longest)
926-
927-
\textbf{Example 2:}
928-
929-
Given nums = [-2, -1, 2, 1], k = 1,
930-
return 2. (because the subarray [-1, 2] sums to 1 and is the longest)
931-
932-
\textbf{Follow Up:}
933-
934-
Can you do it in O(n) time?
935-
\subsubsection{Solution}
936-
937-
\begin{Code}
938-
// 耗时29ms,时间复杂度O(n)
939-
public int maxSubArrayLen2(int[] nums, int k) {
940-
HashMap<Integer, Integer> map = new HashMap<>();
941-
int maxLen = 0;
942-
943-
map.put(0, -1);
944-
945-
for (int i = 0, sum = 0; i < nums.length; i++) {
946-
sum += nums[i];
947-
if (!map.containsKey(sum)) {
948-
map.put(sum, i);
949-
}
950-
951-
int idx = map.getOrDefault(sum - k, -2);
952-
if (idx >= -1 && i - idx > maxLen) {
953-
maxLen = i - idx;
954-
}
955-
}
956-
957-
return maxLen;
958-
}
959-
\end{Code}
960-
961-
\newpage
962-
963913
\section{Unique Paths} %%%%%%%%%%%%%%%%%%%%%%


964914

965915
\subsubsection{Description}

0 commit comments

Comments
 (0)