My Java practice repository. It is a running log of what I have worked through while learning the language: small programs covering the basics, notes on the collections framework, and a growing pile of LeetCode solutions.
Nothing here is a library or a framework. Each file is self contained, has a
main with the example cases from the problem, and can be run on its own.
Java_DailyLearningPractice/ day to day language practice
LeetcodePractice/ one file per LeetCode problem
tools/build_index.py regenerates the index below
Java_DailyLearningPractice/ is the basics: syntax, loops, a calculator, and a
short tour of ArrayList, HashSet, HashMap, ArrayDeque, LinkedList and
PriorityQueue. A few classic problems (longest common prefix, longest
palindromic substring, Pascal's triangle) ended up here before I started the
LeetCode folder.
LeetcodePractice/ is everything else, indexed by topic below.
Both folders are packages, so compile from the repository root:
javac -d out LeetcodePractice/TwoSum.java
java -cp out LeetcodePractice.TwoSum
Or build everything at once:
javac -d out LeetcodePractice/*.java Java_DailyLearningPractice/*.java
240 solutions, grouped by the main technique each one uses.
Arrays | Strings | Hashing | Two pointers | Sliding window | Prefix sum | Stack and queue | Binary search | Sorting and greedy | Heap | Linked lists | Trees | Graphs, BFS and DFS | Backtracking | Dynamic programming | Math and bit manipulation | Design
| Problem | Solution |
|---|---|
| Anagram Checker | AnagramChecker.java |
| Are Almost Equal | AreAlmostEqual.java |
| Attendance Award | AttendanceAward.java |
| Balanced String | BalancedString.java |
| Balanced String Placed | BalancedStringPlaced.java |
| Binary String With at Most One Segment of Ones | CheckOnesSegment.java |
| Buddy Strings | BuddyStrings.java |
| Chessboard | Chessboard.java |
| Consecutive Char | ConsecutiveChar.java |
| Count Asterisks | CountAsterisks.java |
| Count Binary Substrings | CountBinarySubstrings.java |
| Coupon Validator | CouponValidator.java |
| Detect Capital | DetectCapital.java |
| Find the Difference | FindTheDifference.java |
| Find the Index of the First Occurrence in a String | FirstOccurence.java |
| Generate the String | GenerateTheString.java |
| Goat Latin | GoatLatin.java |
| Greatest Common Divisor of Strings | StringDivisor.java |
| Has Valid Substring | HasValidSubstring.java |
| Is Long Pressed Name | IsLongPressedName.java |
| Is Prefix String | IsPrefixString.java |
| Length of Last Word | LengthOfLastWord.java |
| License Key Formatting | LicenseKeyFormatting.java |
| Max Score Split | MaxScoreSplit.java |
| Max Vowel Consonant Frequency | MaxVowelConsonantFrequency.java |
| Minimum Moves to Convert String | MinimumMovesToConvertString.java |
| Number of Different Integers in a String | NumDifferenceInt.java |
| Number of Segments | NumberOfSegments.java |
| Occurrences After Bigram | OccurrencesAfterBigram.java |
| Rearrange Spaces | RearrangeSpaces.java |
| Reformat Phone Number | ReformatPhoneNumber.java |
| Reformat String | ReformatString.java |
| Remove Palindrome | RemovePalindrome.java |
| Reorder String | ReorderString.java |
| Repeated Substring Pattern | RepeatedSubstringPattern.java |
| Reverse Only Letters | ReverseOnlyLetters.java |
| Reverse Prefix | ReversePrefix.java |
| Reverse String II | ReverseStringII.java |
| Reverse Words | ReverseWords.java |
| Reverse Words in String | ReverseWordsInString.java |
| Second Highest | SecondHighest.java |
| Shortest Distance to Char | ShortestDistanceToChar.java |
| Shuffle String | ShuffleString.java |
| Sorting the Sentence | SortingTheSentence.java |
| String Compressor | StringCompressor.java |
| String Matching in Array | StringMatchingInArray.java |
| String Reverse | StringReverse.java |
| String Rotation Check | StringRotationCheck.java |
| Strong Password Checker | StrongPasswordChecker.java |
| Sum of Digits of String After Convert | GetLuck.java |
| Problem | Solution |
|---|---|
| 3Sum | ThreeSum.java |
| 3Sum Closest | ThreeSumCloset.java |
| Container with Most Water | ContainerWithMostWater.java |
| Merge Alternately | MergeAlternately.java |
| Merge Sorted Arrays | MergeSortedArrays.java |
| Min Deletion Size | MinDeletionSize.java |
| Remove Duplicates | RemoveDuplicates.java |
| Reverse Vowels | ReverseVowels.java |
| Subsequence Checker | SubsequenceChecker.java |
| Valid Palindrome | ValidPalindrome.java |
| Valid Palindrome II | ValidPalindromeII.java |
| Problem | Solution |
|---|---|
| K Beauty of Number | KBeautyOfNumber.java |
| Longest Subarray After Deleting One | LongestSubarrayAfterDeletingOne.java |
| Longest Substring Without Repeating Characters | LongestSubstringwithoutRepeating.java |
| Max Avg Sub Array | MaxAvgSubArray.java |
| Max Consecutive Ones III | MaxConsecutiveOnesIII.java |
| Max Vowels | MaxVowels.java |
| Permutation from String | PermutationFromString.java |
| Problem | Solution |
|---|---|
| Find Pivot Index | PivotIndexFinder.java |
| Highest Altitude | HighestAltitude.java |
| Product of Array Except Self | ProductOfArrayExceptSelf.java |
| Running Sum | RunningSum.java |
| Problem | Solution |
|---|---|
| Asteroid Collision | AsteroidCollision.java |
| Backspace | Backspace.java |
| Baseball Game | BaseballGame.java |
| Daily Temperatures | DailyTemperatures.java |
| Decode String | DecodeString.java |
| Dota2 Senate | DotaSenate.java |
| Make String Great | MakeStringGreat.java |
| Maximum Nesting Depth of the Parentheses | MaxDepth.java |
| Next Greater Element | NextGreaterElement.java |
| Remove All Adjacent Duplicates in String | RemoveDuplicatess.java |
| Remove Outer Parentheses | RemoveOuterParentheses.java |
| Remove Stars from String | RemoveStarsFromString.java |
| Stack (practice with the collection) | StackCollection.java |
| Valid Parentheses | ValidParanthesis.java |
| Problem | Solution |
|---|---|
| Binary Search | BinarySearch.java |
| Guess Game | GuessGame.java |
| Koko Eating Bananas | KokoEatingBananas.java |
| Median of Two Sorted Arrays | MedianOfTwoSortedArrays.java |
| Peak Element | PeakElement.java |
| Search Insert | SearchInsert.java |
| Search Range | SearchRange.java |
| Search Suggestion System | SearchSuggestionSystem.java |
| Square Root | SquareRoot.java |
| Successful Pairs | SuccessfulPairs.java |
| Problem | Solution |
|---|---|
| Assign Cookies | AssignCookies.java |
| Jump Game | JumpGame.java |
| Largest Num | LargestNum.java |
| Maximum Units on Truck | MaximumUnitsOnTruck.java |
| Minimum Arrows to Burst Balloons | MinimumArrowsToBurstBalloons.java |
| Non Overlapping Intervals | NonOverlappingIntervals.java |
| Relative Ranks | RelativeRanks.java |
| Triangle Perimeter | TrianglePerimeter.java |
| Problem | Solution |
|---|---|
| Hiring Workers | HiringWorkers.java |
| Kth Largest Element | KthLargestElement.java |
| Max Score Subsequence | MaxScoreSubsequence.java |
| Problem | Solution |
|---|---|
| Delete Middle Node | DeleteMiddleNode.java |
| Maximum Twin Sum of a Linked List | PairSum.java |
| Merge Two Lists | MergeTwoLists.java |
| Odd Even Linked List | OddEvenLinkedList.java |
| Reverse Linked | ReverseLinked.java |
| Problem | Solution |
|---|---|
| Delete Node BST | DeleteNodeBST.java |
| Good Nodes in Binary Tree | GoodNodesInBinaryTree.java |
| Leaf Similar Trees | LeafSimilarTrees.java |
| Longest Zig Zag Path | LongestZigZagPath.java |
| Lowest Common Ancestor | LowestCommonAncestor.java |
| Max Depth Binary Tree | MaxDepthBinaryTree.java |
| Max Level Sum Binary Tree | MaxLevelSumBinaryTree.java |
| Path Sum III | PathSumIII.java |
| Right Side View | RightSideView.java |
| Root to Leaf Paths | RootToLeafPaths.java |
| Search BST | SearchBST.java |
| Problem | Solution |
|---|---|
| Evaluate Division | EvaluateDivision.java |
| Flower Planting | FlowerPlanting.java |
| Island Perimeter | IslandPerimeter.java |
| Nearest Exit in Maze | NearestExitInMaze.java |
| Number of Provinces | NumberOfProvinces.java |
| Reorder Routes | ReorderRoutes.java |
| Rotting Oranges | RottingOranges.java |
| Town Judge | TownJudge.java |
| Visit All Rooms | VisitAllRooms.java |
| Problem | Solution |
|---|---|
| Combination Sum | CombinationSum.java |
| Combination Sum3 | CombinationSum3.java |
| Count Good Triplets | CountGoodTriplets.java |
| Letter Combinations | LetterCombinations.java |
| Word Search | WordSearch.java |
| Problem | Solution |
|---|---|
| Best Time to Buy and Sell Stock | BestTimeToBuyAndSellStock.java |
| Edit Distance | EditDistance.java |
| House Robber | HouseRobber.java |
| Longest Common Subsequence | LongestCommonSubsequence.java |
| Min Cost Climbing Stairs | MinCostClimbingStairs.java |
| Stock with Transaction Fee | StockWithTransactionFee.java |
| Tiling Domino Tromino | TilingDominoTromino.java |
| Tribonacci | Tribonacci.java |
| Unique Paths | UniquePaths.java |
| Problem | Solution |
|---|---|
| Add Binary | AddBinary.java |
| Add Strings | AddStrings.java |
| Add to Array Form | AddToArrayForm.java |
| Binary Date | BinaryDate.java |
| Bitwise Flip Counter | BitwiseFlipCounter.java |
| Convert to Base Seven | ConvertToBaseSeven.java |
| Count Bits | CountBits.java |
| Day of Year | DayOfYear.java |
| Days Between Dates | DaysBetweenDates.java |
| Divide Two Integers | DivideTwoIntegers.java |
| Excel Column Number | ExcelColumnNumber.java |
| Excel Column Title | ExcelColumnTitle.java |
| Fizz Buzz | FizzBuzz.java |
| Integer to Roman | IntegerToRoman.java |
| Missing Number | MissingNumber.java |
| Multiply Strings | MultiplyStrings.java |
| Palindrome Number | PalindromeNumber.java |
| Plus One | PlusOne.java |
| Power | Power.java |
| Reverse Integer | ReverseInteger.java |
| Rotate Matrix | RotateMatrix.java |
| Single Number | SingleNumber.java |
| Smallest Range I | SmallestRangeI.java |
| String to Integer (atoi) | MyAtoi.java |
| Thousand Separator | ThousandSeperator.java |
| Problem | Solution |
|---|---|
| Design HashMap | MyHashMap.java |
| PriorityQueue (practice with the collection) | PriorityQueueCollection.java |
| Recent Counter | RecentCounter.java |
| Smallest Infinite Set | SmallestInfiniteSet.java |
| Stock Spanner | StockSpanner.java |
| Trie | Trie.java |
The table above is generated. After adding a solution, add its class name to the
topic map in tools/build_index.py and run:
python tools/build_index.py
It warns about any file that is not in the map, so nothing goes missing.