Skip to content

Latest commit

 

History

History
479 lines (457 loc) · 103 KB

README.md

File metadata and controls

479 lines (457 loc) · 103 KB

LeetCode Java Practices

LeetCode练习记录,JDK版本是11

可以通过题目名称的大驼峰来搜索,也可以通过题号来搜索,大体思路一般会在commit message里面,详细的思路一般会在注释中

项目拉下来直接导入IntelliJ IDEA就可以了,每道题都可以单独运行,已经带了一部分常见的测试用例

另外如果你也用IDEA刷题的话,推荐一下这个插件 ,非常好用

我的习惯配置如下:

PS:插件查看题目会连tag一起展示出来,这其实是个不小的提示,可以考虑不用这个插件功能

关于TempFilePath,对于我的包com.oddcc.leetcode.editor.cn来说,路径应该是/Users/oddcc/Documents/Study/LeetCode/leetcode-practice/src/main/java/com/oddcc,即从leetcode开始,后面是插件默认的包结构。这里应该根据个人需要进行修改

CodeFileName: $!velocityTool.camelCaseName(${question.title})

CodeTemplate:

// ${question.frontendQuestionId}&&${question.titleSlug}

package com.oddcc.leetcode.editor.cn;
public class $!velocityTool.camelCaseName(${question.title}) {
    public static void main(String[] args) {
        Solution solution = new $!velocityTool.camelCaseName(${question.title})().new Solution();
    }
    ${question.code}
}

PS:

推荐一些工具,方便做题的时候理解

图相关:

  1. graph_editor , 可以根据“边”来构造图,有向图无向图都可以,在测试用例太大,你自己画不出来的时候可以用这个,方便找问题
  2. graphonline.ru ,除了手画之外,构造图不是很方便,但内置了多种算法演示,如果你能把图画出来,在上面演示非常方便,不理解算法中某一步的时候用

目前已有428道题,不断添加中…

ID 标题 难度 CODE
2 Add Two Numbers ⭐⭐ click
3 Longest Substring Without Repeating Characters ⭐⭐ click
5 Longest Palindromic Substring ⭐⭐ click
6 Zigzag Conversion ⭐⭐ click
7 Reverse Integer ⭐⭐ click
8 String to Integer (atoi) ⭐⭐ click
12 Integer to Roman ⭐⭐ click
13 Roman to Integer click
15 3Sum ⭐⭐ click
17 Letter Combinations of a Phone Number ⭐⭐ click
18 4Sum ⭐⭐ click
19 Remove Nth Node From End of List ⭐⭐ click
21 Merge Two Sorted Lists click
22 Generate Parentheses ⭐⭐ click
24 Swap Nodes in Pairs ⭐⭐ click
26 Remove Duplicates from Sorted Array click
27 Remove Element click
28 Find the Index of the First Occurrence in a String click
30 Substring with Concatenation of All Words ⭐⭐⭐ click
31 Next Permutation ⭐⭐ click
33 Search in Rotated Sorted Array ⭐⭐ click
34 Find First and Last Position of Element in Sorted Array ⭐⭐ click
35 Search Insert Position click
36 Valid Sudoku ⭐⭐ click
38 Count and Say ⭐⭐ click
39 Combination Sum ⭐⭐ click
40 Combination Sum II ⭐⭐ click
41 First Missing Positive ⭐⭐⭐ click
42 Trapping Rain Water ⭐⭐⭐ click
45 Jump Game II ⭐⭐ click
46 Permutations ⭐⭐ click
48 Rotate Image ⭐⭐ click
49 Group Anagrams ⭐⭐ click
53 Maximum Subarray ⭐⭐ click
54 Spiral Matrix ⭐⭐ click
55 Jump Game ⭐⭐ click
56 Merge Intervals ⭐⭐ click
58 Length of Last Word click
59 Spiral Matrix II ⭐⭐ click
61 Rotate List ⭐⭐ click
62 Unique Paths ⭐⭐ click
64 Minimum Path Sum ⭐⭐ click
65 Valid Number ⭐⭐⭐ click
66 Plus One click
67 Add Binary click
68 Text Justification ⭐⭐⭐ click
69 Sqrt(x) click
70 Climbing Stairs click
71 Simplify Path ⭐⭐ click
73 Set Matrix Zeroes ⭐⭐ click
74 Search a 2D Matrix ⭐⭐ click
75 Sort Colors ⭐⭐ click
78 Subsets ⭐⭐ click
79 Word Search ⭐⭐ click
80 Remove Duplicates from Sorted Array II ⭐⭐ click
81 Search in Rotated Sorted Array II ⭐⭐ click
82 Remove Duplicates from Sorted List II ⭐⭐ click
83 Remove Duplicates from Sorted List click
84 Largest Rectangle in Histogram ⭐⭐⭐ click
87 Scramble String ⭐⭐⭐ click
88 Merge Sorted Array click
89 Gray Code ⭐⭐ click
90 Subsets II ⭐⭐ click
91 Decode Ways ⭐⭐ click
92 Reverse Linked List II ⭐⭐ click
94 Binary Tree Inorder Traversal click
96 Unique Binary Search Trees ⭐⭐ click
97 Interleaving String ⭐⭐ click
98 Validate Binary Search Tree ⭐⭐ click
99 Recover Binary Search Tree ⭐⭐ click
100 Same Tree click
101 Symmetric Tree click
102 Binary Tree Level Order Traversal ⭐⭐ click
103 Binary Tree Zigzag Level Order Traversal ⭐⭐ click
104 Maximum Depth of Binary Tree click
107 Binary Tree Level Order Traversal II ⭐⭐ click
108 Convert Sorted Array to Binary Search Tree click
110 Balanced Binary Tree click
111 Minimum Depth of Binary Tree click
112 Path Sum click
113 Path Sum II ⭐⭐ click
114 Flatten Binary Tree to Linked List ⭐⭐ click
115 Distinct Subsequences ⭐⭐⭐ click
116 Populating Next Right Pointers in Each Node ⭐⭐ click
117 Populating Next Right Pointers in Each Node II ⭐⭐ click
118 Pascal's Triangle click
119 Pascal's Triangle II click
121 Best Time to Buy and Sell Stock click
121 Best Time to Buy and Sell Stock click
125 Valid Palindrome click
127 Word Ladder ⭐⭐⭐ click
129 Sum Root to Leaf Numbers ⭐⭐ click
131 Palindrome Partitioning ⭐⭐ click
132 Palindrome Partitioning II ⭐⭐⭐ click
134 Gas Station ⭐⭐ click
135 Candy ⭐⭐⭐ click
136 Single Number click
137 Single Number II ⭐⭐ click
138 Copy List with Random Pointer ⭐⭐ click
139 Word Break ⭐⭐ click
141 Linked List Cycle click
142 Linked List Cycle II ⭐⭐ click
143 Reorder List ⭐⭐ click
144 Binary Tree Preorder Traversal click
145 Binary Tree Postorder Traversal click
146 LRU Cache ⭐⭐ click
147 Insertion Sort List ⭐⭐ click
148 Sort List ⭐⭐ click
150 Evaluate Reverse Polish Notation ⭐⭐ click
152 Maximum Product Subarray ⭐⭐ click
153 Find Minimum in Rotated Sorted Array ⭐⭐ click
154 Find Minimum in Rotated Sorted Array II ⭐⭐⭐ click
160 Intersection of Two Linked Lists click
164 Maximum Gap ⭐⭐ click
167 Two Sum II - Input Array Is Sorted ⭐⭐ click
168 Excel Sheet Column Title click
169 Majority Element click
171 Excel Sheet Column Number click
172 Factorial Trailing Zeroes ⭐⭐ click
173 Binary Search Tree Iterator ⭐⭐ click
179 Largest Number ⭐⭐ click
189 Rotate Array ⭐⭐ click
190 Reverse Bits click
191 Number of 1 Bits click
198 House Robber ⭐⭐ click
200 Number of Islands ⭐⭐ click
202 Happy Number click
203 Remove Linked List Elements click
204 Count Primes ⭐⭐ click
205 Isomorphic Strings click
207 Course Schedule ⭐⭐ click
208 Implement Trie (Prefix Tree) ⭐⭐ click
209 Minimum Size Subarray Sum ⭐⭐ click
213 House Robber II ⭐⭐ click
215 Kth Largest Element in an Array ⭐⭐ click
217 Contains Duplicate click
219 Contains Duplicate II click
220 Contains Duplicate III ⭐⭐⭐ click
221 Maximal Square ⭐⭐ click
222 Count Complete Tree Nodes click
224 Basic Calculator ⭐⭐⭐ click
225 Implement Stack using Queues click
226 Invert Binary Tree click
227 Basic Calculator II ⭐⭐ click
228 Summary Ranges click
231 Power of Two click
232 Implement Queue using Stacks click
234 Palindrome Linked List click
235 Lowest Common Ancestor of a Binary Search Tree ⭐⭐ click
236 Lowest Common Ancestor of a Binary Tree ⭐⭐ click
237 Delete Node in a Linked List ⭐⭐ click
238 Product of Array Except Self ⭐⭐ click
240 Search a 2D Matrix II ⭐⭐ click
242 Valid Anagram click
257 Binary Tree Paths click
263 Ugly Number click
264 Ugly Number II ⭐⭐ click
268 Missing Number click
278 First Bad Version click
279 Perfect Squares ⭐⭐ click
283 Move Zeroes click
287 Find the Duplicate Number ⭐⭐ click
290 Word Pattern click
300 Longest Increasing Subsequence ⭐⭐ click
303 Range Sum Query - Immutable click
304 Range Sum Query 2D - Immutable ⭐⭐ click
309 Best Time to Buy and Sell Stock with Cooldown ⭐⭐ click
316 Remove Duplicate Letters ⭐⭐ click
322 Coin Change ⭐⭐ click
328 Odd Even Linked List ⭐⭐ click
331 Verify Preorder Serialization of a Binary Tree ⭐⭐ click
337 House Robber III ⭐⭐ click
338 Counting Bits click
341 Flatten Nested List Iterator ⭐⭐ click
342 Power of Four click
343 Integer Break ⭐⭐ click
344 Reverse String click
347 Top K Frequent Elements ⭐⭐ click
349 Intersection of Two Arrays click
350 Intersection of Two Arrays II click
354 Russian Doll Envelopes ⭐⭐⭐ click
363 Max Sum of Rectangle No Larger Than K ⭐⭐⭐ click
368 Largest Divisible Subset ⭐⭐ click
377 Combination Sum IV ⭐⭐ click
387 First Unique Character in a String click
394 Decode String ⭐⭐ click
395 Longest Substring with At Least K Repeating Characters ⭐⭐ click
396 Rotate Function ⭐⭐ click
398 Random Pick Index ⭐⭐ click
399 Evaluate Division ⭐⭐ click
401 Binary Watch click
403 Frog Jump ⭐⭐⭐ click
406 Queue Reconstruction by Height ⭐⭐ click
409 Longest Palindrome click
415 Add Strings click
416 Partition Equal Subset Sum ⭐⭐ click
421 Maximum XOR of Two Numbers in an Array ⭐⭐ click
424 Longest Repeating Character Replacement ⭐⭐ click
430 Flatten a Multilevel Doubly Linked List ⭐⭐ click
435 Non-overlapping Intervals ⭐⭐ click
437 Path Sum III ⭐⭐ click
438 Find All Anagrams in a String ⭐⭐ click
448 Find All Numbers Disappeared in an Array click
451 Sort Characters By Frequency ⭐⭐ click
452 Minimum Number of Arrows to Burst Balloons ⭐⭐ click
454 4Sum II ⭐⭐ click
455 Assign Cookies click
456 132 Pattern ⭐⭐ click
461 Hamming Distance click
463 Island Perimeter click
474 Ones and Zeroes ⭐⭐ click
477 Total Hamming Distance ⭐⭐ click
480 Sliding Window Median ⭐⭐⭐ click
485 Max Consecutive Ones click
494 Target Sum ⭐⭐ click
496 Next Greater Element I click
502 IPO ⭐⭐⭐ click
503 Next Greater Element II ⭐⭐ click
509 Fibonacci Number click
518 Coin Change II ⭐⭐ click
523 Continuous Subarray Sum ⭐⭐ click
525 Contiguous Array ⭐⭐ click
530 Minimum Absolute Difference in BST click
538 Convert BST to Greater Tree ⭐⭐ click
543 Diameter of Binary Tree click
547 Number of Provinces ⭐⭐ click
554 Brick Wall ⭐⭐ click
560 Subarray Sum Equals K ⭐⭐ click
561 Array Partition click
566 Reshape the Matrix click
567 Permutation in String ⭐⭐ click
575 Distribute Candies click
581 Shortest Unsorted Continuous Subarray ⭐⭐ click
599 Minimum Index Sum of Two Lists click
605 Can Place Flowers click
606 Construct String from Binary Tree ⭐⭐ click
611 Valid Triangle Number ⭐⭐ click
617 Merge Two Binary Trees click
621 Task Scheduler ⭐⭐ click
622 Design Circular Queue ⭐⭐ click
623 Add One Row to Tree ⭐⭐ click
628 Maximum Product of Three Numbers click
633 Sum of Square Numbers ⭐⭐ click
636 Exclusive Time of Functions ⭐⭐ click
639 Decode Ways II ⭐⭐⭐ click
640 Solve the Equation ⭐⭐ click
643 Maximum Average Subarray I click
645 Set Mismatch click
646 Maximum Length of Pair Chain ⭐⭐ click
647 Palindromic Substrings ⭐⭐ click
652 Find Duplicate Subtrees ⭐⭐ click
664 Strange Printer ⭐⭐⭐ click
665 Non-decreasing Array ⭐⭐ click
674 Longest Continuous Increasing Subsequence click
680 Valid Palindrome II click
684 Redundant Connection ⭐⭐ click
687 Longest Univalue Path ⭐⭐ click
690 Employee Importance ⭐⭐ click
692 Top K Frequent Words ⭐⭐ click
695 Max Area of Island ⭐⭐ click
697 Degree of an Array click
701 Insert into a Binary Search Tree ⭐⭐ click
703 Kth Largest Element in a Stream click
704 Binary Search click
705 Design HashSet click
706 Design HashMap click
709 To Lower Case click
713 Subarray Product Less Than K ⭐⭐ click
714 Best Time to Buy and Sell Stock with Transaction Fee ⭐⭐ click
718 Maximum Length of Repeated Subarray ⭐⭐ click
721 Accounts Merge ⭐⭐ click
724 Find Pivot Index click
738 Monotone Increasing Digits ⭐⭐ click
739 Daily Temperatures ⭐⭐ click
740 Delete and Earn ⭐⭐ click
746 Min Cost Climbing Stairs click
752 Open the Lock ⭐⭐ click
763 Partition Labels ⭐⭐ click
765 Couples Holding Hands ⭐⭐⭐ click
766 Toeplitz Matrix click
767 Reorganize String ⭐⭐ click
771 Jewels and Stones click
781 Rabbits in Forest ⭐⭐ click
783 Minimum Distance Between BST Nodes click
817 Linked List Components ⭐⭐ click
830 Positions of Large Groups click
832 Flipping an Image click
844 Backspace String Compare click
845 Longest Mountain in Array ⭐⭐ click
852 Peak Index in a Mountain Array ⭐⭐ click
856 Score of Parentheses ⭐⭐ click
860 Lemonade Change click
867 Transpose Matrix click
868 Binary Gap click
872 Leaf-Similar Trees click
877 Stone Game ⭐⭐ click
883 Projection Area of 3D Shapes click
888 Fair Candy Swap click
896 Monotonic Array click
897 Increasing Order Search Tree click
899 Orderly Queue ⭐⭐⭐ click
918 Maximum Sum Circular Subarray ⭐⭐ click
922 Sort Array By Parity II click
923 3Sum With Multiplicity ⭐⭐ click
925 Long Pressed Name click
930 Binary Subarrays With Sum ⭐⭐ click
938 Range Sum of BST click
941 Valid Mountain Array click
951 Flip Equivalent Binary Trees ⭐⭐ click
959 Regions Cut By Slashes ⭐⭐ click
973 K Closest Points to Origin ⭐⭐ click
977 Squares of a Sorted Array click
978 Longest Turbulent Subarray ⭐⭐ click
981 Time Based Key-Value Store ⭐⭐ click
989 Add to Array-Form of Integer click
992 Subarrays with K Different Integers ⭐⭐⭐ click
993 Cousins in Binary Tree click
995 Minimum Number of K Consecutive Bit Flips ⭐⭐⭐ click
1002 Find Common Characters click
1004 Max Consecutive Ones III ⭐⭐ click
1006 Clumsy Factorial ⭐⭐ click
1011 Capacity To Ship Packages Within D Days ⭐⭐ click
1018 Binary Prefix Divisible By 5 click
1030 Matrix Cells in Distance Order click
1035 Uncrossed Lines ⭐⭐ click
1046 Last Stone Weight click
1047 Remove All Adjacent Duplicates In String click
1049 Last Stone Weight II ⭐⭐ click
1052 Grumpy Bookstore Owner ⭐⭐ click
1074 Number of Submatrices That Sum to Target ⭐⭐⭐ click
1122 Relative Sort Array click
1128 Number of Equivalent Domino Pairs click
1137 N-th Tribonacci Number click
1143 Longest Common Subsequence ⭐⭐ click
1178 Number of Valid Words for Each Puzzle ⭐⭐⭐ click
1190 Reverse Substrings Between Each Pair of Parentheses ⭐⭐ click
1202 Smallest String With Swaps ⭐⭐ click
1207 Unique Number of Occurrences click
1208 Get Equal Substrings Within Budget ⭐⭐ click
1221 Split a String in Balanced Strings click
1232 Check If It Is a Straight Line click
1239 Maximum Length of a Concatenated String with Unique Characters ⭐⭐ click
1269 Number of Ways to Stay in the Same Place After Some Steps ⭐⭐⭐ click
1277 Count Square Submatrices with All Ones ⭐⭐ click
1310 XOR Queries of a Subarray ⭐⭐ click
1356 Sort Integers by The Number of 1 Bits click
1365 How Many Numbers Are Smaller Than the Current Number click
1370 Increasing Decreasing String click
1403 Minimum Subsequence in Non-Increasing Order click
1408 String Matching in an Array click
1413 Minimum Value to Get Positive Step by Step Sum click
1417 Reformat The String click
1418 Display Table of Food Orders in a Restaurant ⭐⭐ click
1423 Maximum Points You Can Obtain from Cards ⭐⭐ click
1438 Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit ⭐⭐ click
1442 Count Triplets That Can Form Two Arrays of Equal XOR ⭐⭐ click
1473 Paint House III ⭐⭐⭐ click
1475 Final Prices With a Special Discount in a Shop click
1482 Minimum Number of Days to Make m Bouquets ⭐⭐ click
1486 XOR Operation in an Array click
1582 Special Positions in a Binary Matrix click
1592 Rearrange Spaces Between Words click
1600 Throne Inheritance ⭐⭐ click
1603 Design Parking System click
1614 Maximum Nesting Depth of the Parentheses click
1629 Slowest Key click
1631 Path With Minimum Effort ⭐⭐ click
1694 Reformat Phone Number click
1707 Maximum XOR With an Element From Array ⭐⭐⭐ click
1711 Count Good Meals ⭐⭐ click
1720 Decode XORed Array click
1723 Find Minimum Time to Finish All Jobs ⭐⭐⭐ click
1734 Decode XORed Permutation ⭐⭐ click
1736 Latest Time by Replacing Hidden Digits click
1738 Find Kth Largest XOR Coordinate Value ⭐⭐ click
1744 Can You Eat Your Favorite Candy on Your Favorite Day? ⭐⭐ click
1758 Minimum Changes To Make Alternating Binary String click
1780 Check if Number is a Sum of Powers of Three ⭐⭐ click
1781 Sum of Beauty of All Substrings ⭐⭐ click
1790 Check if One String Swap Can Make Strings Equal click
1800 Maximum Ascending Subarray Sum click
1822 Sign of the Product of an Array click
1823 Find the Winner of the Circular Game ⭐⭐ click
1827 Minimum Operations to Make the Array Increasing click
1832 Check if the Sentence Is Pangram click
1833 Maximum Ice Cream Bars ⭐⭐ click
1877 Minimize Maximum Pair Sum in Array ⭐⭐ click
1893 Check if All the Integers in a Range Are Covered click
1894 Find the Student that Will Replace the Chalk ⭐⭐ click
2038 Remove Colored Pieces if Both Neighbors are the Same Color ⭐⭐ click
2043 Simple Bank System ⭐⭐ click
2044 Count Number of Maximum Bitwise-OR Subsets ⭐⭐ click
LCP 07 传递信息 click
LCR 007 三数之和 ⭐⭐ click
LCR 120 寻找文件副本 click
LCR 121 寻找目标值 - 二维数组 ⭐⭐ click
LCR 122 路径加密 click
LCR 123 图书整理 I click
LCR 124 推理二叉树 ⭐⭐ click
LCR 125 图书整理 II click
LCR 126 斐波那契数 click
LCR 127 跳跃训练 click
LCR 128 库存管理 I click
LCR 129 字母迷宫 ⭐⭐ click
LCR 130 衣橱整理 ⭐⭐ click
LCR 131 砍竹子 I ⭐⭐ click
LCR 132 砍竹子 II ⭐⭐ click
LCR 133 位 1 的个数 click
LCR 135 报数 click
LCR 136 删除链表的节点 click
LCR 139 训练计划 I click
LCR 140 训练计划 II click
LCR 141 训练计划 III click
LCR 156 序列化与反序列化二叉树 ⭐⭐⭐ click
LCR 157 套餐内商品的排列顺序 ⭐⭐ click
LCR 161 连续天数的最高销售额 click
LCR 171 训练计划 V click
LCR 172 统计目标成绩的出现次数 click
面试题 01.01 Is Unique LCCI click
面试题 01.02 Check Permutation LCCI click
面试题 01.03 String to URL LCCI click
面试题 01.04 Palindrome Permutation LCCI click
面试题 01.05 One Away LCCI ⭐⭐ click
面试题 01.06 Compress String LCCI click
面试题 01.08 Zero Matrix LCCI ⭐⭐ click
面试题 01.09 String Rotation LCCI click
面试题 17.10 Find Majority Element LCCI click
面试题 17.21 Volume of Histogram LCCI ⭐⭐⭐ click