├── .coveralls.yml ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE.txt ├── README.md ├── cgit.bat ├── cgit.sh ├── doc ├── 001-100 │ ├── 001-two-num-sum.md │ ├── 002-add-two-numbers.md │ ├── 003-longest-substring-without-repeating-characters.md │ ├── 004-median-of-two-sorted-arrays.md │ ├── 005-longest-palindromic-substring.md │ ├── 006-zigzag-conversion.md │ ├── 007-reverse-integer.md │ ├── 008-string-to-integer-atoi.md │ ├── 009-palindrome-number.md │ ├── 010-regular-expression-matching.md │ ├── 011-container-with-most-water.md │ ├── 012-integer-to-roman.md │ ├── 013-roman-to-integer.md │ ├── 014-longest-common-prefix.md │ ├── 015-3num.md │ ├── 016-3sum-closest.md │ ├── 017-letter-combinations-of-a-phone-number.md │ ├── 018-4sum.md │ ├── 019-remove-nth-node-from-end-of-list.md │ ├── 020-valid-parentheses.md │ ├── 021-merge-two-sorted-lists.md │ ├── 022-generate-parentheses.md │ ├── 023-merge-k-sorted-lists.md │ ├── 024-swap-nodes-in-pairs.md │ ├── 025-reverse-nodes-in-k-group.md │ ├── 026-remove-duplicates-from-sorted-array.md │ ├── 027-remove-element.md │ ├── 028-implement-strstr.md │ ├── 029-divide-two-integers.md │ ├── 030-substring-with-concatenation-of-all-words.md │ ├── 031-next-permutation.md │ ├── 032-longest-valid-parentheses.md │ ├── 033-search-in-rotated-sorted-array.md │ ├── 034-find-first-and-last-position-of-element-in-sorted-array.md │ ├── 035-search-insert-position.md │ ├── 036-valid-sudoku.md │ ├── 037-sudoku-solver.md │ ├── 038-count-and-say.md │ ├── 039-combination-sum.md │ ├── 040-combination-sum-ii.md │ ├── 041-first-missing-positive.md │ ├── 042-trapping-rain-water.md │ ├── 043-multiply-strings.md │ ├── 044-wildcard-matching.md │ ├── 045-jump-game-ii.md │ ├── 046-permutations.md │ ├── 047-permutations-ii.md │ ├── 048-rotate-image.md │ ├── 049-group-anagrams.md │ ├── 050-powerxn.md │ ├── 051-n-queens.md │ ├── 052-n-queens-ii.md │ ├── 053-maximum-subarray.md │ ├── 054-spiral-matrix.md │ ├── 055-jump-game.md │ ├── 056-merge-intervals.md │ ├── 057-insert-intervals.md │ ├── 058-length-of-last-word.md │ ├── 059-spiral-matrix-ii.md │ ├── 060-permutation-sequence.md │ ├── 061-rotate-list.md │ ├── 062-unique-paths.md │ ├── 063-unique-paths-ii.md │ ├── 064-minimum-path-sum.md │ ├── 065-valid-number.md │ ├── 066-plus-one.md │ ├── 067-add-binary.md │ ├── 068-text-justification.md │ ├── 070-climbing-stairs.md │ ├── 071-edit-distance.md │ ├── 071-simplify-path.md │ ├── 073-set-matrix-zeroes.md │ ├── 074-search-a-2d-matrix.md │ ├── 075-sort-colors.md │ ├── 076-minimum-window-substring.md │ ├── 077-combinations.md │ ├── 078-subsets.md │ ├── 079-word-search.md │ ├── 080-remove-duplicates-from-sorted-array-ii.md │ ├── 081-search-in-rotated-sorted-array-ii.md │ ├── 082-remove-duplicates-from-sorted-list-ii.md │ ├── 083-remove-duplicates-from-sorted-list.md │ ├── 084-largest-rectangle-in-histogram.md │ ├── 085-maximal-rectangle.md │ ├── 086-partition-list.md │ ├── 087-scramble-string.md │ ├── 088-merge-sorted-array.md │ ├── 089-grey-code.md │ ├── 090-subsets-ii.md │ ├── 091-decode-ways.md │ ├── 092-reverse-linked-list-ii.md │ ├── 093-restore-ip-addresses.md │ ├── 094-binary-tree-inorder-traversal.md │ ├── 095-unique-binary-search-trees-ii.md │ ├── 096-unique-binary-search-trees.md │ ├── 097-interleaving-string.md │ ├── 098-validate-binary-search-tree.md │ ├── 099-recover-binary-search-tree.md │ └── 100-same-tree.md ├── 101-200 │ ├── 101-symmetric-tree.md │ ├── 102-binary-tree-level-order-traversal.md │ ├── 103-binary-tree-zigzag-level-order-traversal.md │ ├── 104-maximum-depth-of-binary-tree.md │ ├── 105-construct-binary-tree-from-preorder-and-inorder-traversal.md │ ├── 106-construct-binary-tree-from-inorder-and-postorder-traversal.md │ ├── 107-binary-tree-level-order-traversal-ii.md │ ├── 108-convert-sorted-array-to-binary-search-tree.md │ ├── 109-convert-sorted-list-to-binary-search-tree.md │ ├── 110-balanced-binary-tree.md │ ├── 111-minimum-depth-of-binary-tree.md │ ├── 112-path-sum.md │ ├── 113-path-sum-ii.md │ ├── 114-flatten-binary-tree-to-linked-list.md │ ├── 115-distinct-subsequences.md │ ├── 116-populating-next-right-pointers-in-each-node.md │ ├── 117-populating-next-right-pointers-in-each-node-ii.md │ ├── 118-pascals-triangle.md │ ├── 119-pascals-triangle-ii.md │ ├── 120-triangle.md │ ├── 121-best-time-to-buy-and-sell-stock.md │ ├── 122-best-time-to-buy-and-sell-stock-ii.md │ ├── 123-best-time-to-buy-and-sell-stock-iii.md │ ├── 124-binary-tree-maximum-path-sum.md │ ├── 125-valid-palindrome.md │ ├── 126-word-ladder-ii.md │ ├── 127-word-ladder.md │ ├── 128-longest-consecutive-sequence.md │ ├── 129-sum-root-to-leaf-numbers.md │ ├── 130-surrounded-regions.md │ ├── 131-palindrome-partitioning.md │ ├── 132-palindrome-partitioning-ii.md │ ├── 133-clone-graph.md │ ├── 134-gas-station.md │ ├── 135-candy.md │ ├── 136-single-number.md │ ├── 137-single-number-ii.md │ ├── 138-copy-list-with-random-pointer.md │ ├── 139-word-break.md │ ├── 140-word-break-ii.md │ ├── 141-linked-list-cycle.md │ ├── 143-reorder-list.md │ ├── 144-binary-tree-preorder-traversal.md │ ├── 145-binary-tree-postorder-traversal.md │ ├── 146-lru-cache.md │ ├── 147-insertion-sort-list.md │ ├── 148-sort-list.md │ ├── 149-max-points-on-a-line.md │ ├── 150-evaluate-reverse-polish-notation.md │ ├── 151-reverse-words-in-a-string.md │ ├── 152-maximum-product-subarray.md │ ├── 153-find-minimum-in-rotated-sorted-array.md │ ├── 154-find-minimum-in-rotated-sorted-array-ii.md │ ├── 155-min-stack.md │ ├── 160-intersection-of-two-linked-lists.md │ ├── 162-find-peak-element.md │ ├── 164-maximum-gap.md │ ├── 165-compare-version-numbers.md │ ├── 166-fraction-to-recurring-decimal.md │ ├── 167-two-sum-ii-input-array-is-sorted.md │ ├── 168-excel-sheet-column-title.md │ ├── 169-excel-sheet-column-number.md │ ├── 169-majority-element.md │ ├── 172-factorial-trailing-zeroes.md │ ├── 173-binary-search-tree-iterator.md │ ├── 174-dungeon-game.md │ ├── 179-largest-number.md │ ├── 187-repeated-dna-sequences.md │ ├── 188-best-time-to-buy-and-sell-stock-iv.md │ ├── 189-rotate-array.md │ ├── 190-reverse-bits.md │ ├── 191-number-of-1-bits.md │ ├── 198-house-robber.md │ ├── 199-binary-tree-right-side-view.md │ └── 200-number-of-islands.md ├── 1300-1400 │ ├── 1305-all-elements-in-two-binary-search-trees.md │ └── 1329-sort-the-matrix-diagonally.md ├── 200-300 │ ├── 201-bitwise-and-of-numbers-range.md │ ├── 202-happy-number.md │ ├── 203-remove-linked-list-elements.md │ ├── 204-count-primes.md │ ├── 205-isomorphic-strings.md │ ├── 206-reverse-linked-list.md │ ├── 206-single-number-iii.md │ ├── 207-course-schedule.md │ ├── 208-implement-trie-prefix-tree.md │ ├── 209-minimum-size-subarray-sum.md │ ├── 210-course-schedule-ii.md │ ├── 211-design-add-and-search-words-data-structure.md │ ├── 212-word-search-ii.md │ ├── 213-house-robber-ii.md │ ├── 214-shortest-palindrome.md │ ├── 215-kth-largest-element-in-an-array.md │ ├── 217-contains-duplicate.md │ ├── 229-majority-element-ii.md │ ├── 233-number-of-digit-one.md │ ├── 237-delete-node-in-a-linked-list.md │ └── 257-binary-tree-paths.md ├── 206-reverse-linked-list.md ├── 300-400 │ └── 347-top-k-frequent-elements.md ├── 400-500 │ └── 437-path-sum-iii.md ├── 500-600 │ └── 509-fibonacci-number.md ├── 600-700 │ └── 629-top-k-frequent-words.md ├── README.md └── _BAK │ ├── README.md │ └── README_BAK.md ├── pom.xml ├── release.bat ├── release.sh ├── release_rm.sh └── src ├── main └── java │ └── com │ └── github │ └── houbb │ └── leetcode │ ├── AddTwoNumbers.java │ ├── AddTwoNumbersLeetCodeVersion1.java │ ├── AddTwoNumbersLeetCodeVersion2.java │ ├── AddTwoNumbersLeetCodeVersion3.java │ ├── ClimbStairs.java │ ├── ContainerWithMostWater.java │ ├── DivideTwoIntegers.java │ ├── F000T100 │ ├── T001_TwoNumSum.java │ ├── T002_AddTwoNumbers.java │ ├── T002_AddTwoNumbersV1.java │ ├── T002_AddTwoNumbersV2.java │ ├── T002_AddTwoNumbersV3.java │ ├── T003_LongestSubstringWithoutRepeatingCharacters.java │ ├── T003_LongestSubstringWithoutRepeatingCharactersV2.java │ ├── T003_LongestSubstringWithoutRepeatingCharactersV3.java │ ├── T004_MedianOfTwoSortedArrays.java │ ├── T005_LongestPalindromicSubstring.java │ ├── T005_LongestPalindromicSubstringManacher.java │ ├── T005_LongestPalindromicSubstringV2.java │ ├── T006_ZigzagConversion.java │ ├── T006_ZigzagConversionV2.java │ ├── T006_ZigzagConversionV3.java │ ├── T006_ZigzagConversionV4.java │ ├── T007_ReverseInteger.java │ ├── T007_ReverseIntegerV2.java │ ├── T008_StringToIntegerAtoi.java │ ├── T008_StringToIntegerAtoiV2.java │ ├── T009_PalindromeNumber.java │ ├── T009_PalindromeNumberV1.java │ ├── T009_PalindromeNumberV2.java │ ├── T010_RegularExpressionMatching.java │ ├── T010_RegularExpressionMatchingV2.java │ ├── T011_ContainerWithMostWater.java │ ├── T011_ContainerWithMostWaterV2.java │ ├── T011_ContainerWithMostWaterV3.java │ ├── T012_IntegerToRoman.java │ ├── T012_IntegerToRomanV2.java │ ├── T012_IntegerToRomanV3.java │ ├── T013_RomanToInteger.java │ ├── T014_LongestCommonPrefix.java │ ├── T015_3Num.java │ ├── T015_3NumV2.java │ ├── T016_3SumClosest.java │ ├── T016_3SumClosestV2.java │ ├── T017_LetterCombinationsOfAPhoneNumber.java │ ├── T017_LetterCombinationsOfAPhoneNumberRecursive.java │ ├── T018_FourSum.java │ ├── T018_FourSumV2.java │ ├── T019_RemoveNthNodeFromEndOfList.java │ ├── T019_RemoveNthNodeFromEndOfListV2.java │ ├── T019_RemoveNthNodeFromEndOfListV3.java │ ├── T020_ValidParentheses.java │ ├── T020_ValidParenthesesV2.java │ ├── T021_MergeTwoSortedLists.java │ ├── T021_MergeTwoSortedListsV2.java │ ├── T022_GenerateParenthesesBF.java │ ├── T022_GenerateParenthesesBacktrack.java │ ├── T022_GenerateParenthesesBfs.java │ ├── T022_GenerateParenthesesDfs.java │ ├── T022_GenerateParenthesesDfsMinis.java │ ├── T022_GenerateParenthesesDp.java │ ├── T023_MergeKSortedLists.java │ ├── T023_MergeKSortedListsDivideAndConquer.java │ ├── T023_MergeKSortedListsOneByOne.java │ ├── T023_MergeKSortedListsPriorityQueue.java │ ├── T023_MergeKSortedListsV2.java │ ├── T024_SwapNodesInPairs.java │ ├── T025_ReverseNodesInKGroup.java │ ├── T025_ReverseNodesInKGroupOptimize.java │ ├── T025_ReverseNodesInKGroupV3.java │ ├── T026_RemoveDuplicatesFromSortedArray.java │ ├── T026_RemoveDuplicatesFromSortedArrayV2.java │ ├── T027_RemoveElement.java │ ├── T028_FindTheIndexOfTheFirstOccurrenceInAString.java │ ├── T029_DivideTwoIntegers.java │ ├── T030_SubstringWithConcatenationOfAllWords.java │ ├── T030_SubstringWithConcatenationOfAllWordsSlideWindow.java │ ├── T030_SubstringWithConcatenationOfAllWordsSlideWindowOptimize.java │ ├── T030_SubstringWithConcatenationOfAllWordsV2.java │ ├── T031_NextPermutation.java │ ├── T032_LongestValidParentheses.java │ ├── T032_LongestValidParenthesesV2.java │ ├── T032_LongestValidParenthesesV3.java │ ├── T033_SearchInRotatedSortedArray.java │ ├── T033_SearchInRotatedSortedArrayV2.java │ ├── T034_FindFirstAndLastPosition.java │ ├── T034_FindFirstAndLastPositionV2.java │ ├── T034_FindFirstAndLastPositionV3.java │ ├── T035_SearchInsertPosition.java │ ├── T035_SearchInsertPositionV2.java │ ├── T036_ValidSoduku.java │ ├── T037_SudokuSolver.java │ ├── T037_SudokuSolverV2.java │ ├── T037_SudokuSolver_FAILED.java │ ├── T038_CountAndSay.java │ ├── T039_CombinationSum.java │ ├── T039_CombinationSumV2.java │ ├── T040_CombinationSumII.java │ ├── T040_CombinationSumIIBest.java │ ├── T040_CombinationSumIIV1.java │ ├── T041_FirstMissingPositive.java │ ├── T042_TrappingRainWater.java │ ├── T042_TrappingRainWaterV0.java │ ├── T042_TrappingRainWaterV1.java │ ├── T042_TrappingRainWaterV2.java │ ├── T042_TrappingRainWaterV3.java │ ├── T042_TrappingRainWaterV4.java │ ├── T043_MultiplyStrings.java │ ├── T044_WildcardMatching.java │ ├── T044_WildcardMatchingDp.java │ ├── T044_WildcardMatchingRecursive.java │ ├── T044_WildcardMatchingRecursiveMem.java │ ├── T045_JumpGameII.java │ ├── T046_Permutations.java │ ├── T047_PermutationsII.java │ ├── T047_PermutationsII_V0.java │ ├── T048_RotateImage.java │ ├── T049_GroupAnagrams.java │ ├── T049_GroupAnagramsV2.java │ ├── T050_PowerxN.java │ ├── T051_NQueens.java │ ├── T052_NQueensII.java │ ├── T052_NQueensIIV2.java │ ├── T053_MaximumSubarray.java │ ├── T054_SpiralMatrix.java │ ├── T055_JumpGame.java │ ├── T056_MergeIntervals.java │ ├── T057_InsertIntervals.java │ ├── T057_InsertIntervalsWorst.java │ ├── T058_LengthOfLastWord.java │ ├── T059_SpiralMatrixII.java │ ├── T059_SpiralMatrixIIBasic.java │ ├── T060_PermutationSequence.java │ ├── T060_PermutationSequenceV2.java │ ├── T060_PermutationSequenceV3.java │ ├── T061_RotateList.java │ ├── T061_RotateListV2.java │ ├── T062_UniquePaths.java │ ├── T063_UniquePathsII.java │ ├── T064_MinimumPathSum.java │ ├── T065_ValidNumber.java │ ├── T066_PlusOne.java │ ├── T067_AddBinary.java │ ├── T068_TextJustification.java │ ├── T069_Sqrtx.java │ ├── T069_SqrtxV2.java │ ├── T070_ClimbStairs.java │ ├── T071_SimplifyPath.java │ ├── T072_EditDistance.java │ ├── T072_EditDistanceV2.java │ ├── T072_EditDistanceV3.java │ ├── T073_SetMatrixZeroes.java │ ├── T074_SearchA2dMatrix.java │ ├── T075_SortColors.java │ ├── T076_MinimumWindowSubstring.java │ ├── T076_MinimumWindowSubstringV2.java │ ├── T076_MinimumWindowSubstringV3.java │ ├── T077_Combinations.java │ ├── T078_Subsets.java │ ├── T079_WordSearch.java │ ├── T081_SearchInRotatedSortedArrayII.java │ ├── T082_RemoveDuplicatesFromSortedListII.java │ ├── T082_RemoveDuplicatesFromSortedListIIV2.java │ ├── T082_RemoveDuplicatesFromSortedListIIV3.java │ ├── T083_RemoveDuplicatesFromSortedList.java │ ├── T083_RemoveDuplicatesFromSortedListV2.java │ ├── T084_LargestRectangleInHistogram.java │ ├── T084_LargestRectangleInHistogramV2.java │ ├── T085_MaximalRectangle.java │ ├── T085_MaximalRectangleV2.java │ ├── T085_MaximalRectangleV3.java │ ├── T086_PartitionList.java │ ├── T086_PartitionListV2.java │ ├── T087_ScrambleString.java │ ├── T087_ScrambleStringV2.java │ ├── T087_ScrambleStringV3.java │ ├── T088_MergeSortedArray.java │ ├── T088_MergeSortedArrayV2.java │ ├── T089_GrayCode.java │ ├── T090_SubsetsII.java │ ├── T091_DecodeWays.java │ ├── T092_ReverseLinkedListII.java │ ├── T093_RestoreIpAddresses.java │ ├── T094_BinaryTreeInorderTraversal.java │ ├── T094_BinaryTreeInorderTraversalV2.java │ ├── T095_UniqueBinarySearchTreesII.java │ ├── T096_UniqueBinarySearchTrees.java │ ├── T096_UniqueBinarySearchTreesV2.java │ ├── T097_InterleavingString.java │ ├── T097_InterleavingStringV2.java │ ├── T098_ValidateBinarySearchTree.java │ ├── T099_RecoverBinarySearchTree.java │ ├── T100_SameTree.java │ └── package-info.java │ ├── F1000T1100 │ ├── T1124longestWPI.java │ ├── T1124longestWPI_V2_PrefixSumHashMap.java │ ├── T1182_MIN_COLOR.java │ ├── T1182_MIN_COLOR_BF.java │ ├── T1182_MIN_COLOR_V2.java │ ├── T2459_MinMoveSteps.java │ ├── T2459_MinMoveSteps_V2.java │ ├── T2548_maxPriceBag.java │ ├── T2548_maxPriceBag_V2.java │ ├── T3195_minContainsOneArea.java │ └── T325_maxSubArrayEqualsK_V1.java │ ├── F100T200 │ ├── T101_SymmetricTree.java │ ├── T102_BinaryTreeLevelOrderTraversal.java │ ├── T103_BinaryTreeZigZagLevelOrderTraversal.java │ ├── T104_MaximumDepthOfBinaryTree.java │ ├── T105_ConstructBinaryTreeFromInorderAndPostOrderTraversal.java │ ├── T106_ConstructBinaryTreeFromPreorderAndInorderTraversal.java │ ├── T107_BinaryTreeLevelOrderTraversalII.java │ ├── T108_ConvertSortedArrayToBinarySearchTree.java │ ├── T108_ConvertSortedArrayToBinarySearchTreeV1.java │ ├── T109_ConvertSortedListToBinarySearchTree.java │ ├── T109_ConvertSortedListToBinarySearchTreeV2.java │ ├── T110_BalancedBinaryTree.java │ ├── T111_MinimumDepthOfBinaryTreeBFS.java │ ├── T111_MinimumDepthOfBinaryTreeDFS.java │ ├── T112_PathSum.java │ ├── T113_PathSumII.java │ ├── T113_PathSumIIV2.java │ ├── T113_PathSumIIV3.java │ ├── T114_FlattenBinaryTreeToLinkedList.java │ ├── T114_FlattenBinaryTreeToLinkedListV2.java │ ├── T114_FlattenBinaryTreeToLinkedListV3.java │ ├── T114_FlattenBinaryTreeToLinkedListV4.java │ ├── T115_DistinctSubsequences.java │ ├── T116_PopulatingNextRightPointersInEachNode.java │ ├── T116_PopulatingNextRightPointersInEachNodeV2.java │ ├── T117_PopulatingNextRightPointersInEachNodeII.java │ ├── T117_PopulatingNextRightPointersInEachNodeIIV2.java │ ├── T117_PopulatingNextRightPointersInEachNodeIIV3.java │ ├── T118_PascalsTriangle.java │ ├── T118_PascalsTriangleV2.java │ ├── T119_PascalsTriangleII.java │ ├── T119_PascalsTriangleIIV2.java │ ├── T120_TriangleDp.java │ ├── T120_TriangleDpOptimize.java │ ├── T120_TriangleDpReusage.java │ ├── T120_TriangleGreedy.java │ ├── T121_BestTimeToBuyAndSellStock.java │ ├── T121_BestTimeToBuyAndSellStockV2.java │ ├── T121_BestTimeToBuyAndSellStock_V20241105.java │ ├── T122_BestTimeToBuyAndSellStockII.java │ ├── T122_BestTimeToBuyAndSellStockII_DP.java │ ├── T123_BestTimeToBuyAndSellStockIII.java │ ├── T123_BestTimeToBuyAndSellStockIIIV2.java │ ├── T123_BestTimeToBuyAndSellStockIIIV3.java │ ├── T123_BestTimeToBuyAndSellStockIIIV4.java │ ├── T123_BestTimeToBuyAndSellStockIII_V20241105.java │ ├── T123_BestTimeToBuyAndSellStockIII_V20241105_VDP.java │ ├── T124_BinaryTreeMaximumPathSum.java │ ├── T125_ValidPalindrome.java │ ├── T126_WordLadderII.java │ ├── T126_WordLadderIIV2.java │ ├── T126_WordLadderIIV3.java │ ├── T126_WordLadderIIV_OTHER.java │ ├── T126_WordLadderIIV_OTHER2.java │ ├── T127_WordLadder.java │ ├── T127_WordLadderV2.java │ ├── T128_LongestConsecutiveSequence.java │ ├── T129_SumRootToLeafNums.java │ ├── T129_SumRootToLeafNumsV2.java │ ├── T130_SurroundedRegions.java │ ├── T131_PalindromePartitioning.java │ ├── T131_PalindromePartitioningV2.java │ ├── T131_PalindromePartitioningV3.java │ ├── T132_PalindromePartitioningII.java │ ├── T132_PalindromePartitioningV2.java │ ├── T133_CloneGraph.java │ ├── T133_CloneGraphBFS.java │ ├── T134_GasStation.java │ ├── T135_Candy.java │ ├── T135_CandyV2.java │ ├── T135_CandyV3.java │ ├── T135_CandyV4.java │ ├── T136_SingleNumber.java │ ├── T136_SingleNumberV2.java │ ├── T136_SingleNumberV3.java │ ├── T137_SingleNumberII.java │ ├── T137_SingleNumberIIV2.java │ ├── T138_CopyListWithRandomPointer.java │ ├── T139_WordBreak.java │ ├── T139_WordBreakV2.java │ ├── T139_WordBreakV3.java │ ├── T139_WordBreakV4.java │ ├── T139_WordBreakV5.java │ ├── T139_WordBreakV6.java │ ├── T140_WordBreakII.java │ ├── T141_LinkedListCycle.java │ ├── T141_LinkedListCycle_ERROR.java │ ├── T142_LinkedListCycleII.java │ ├── T143_ReorderList.java │ ├── T144_BinaryTreePreorderTraversal.java │ ├── T144_BinaryTreePreorderTraversalLoop.java │ ├── T145_BinaryTreePostorderTraversal.java │ ├── T145_BinaryTreePostorderTraversalLoop.java │ ├── T146_LRUCache.java │ ├── T146_LRUCacheV2.java │ ├── T146_LRUCacheV3.java │ ├── T147_InsertionSortList.java │ ├── T148_SortList.java │ ├── T149_MaxPointsOnALine.java │ ├── T149_MaxPointsOnALineV2.java │ ├── T149_MaxPointsOnALineV3.java │ ├── T149_MaxPointsOnALineV4.java │ ├── T150_EvaluateReversePolishNotation.java │ ├── T151_ReverseWordsInAString.java │ ├── T151_ReverseWordsInAStringV2.java │ ├── T152_MaximumProductSubarray.java │ ├── T152_MaximumProductSubarrayV2.java │ ├── T152_MaximumProductSubarrayV3.java │ ├── T153_FindMinimumInRotatedSortedArray.java │ ├── T153_FindMinimumInRotatedSortedArrayV2.java │ ├── T154_FindMinimumInRotatedSortedArrayII.java │ ├── T154_FindMinimumInRotatedSortedArrayIIV2.java │ ├── T155_MinStack.java │ ├── T160_IntersectionOfTwoLinkedLists.java │ ├── T162_FindPeakElement.java │ ├── T162_FindPeakElementV2.java │ ├── T164_MaximumGap.java │ ├── T165_CompareVersionNumbers.java │ ├── T166_FractionToRecurringDecimal.java │ ├── T167_TwoSumIIInputArrayIsSorted.java │ ├── T167_TwoSumIIInputArrayIsSortedV2.java │ ├── T167_TwoSumIIInputArrayIsSortedV3.java │ ├── T168_ExcelSheetColumnTitle.java │ ├── T169_MajorityElement.java │ ├── T169_MajorityElementMoerV3.java │ ├── T169_MajorityElementV2.java │ ├── T169_MajorityElementV4.java │ ├── T171_ExcelSheetColumnNumber.java │ ├── T172_FactorialTrailingZeroes.java │ ├── T172_FactorialTrailingZeroesV2.java │ ├── T173_BinarySearchTreeIterator.java │ ├── T174_DungeonGame.java │ ├── T174_DungeonGameV2.java │ ├── T174_DungeonGameV3.java │ ├── T179_LargestNumber.java │ ├── T187_RepeatedDnaSequences.java │ ├── T188_BestTimeToBuyAndSellStockIV.java │ ├── T188_BestTimeToBuyAndSellStockIV_v20241105_VDP.java │ ├── T189_RotateArray.java │ ├── T190_ReverseBits.java │ ├── T191_NumberOf1Bits.java │ ├── T191_NumberOf1BitsV2.java │ ├── T198_HouseRobber.java │ ├── T198_HouseRobberV2.java │ ├── T198_HouseRobberV3.java │ ├── T198_HouseRobberV4.java │ ├── T198_rob_V1_DP.java │ ├── T199_BinaryTreeRightSideView.java │ ├── T200_NumberOfIslands.java │ ├── T200_NumberOfIslandsV2.java │ └── T213_robII_V1_DP.java │ ├── F1300T1400 │ ├── AllElementsInTwoBinarySearchTrees.java │ ├── AllElementsInTwoBinarySearchTrees2.java │ ├── AllElementsInTwoBinarySearchTreesBetter.java │ ├── SortTheMatrixDiagonally.java │ ├── SortTheMatrixDiagonallyBest.java │ ├── SortTheMatrixDiagonallyBetter.java │ ├── T_1371_findTheLongestSubstring_V1.java │ ├── T_1371_findTheLongestSubstring_V2.java │ └── T_1371_findTheLongestSubstring_V3.java │ ├── F200T300 │ ├── BinaryTreePaths.java │ ├── DeleteNodeInALinkedList.java │ ├── KthLargestElementInAnArray.java │ ├── KthLargestElementInAnArrayHeap.java │ ├── MajorityElementII.java │ ├── MajorityElementIIMoerVote.java │ ├── NumberOfDigitOne.java │ ├── NumberOfDigitOneMath.java │ ├── SingleNumIII.java │ ├── SingleNumIIIBest.java │ ├── SingleNumIIIBetter.java │ ├── T201_BitwiseAndOfNumbersRange.java │ ├── T201_BitwiseAndOfNumbersRangeV2.java │ ├── T202_HappyNumber.java │ ├── T202_HappyNumberV2.java │ ├── T203_RemoveLinkedListElements.java │ ├── T204_CountPrimes.java │ ├── T204_CountPrimesV2.java │ ├── T204_CountPrimesV3.java │ ├── T204_CountPrimesV4.java │ ├── T205_IsomorphicStrings.java │ ├── T205_IsomorphicStringsV2.java │ ├── T206_ReverseLinkedList.java │ ├── T206_ReverseLinkedListV2.java │ ├── T207_CourseSchedule.java │ ├── T207_CourseScheduleV2.java │ ├── T208_ImplementTriePrefixTree.java │ ├── T209_MinimumSizeSubarraySum.java │ ├── T209_MinimumSizeSubarraySumV2.java │ ├── T209_MinimumSizeSubarraySumV3.java │ ├── T209_MinimumSizeSubarraySum_V4_PrefixSum.java │ ├── T209_MinimumSizeSubarraySum_V4_PrefixSum_BinarySearch.java │ ├── T209_MinimumSizeSubarraySum_V6_TwoPinter.java │ ├── T210_CourseScheduleII.java │ ├── T211_WordDictionary.java │ ├── T212_WordSearch.java │ ├── T212_WordSearchV2.java │ ├── T212_WordSearchV3.java │ ├── T212_bestTimeToBuyAndSellStock.java │ ├── T212_bestTimeToBuyAndSellStockBest.java │ ├── T212_bestTimeToBuyAndSellStock_II.java │ ├── T213_HouseRobberII.java │ ├── T213_bestTimeToBuyAndSellStock_III.java │ ├── T214_ShortestPalindrome.java │ ├── T214_ShortestPalindromeV2.java │ ├── T214_ShortestPalindromeV3.java │ ├── T214_ShortestPalindromeV4.java │ ├── T214_ShortestPalindromeV5.java │ ├── T216_CombinationSumIII.java │ ├── T217_ContainsDuplicate.java │ ├── T217_ContainsDuplicateV2Bit.java │ ├── T217_ContainsDuplicateV3InsertSort.java │ ├── T217_ContainsDuplicateV4CompareTest.java │ ├── T217_ContainsDuplicateV4InsertSortOptimize.java │ ├── T218_SkyProblem_V1.java │ ├── T219_ContainsDuplicateII_V1.java │ ├── T219_ContainsDuplicateII_V2.java │ ├── T220_ContainsDuplicateIII_V1.java │ ├── T220_ContainsDuplicateIII_V2.java │ ├── T220_ContainsDuplicateIII_V3.java │ ├── T220_ContainsDuplicateIII_V4.java │ ├── T220_ContainsDuplicateIII_V5.java │ ├── T220_ContainsDuplicateIII_V6.java │ ├── T238_ProductOfArrayExceptSelf_V1_PrefixSuffix.java │ └── T238_ProductOfArrayExceptSelf_V2_PrefixSuffixMemOpt.java │ ├── F300T400 │ ├── T302_PrefixSum_RangeSumQueryImmutable_V1.java │ ├── T307_PrefixSum_RangeSumQueryMutable_V1.java │ ├── T309_bestTimeToBuyAndSellStockWithCooldownV1.java │ ├── T309_bestTimeToBuyAndSellStockWithCooldownV2_Dp.java │ ├── T325_LongestSubarraySumK_V1.java │ ├── T325_LongestSubarraySumZero_V2_PrefixSumHashMap.java │ ├── T325_maxSubArrayEqualsK_V1.java │ ├── T377_CombinationSumIV.java │ ├── T377_CombinationSumIVV2.java │ ├── T377_CombinationSumIVV3.java │ ├── T377_CombinationSumIVV4.java │ ├── TopKFrequentElements.java │ ├── TopKFrequentElementsListSort.java │ ├── TopKFrequentElementsMoerVote.java │ └── TopKFrequentElementsTreeMap.java │ ├── F400T500 │ ├── PathSumIII.java │ ├── PathSumIIIBest.java │ └── PathSumIIIRecursive.java │ ├── F600T700 │ ├── T618_ClosestTime.java │ ├── T_MaxStatck.java │ ├── T_minMeetingRooms.java │ ├── T_moveQi.java │ ├── TopKFrequentWords.java │ └── TopKFrequentWordsSort.java │ ├── F700T800 │ ├── F713_bestTimeToBuyAndSellStockWithTransactionFee_DP.java │ └── T713_BestTimeToBuyAndSellStockWithTxFee_V1.java │ ├── FourSum.java │ ├── FourSumBest.java │ ├── GenerateParenthesesBF.java │ ├── GenerateParenthesesBacktrack.java │ ├── GenerateParenthesesBfs.java │ ├── GenerateParenthesesDfs.java │ ├── GenerateParenthesesDfsMinis.java │ ├── GenerateParenthesesDp.java │ ├── ImplementStrStr.java │ ├── IntegerToRoman.java │ ├── IntegerToRomanBest.java │ ├── KSum.java │ ├── LetterCombinationsOfAPhoneNumber.java │ ├── LetterCombinationsOfAPhoneNumberRecursive.java │ ├── ListNode.java │ ├── LongestCommonPrefix.java │ ├── LongestPalindromicSubstring.java │ ├── LongestPalindromicSubstringManacher.java │ ├── LongestSubstringWithoutRepeatingCharacters.java │ ├── MedianOfTwoSortedArrays.java │ ├── MergeKSortedLists.java │ ├── MergeKSortedListsBest.java │ ├── MergeKSortedListsDivideAndConquer.java │ ├── MergeKSortedListsOneByOne.java │ ├── MergeKSortedListsPriorityQueue.java │ ├── MergeTwoSortedLists.java │ ├── MergeTwoSortedListsBest.java │ ├── PalindromeNumber.java │ ├── PalindromeNumberOptimize.java │ ├── RegularExpressionMatching.java │ ├── RegularExpressionMatchingDp.java │ ├── RemoveDuplicatesFromSortedArray.java │ ├── RemoveDuplicatesFromSortedArrayII.java │ ├── RemoveElement.java │ ├── RemoveNthNodeFromEndOfList.java │ ├── ReverseInteger.java │ ├── ReverseLinkedList.java │ ├── ReverseLinkedListBetter.java │ ├── ReverseLinkedListII.java │ ├── ReverseNodesInKGroup.java │ ├── ReverseNodesInKGroupOptimize.java │ ├── RomanToInteger.java │ ├── StringToIntegerAtoi.java │ ├── StringToIntegerAtoiOptimize.java │ ├── SubstringWithConcatenationOfAllWords.java │ ├── SubstringWithConcatenationOfAllWordsBest.java │ ├── SubstringWithConcatenationOfAllWordsSlideWindow.java │ ├── SubstringWithConcatenationOfAllWordsSlideWindowOptimize.java │ ├── SwapNodesInPairs.java │ ├── ThirdNumBasic.java │ ├── ThirdNumOptimize.java │ ├── ThirdNumSortedAndTwoPointer.java │ ├── ThirdSumClosest.java │ ├── ThirdSumClosestOptimize.java │ ├── TwoNumSum.java │ ├── ValidParentheses.java │ ├── ValidParenthesesOptimize.java │ ├── ZigzagConversion.java │ ├── component │ ├── MyTreeSet.java │ ├── Node.java │ └── TreeNode.java │ ├── datastruct │ ├── array │ │ ├── T001_twoSum_V1_BF.java │ │ ├── T001_twoSum_V2_SortBinarySearch.java │ │ ├── T001_twoSum_V2_SortBinarySearch_ERR.java │ │ ├── T001_twoSum_V3_HashMap.java │ │ ├── T001_twoSum_V3_SortTwoPointer.java │ │ ├── T015_threeSum_V1_BF.java │ │ ├── T015_threeSum_V1_SortTwoPointer.java │ │ ├── T015_threeSum_V1_SortTwoPointerOpt.java │ │ ├── T016_threeSumClosest_V0_BF.java │ │ ├── T016_threeSumClosest_V1_SortTwoPointer.java │ │ ├── T018_fourSum_V1_BF.java │ │ ├── T018_fourSum_V2_SortAndTwoPointer.java │ │ ├── T128_longestConsecutiveSequence_V1.java │ │ ├── T136_SingleNumber_V1_HashMap.java │ │ ├── T136_SingleNumber_V2_HashSet.java │ │ ├── T136_SingleNumber_V3_BitOperator.java │ │ ├── T137_SingleNumberII_V1_HashMap.java │ │ ├── T137_SingleNumberII_V2_Sort.java │ │ ├── T137_SingleNumberII_V3_BitOperator.java │ │ ├── T167_twoSum_V1_BF.java │ │ ├── T167_twoSum_V2_SortBinarySearch.java │ │ ├── T167_twoSum_V3_HashMap.java │ │ ├── T167_twoSum_V4_TwoPointer.java │ │ ├── T217_ContainsDup_V1_HashMap.java │ │ ├── T217_ContainsDup_V2_Set.java │ │ ├── T217_ContainsDup_V2_Set2.java │ │ ├── T217_ContainsDup_V3_Sort.java │ │ ├── T219_ContainsDup_V1_HashMap.java │ │ ├── T219_ContainsDup_V2_SlideWindow.java │ │ ├── T220_ContainsDup_V1_SlideWindow.java │ │ ├── T220_ContainsDup_V2_SlideWindowAndSort.java │ │ ├── T220_ContainsDup_V3_SlideWindowAndTreeSet.java │ │ ├── T220_ContainsDup_V4_BucketSort.java │ │ ├── T252_meetingRoom_V1_BF.java │ │ ├── T252_meetingRoom_V2_Sort.java │ │ ├── T252_meetingRoom_V3_SweepLine.java │ │ ├── T252_meetingRoom_V4_PriorityQueue.java │ │ ├── T252_meetingRoot_V1_BF.java │ │ ├── T253_meetingRoom_V1_BF.java │ │ ├── T259_threeSumSmaller_V1_BF.java │ │ ├── T259_threeSumSmaller_V2_SortTwoPointer.java │ │ ├── T260_SingleNumberIII_V1_HashMap.java │ │ ├── T287_findDuplicate_V1_HashSet.java │ │ ├── T287_findDuplicate_V2_Sort.java │ │ ├── T442_findDuplicates_V1_HashMap.java │ │ ├── T442_findDuplicates_V2_HashSet.java │ │ ├── T442_findDuplicates_V3_Sort.java │ │ ├── T454_fourSumII_V1_BF.java │ │ ├── T454_fourSumII_V2_SortAndBinarySearch.java │ │ ├── T454_fourSumII_V3_HashMap.java │ │ ├── T454_fourSumII_V3_HashMapAndComparess.java │ │ ├── T51_maxSumSubArray_V1_PrefixSum.java │ │ ├── T51_maxSumSubArray_V1_TwoPointer.java │ │ ├── T51_maxSumSubArray_V3_Greedy.java │ │ ├── T51_maxSumSubArray_V4_DP.java │ │ ├── T653_twoSumIV_V1_PreOrderHashSet.java │ │ ├── T653_twoSumIV_V2_InOrderHashSet.java │ │ ├── T653_twoSumIV_V3_PostOrderHashSet.java │ │ ├── T653_twoSumIV_V4_levelOrderHashSet.java │ │ └── T653_twoSumIV_V5_levelOrderTwoPointer.java │ ├── package-info.java │ ├── queryopt │ │ ├── T1906_minDifference_V1_BF.java │ │ ├── T1906_minDifference_V2_subArraySort.java │ │ ├── T1906_minDifference_V3_binarySearch.java │ │ ├── T1906_minDifference_V4_prefixSum.java │ │ ├── T1906_minDifference_V5_mos.java │ │ ├── T1906_minDifference_V6_BIT.java │ │ └── T1906_minDifference_V7_SegmentTree.java │ └── sweepline │ │ ├── T1851_minInterval_V1_BF.java │ │ ├── T1851_minInterval_V2_Sort.java │ │ ├── T1851_minInterval_V3_Sort_BinarySearchKey.java │ │ ├── T1851_minInterval_V3_queryPreSort_queryOpt.java │ │ ├── T1851_minInterval_V4_SegmentTree.java │ │ ├── T223_rectangleArea_V1_overlapArea.java │ │ ├── T223_rectangleArea_V2_Sweepline.java │ │ ├── T3047_rectangleBiggestOverlapArea_V1_overlapArea.java │ │ ├── T3047_rectangleBiggestOverlapArea_V2_overlapAreaOpt.java │ │ ├── T3047_rectangleBiggestOverlapArea_V3_Sweepline.java │ │ ├── T391_perfectRectangle_v1_HashMap.java │ │ ├── T391_perfectRectangle_v1_HashSet.java │ │ ├── T836_rectangleOverlap_V1.java │ │ ├── T836_rectangleOverlap_V2_Sweepline.java │ │ ├── T836_rectangleOverlap_V2_overlapArea.java │ │ ├── T850_rectangleArea_v1_split.java │ │ ├── T850_rectangleArea_v2_sweepline.java │ │ └── T850_rectangleArea_v3_sweepline_yOpt.java │ ├── f500t600 │ ├── FibonacciNumber.java │ ├── FibonacciNumberBest.java │ ├── FibonacciNumberDp.java │ ├── FibonacciNumberDpOptimize.java │ ├── FibonacciNumberMath.java │ ├── T523_checkSubarraySum_V1_BF.java │ ├── T523_checkSubarraySum_V2_SameMod.java │ ├── T525_findMaxLength_V1_prefixSum.java │ ├── T525_findMaxLength_V2_prefixSumHashMap.java │ └── T560_subarraySum_V1_prefixSumHashMap.java │ ├── hard │ └── PermutationSequence.java │ ├── medium │ ├── BinaryTreeInorderTraversal.java │ ├── BinaryTreeInorderTraversalLoop.java │ ├── BinaryTreePostorderTraversal.java │ ├── BinaryTreePostorderTraversalLoop.java │ ├── BinaryTreePostorderTraversalLoopDebug.java │ ├── BinaryTreePreorderTraversal.java │ ├── BinaryTreePreorderTraversalLoop.java │ ├── BinaryTreePreorderTraversalLoopDebug.java │ ├── CombinationSum.java │ ├── CombinationSumBest.java │ ├── CombinationSumII.java │ ├── CombinationSumIIBest.java │ ├── Combinations.java │ ├── CountAndSay.java │ ├── DecodeWays.java │ ├── F100T200 │ │ ├── BinaryTreeLevelOrderTraversal.java │ │ ├── BinaryTreeLevelOrderTraversalII.java │ │ ├── BinaryTreeZigZagLevelOrderTraversal.java │ │ ├── CloneGraph.java │ │ ├── CloneGraphBFS.java │ │ ├── ConstructBinaryTreeFromInorderAndPostOrderTraversal.java │ │ ├── ConstructBinaryTreeFromPreorderAndInorderTraversal.java │ │ ├── ConvertSortedListToBinarySearchTree.java │ │ ├── ConvertSortedListToBinarySearchTreeBetter.java │ │ ├── ConvertSortedListToBinarySearchTreeForTest.java │ │ ├── FlattenBinaryTreeToLinkedList.java │ │ ├── FlattenBinaryTreeToLinkedListBetter.java │ │ ├── GasStation.java │ │ ├── PalindromePartitioning.java │ │ ├── PathSum.java │ │ ├── PathSumII.java │ │ ├── PathSumIIBest.java │ │ ├── PathSumIIBetter.java │ │ ├── PopulatingNextRightPointersInEachNode.java │ │ ├── PopulatingNextRightPointersInEachNodeBetter.java │ │ ├── PopulatingNextRightPointersInEachNodeII.java │ │ ├── PopulatingNextRightPointersInEachNodeIIBasic.java │ │ ├── PopulatingNextRightPointersInEachNodeIIBetter.java │ │ ├── SingleNumber.java │ │ ├── SingleNumberBest.java │ │ ├── SingleNumberBetter.java │ │ ├── SingleNumberII.java │ │ ├── SingleNumberIIBest.java │ │ ├── SumRootToLeafNums.java │ │ ├── SumRootToLeafNumsBetter.java │ │ ├── SurroundedRegionsDFS.java │ │ ├── TriangleDp.java │ │ ├── TriangleDpOptimize.java │ │ ├── TriangleDpReusage.java │ │ └── TriangleGreedy.java │ ├── FindFirstAndLastPosition.java │ ├── FindFirstAndLastPositionBest.java │ ├── FindFirstAndLastPositionBetter.java │ ├── GrayCode.java │ ├── GroupAnagrams.java │ ├── GroupAnagramsBest.java │ ├── InsertIntervals.java │ ├── InsertIntervalsWorst.java │ ├── InterleavingString.java │ ├── InterleavingStringBetter.java │ ├── InterleavingStringError.java │ ├── JumpGame.java │ ├── JumpGameII.java │ ├── JumpGameIIForward.java │ ├── MergeIntervals.java │ ├── MinPathSum.java │ ├── MinPathSumRecursion.java │ ├── MultiplyStrings.java │ ├── NextPermutation.java │ ├── PartitionList.java │ ├── PartitionListBetter.java │ ├── Permutations.java │ ├── PermutationsII.java │ ├── PowerxN.java │ ├── RemoveDuplicatesFromSortedListII.java │ ├── RemoveDuplicatesFromSortedListIIBest.java │ ├── RemoveDuplicatesFromSortedListIIWorst.java │ ├── RestoreIpAddresses.java │ ├── RotateImage.java │ ├── RotateList.java │ ├── RotateListBest.java │ ├── SearchA2dMatrix.java │ ├── SearchInRotatedSortedArray.java │ ├── SearchInRotatedSortedArrayII.java │ ├── SearchInRotatedSortedArrayOld.java │ ├── SetMatrixZeroes.java │ ├── SimplifyPath.java │ ├── SortColors.java │ ├── SpiralMatrix.java │ ├── SpiralMatrixII.java │ ├── SpiralMatrixIIBasic.java │ ├── Subsets.java │ ├── SubsetsII.java │ ├── T079_WordSearch.java │ ├── UniqueBinarySearchTrees.java │ ├── UniqueBinarySearchTreesBest.java │ ├── UniqueBinarySearchTreesII.java │ ├── UniquePaths.java │ ├── UniquePathsII.java │ ├── ValidBinarySearchTreeInOrderTraversal.java │ ├── ValidSoduku.java │ └── ValidateBinarySearchTree.java │ ├── package-info.java │ ├── sort │ └── InsertSortTest.java │ ├── topics │ ├── editdistance │ │ ├── T161_isOneEditDistance.java │ │ ├── T2542_twoEditWords_V1_BF.java │ │ ├── T2542_twoEditWords_V2_BF_OPT.java │ │ ├── T72_minDistanceList_V1_DP.java │ │ ├── T72_minDistance_V1_BF.java │ │ ├── T72_minDistance_V2_BF_memory.java │ │ ├── T72_minDistance_V3_DP.java │ │ └── T72_minDistance_V4_DP_memOpt.java │ └── package-info.java │ └── util │ ├── ListNodes.java │ └── MultiArrays.java └── test └── java └── com └── github └── houbb └── leetcode ├── AddTwoNumbersLeetCodeV2Test.java ├── AddTwoNumbersLeetCodeV3Test.java ├── AddTwoNumbersTest.java ├── ContainerWithMostWaterTest.java ├── FourSumTest.java ├── GenerateParenthesesTest.java ├── IntegerToRomanTest.java ├── LongestCommonPrefixTest.java ├── LongestPalindromicSubstringTest.java ├── LongestSubstringWithoutRepeatingCharactersTest.java ├── MedianOfTwoSortedArraysTest.java ├── MergeKSortedListsTest.java ├── MergeTwoSortedListsTest.java ├── RegularExpressionMatchingTest.java ├── RemoveNthNodeFromEndOfListTest.java ├── ReverseIntegerTest.java ├── ReverseNodesInKGroupTest.java ├── RomanToIntegerTest.java ├── SwapNodesInPairsTest.java ├── T008StringToIntegerAtoiTest.java ├── ThirdNumTest.java ├── ThirdSumClosestTest.java ├── ValidParenthesesTest.java ├── ZigzagConversionTest.java └── sort └── InsertSortTest.java /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-ci -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # maven ignore 2 | target/ 3 | *.jar 4 | *.war 5 | *.zip 6 | *.tar 7 | *.tar.gz 8 | 9 | # eclipse ignore 10 | .settings/ 11 | .project 12 | .classpath 13 | 14 | # idea ignore 15 | .idea/ 16 | *.ipr 17 | *.iml 18 | *.iws 19 | 20 | # temp ignore 21 | *.log 22 | *.cache 23 | *.diff 24 | *.patch 25 | *.tmp 26 | *.java~ 27 | *.properties~ 28 | *.xml~ 29 | 30 | # system ignore 31 | .DS_Store 32 | Thumbs.db 33 | 34 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk8 4 | install: mvn install -DskipTests=true -Dmaven.javadoc.skip=true 5 | script: mvn test 6 | after_success: 7 | - mvn clean cobertura:cobertura coveralls:report 8 | 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 变更日志 2 | 3 | | 类型 | 说明 | 4 | |:----|:----| 5 | | A | 新增 | 6 | | U | 更新 | 7 | | D | 删除 | 8 | | T | 测试 | 9 | | O | 优化 | 10 | | F | 修复BUG | 11 | 12 | # release_0.0.1 13 | 14 | | 序号 | 变更类型 | 说明 | 时间 | 备注 | 15 | |:---|:---|:---|:---|:--| 16 | | 1 | A | 基本功能的实现 | 2020-5-12 21:06:00 | | -------------------------------------------------------------------------------- /cgit.bat: -------------------------------------------------------------------------------- 1 | :: 用于提交当前变更(windows) 2 | :: author: houbb 3 | :: LastUpdateTime: 2018-11-22 09:08:52 4 | :: 用法:双击运行,或者当前路径 cmd 直接输入 .\cgit.bat 5 | 6 | git pull 7 | git add . 8 | git commit -m "[Feature] add for new" 9 | git push 10 | git status 11 | 12 | -------------------------------------------------------------------------------- /cgit.sh: -------------------------------------------------------------------------------- 1 | # 提交 2 | 3 | git pull 4 | git add . 5 | git commit -m "[Feature] add for new" 6 | git push 7 | git status 8 | 9 | # 1. 赋值权限: chmod +x ./cgit.sh 10 | # 2. 执行: ./cgit.sh 11 | # Last Update Time: 2018-11-21 21:55:38 12 | # Author: houbb -------------------------------------------------------------------------------- /doc/001-100/001-two-num-sum.md: -------------------------------------------------------------------------------- 1 | Given an array of integers, return indices of the two numbers such that they add up to a specific target. 2 | 3 | You may assume that each input would have exactly one solution, and you may not use the same element twice. 4 | 5 | Example: 6 | 7 | ``` 8 | Given nums = [2, 7, 11, 15], target = 9, 9 | 10 | Because nums[0] + nums[1] = 2 + 7 = 9, 11 | return [0, 1]. 12 | ``` 13 | 14 | https://leetcode.com/problems/two-sum/ -------------------------------------------------------------------------------- /doc/001-100/002-add-two-numbers.md: -------------------------------------------------------------------------------- 1 | You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. 2 | 3 | You may assume the two numbers do not contain any leading zero, except the number 0 itself. 4 | 5 | Example: 6 | 7 | Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) 8 | Output: 7 -> 0 -> 8 9 | Explanation: 342 + 465 = 807. 10 | 11 | https://leetcode.com/problems/add-two-numbers/ -------------------------------------------------------------------------------- /doc/001-100/003-longest-substring-without-repeating-characters.md: -------------------------------------------------------------------------------- 1 | Given a string, find the length of the longest substring without repeating characters. 2 | 3 | Example 1: 4 | 5 | Input: "abcabcbb" 6 | Output: 3 7 | Explanation: The answer is "abc", with the length of 3. 8 | Example 2: 9 | 10 | Input: "bbbbb" 11 | Output: 1 12 | Explanation: The answer is "b", with the length of 1. 13 | Example 3: 14 | 15 | Input: "pwwkew" 16 | Output: 3 17 | Explanation: The answer is "wke", with the length of 3. 18 | Note that the answer must be a substring, "pwke" is a subsequence and not a substring. -------------------------------------------------------------------------------- /doc/001-100/005-longest-palindromic-substring.md: -------------------------------------------------------------------------------- 1 | Given a string s, find the longest palindromic substring(回文子串) in s. You may assume that the maximum length of s is 1000. 2 | 3 | Example 1: 4 | 5 | ``` 6 | Input: "babad" 7 | Output: "bab" 8 | Note: "aba" is also a valid answer. 9 | ``` 10 | 11 | Example 2: 12 | 13 | ``` 14 | Input: "cbbd" 15 | Output: "bb" 16 | ``` 17 | 18 | https://leetcode.com/problems/longest-palindromic-substring/ -------------------------------------------------------------------------------- /doc/001-100/006-zigzag-conversion.md: -------------------------------------------------------------------------------- 1 | The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) 2 | 3 | ``` 4 | P A H N 5 | A P L S I I G 6 | Y I R 7 | ``` 8 | 9 | And then read line by line: "PAHNAPLSIIGYIR" 10 | 11 | Write the code that will take a string and make this conversion given a number of rows: 12 | 13 | string convert(string s, int numRows); 14 | Example 1: 15 | 16 | ``` 17 | Input: s = "PAYPALISHIRING", numRows = 3 18 | Output: "PAHNAPLSIIGYIR" 19 | ``` 20 | 21 | Example 2: 22 | 23 | ``` 24 | Input: s = "PAYPALISHIRING", numRows = 4 25 | Output: "PINALSIGYAHRPI" 26 | Explanation: 27 | 28 | P I N 29 | A L S I G 30 | Y A H R 31 | P I 32 | ``` 33 | 34 | https://leetcode.com/problems/zigzag-conversion/ -------------------------------------------------------------------------------- /doc/001-100/007-reverse-integer.md: -------------------------------------------------------------------------------- 1 | Given a 32-bit signed integer, reverse digits of an integer. 2 | 3 | Example 1: 4 | 5 | ``` 6 | Input: 123 7 | Output: 321 8 | ``` 9 | 10 | Example 2: 11 | 12 | ``` 13 | Input: -123 14 | Output: -321 15 | ``` 16 | 17 | Example 3: 18 | 19 | ``` 20 | Input: 120 21 | Output: 21 22 | ``` 23 | 24 | Note: 25 | Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−2^31, 2^31 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows. -------------------------------------------------------------------------------- /doc/001-100/009-palindrome-number.md: -------------------------------------------------------------------------------- 1 | Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. 2 | 3 | Example 1: 4 | 5 | ``` 6 | Input: 121 7 | Output: true 8 | ``` 9 | 10 | Example 2: 11 | 12 | ``` 13 | Input: -121 14 | Output: false 15 | ``` 16 | 17 | Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome. 18 | Example 3: 19 | 20 | ``` 21 | Input: 10 22 | Output: false 23 | ``` 24 | 25 | Explanation: Reads 01 from right to left. Therefore it is not a palindrome. 26 | 27 | Follow up: 28 | 29 | Coud you solve it without converting the integer to a string? -------------------------------------------------------------------------------- /doc/001-100/011-container-with-most-water.md: -------------------------------------------------------------------------------- 1 | Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. 2 | 3 | Note: You may not slant(倾斜) the container and n is at least 2. 4 | 5 |  -------------------------------------------------------------------------------- /doc/001-100/014-longest-common-prefix.md: -------------------------------------------------------------------------------- 1 | Write a function to find the longest common prefix string amongst an array of strings. 2 | 3 | If there is no common prefix, return an empty string "". 4 | 5 | Example 1: 6 | 7 | ``` 8 | Input: ["flower","flow","flight"] 9 | Output: "fl" 10 | ``` 11 | 12 | Example 2: 13 | 14 | ``` 15 | Input: ["dog","racecar","car"] 16 | Output: "" 17 | ``` 18 | 19 | Explanation: There is no common prefix among the input strings. 20 | 21 | Note: 22 | 23 | All given inputs are in lowercase letters a-z. -------------------------------------------------------------------------------- /doc/001-100/015-3num.md: -------------------------------------------------------------------------------- 1 | Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. 2 | 3 | Note: 4 | 5 | The solution set must not contain duplicate triplets. 6 | 7 | Example: 8 | 9 | ``` 10 | Given array nums = [-1, 0, 1, 2, -1, -4], 11 | 12 | A solution set is: 13 | [ 14 | [-1, 0, 1], 15 | [-1, -1, 2] 16 | ] 17 | ``` -------------------------------------------------------------------------------- /doc/001-100/016-3sum-closest.md: -------------------------------------------------------------------------------- 1 | Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. 2 | 3 | You may assume that each input would have exactly one solution. 4 | 5 | Example 1: 6 | 7 | ``` 8 | Input: nums = [-1,2,1,-4], target = 1 9 | Output: 2 10 | Explanation: The sum that is closest to the target is 2. (-1 + 2 + 1 = 2). 11 | ``` 12 | 13 | Constraints: 14 | 15 | ``` 16 | 3 <= nums.length <= 10^3 17 | -10^3 <= nums[i] <= 10^3 18 | -10^4 <= target <= 10^4 19 | ``` 20 | -------------------------------------------------------------------------------- /doc/001-100/017-letter-combinations-of-a-phone-number.md: -------------------------------------------------------------------------------- 1 | Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. 2 | 3 | A mapping of digit to letters (just like on the telephone buttons) is given below. 4 | 5 | Note that 1 does not map to any letters. 6 | 7 | Example: 8 | 9 | ``` 10 | Input: "23" 11 | Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]. 12 | ``` 13 | 14 | Note: 15 | 16 | Although the above answer is in lexicographical order, your answer could be in any order you want. 17 | 18 | -------------------------------------------------------------------------------- /doc/001-100/018-4sum.md: -------------------------------------------------------------------------------- 1 | Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? 2 | 3 | Find all unique quadruplets in the array which gives the sum of target. 4 | 5 | Note: 6 | 7 | The solution set must not contain duplicate quadruplets. 8 | 9 | Example: 10 | 11 | ``` 12 | Given array nums = [1, 0, -1, 0, -2, 2], and target = 0. 13 | 14 | A solution set is: 15 | [ 16 | [-1, 0, 0, 1], 17 | [-2, -1, 1, 2], 18 | [-2, 0, 0, 2] 19 | ] 20 | ``` -------------------------------------------------------------------------------- /doc/001-100/019-remove-nth-node-from-end-of-list.md: -------------------------------------------------------------------------------- 1 | Given a linked list, remove the n-th node from the end of list and return its head. 2 | 3 | Example: 4 | 5 | ``` 6 | Given linked list: 1->2->3->4->5, and n = 2. 7 | 8 | After removing the second node from the end, the linked list becomes 1->2->3->5. 9 | ``` 10 | 11 | Note: 12 | 13 | Given n will always be valid. 14 | 15 | Follow up: 16 | 17 | Could you do this in one pass? -------------------------------------------------------------------------------- /doc/001-100/020-valid-parentheses.md: -------------------------------------------------------------------------------- 1 | Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. 2 | 3 | An input string is valid if: 4 | 5 | Open brackets must be closed by the same type of brackets. 6 | 7 | Open brackets must be closed in the correct order. 8 | 9 | Note that an empty string is also considered valid. 10 | 11 | Example 1: 12 | 13 | ``` 14 | Input: "()" 15 | Output: true 16 | ``` 17 | 18 | Example 2: 19 | 20 | ``` 21 | Input: "()[]{}" 22 | Output: true 23 | ``` 24 | 25 | Example 3: 26 | 27 | ``` 28 | Input: "(]" 29 | Output: false 30 | ``` 31 | 32 | Example 4: 33 | 34 | ``` 35 | Input: "([)]" 36 | Output: false 37 | ``` 38 | 39 | Example 5: 40 | 41 | ``` 42 | Input: "{[]}" 43 | Output: true 44 | ``` 45 | 46 | https://leetcode.com/problems/valid-parentheses/ -------------------------------------------------------------------------------- /doc/001-100/021-merge-two-sorted-lists.md: -------------------------------------------------------------------------------- 1 | Merge two sorted linked lists and return it as a new sorted list. 2 | 3 | The new list should be made by splicing together the nodes of the first two lists. 4 | 5 | Example: 6 | 7 | ``` 8 | Input: 1->2->4, 1->3->4 9 | Output: 1->1->2->3->4->4 10 | ``` 11 | 12 | https://leetcode.com/problems/merge-two-sorted-lists/ -------------------------------------------------------------------------------- /doc/001-100/022-generate-parentheses.md: -------------------------------------------------------------------------------- 1 | Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. 2 | 3 | For example, given n = 3, a solution set is: 4 | 5 | ``` 6 | [ 7 | "((()))", 8 | "(()())", 9 | "(())()", 10 | "()(())", 11 | "()()()" 12 | ] 13 | ``` -------------------------------------------------------------------------------- /doc/001-100/023-merge-k-sorted-lists.md: -------------------------------------------------------------------------------- 1 | Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 2 | 3 | Example: 4 | 5 | ``` 6 | Input: 7 | [ 8 | 1->4->5, 9 | 1->3->4, 10 | 2->6 11 | ] 12 | Output: 1->1->2->3->4->4->5->6 13 | ``` 14 | 15 | -------------------------------------------------------------------------------- /doc/001-100/024-swap-nodes-in-pairs.md: -------------------------------------------------------------------------------- 1 | Given a linked list, swap every two adjacent nodes and return its head. 2 | 3 | You may not modify the values in the list's nodes, only nodes itself may be changed. 4 | 5 | Example: 6 | 7 | ``` 8 | Given 1->2->3->4, you should return the list as 2->1->4->3. 9 | ``` -------------------------------------------------------------------------------- /doc/001-100/025-reverse-nodes-in-k-group.md: -------------------------------------------------------------------------------- 1 | Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. 2 | 3 | k is a positive integer and is less than or equal to the length of the linked list. 4 | 5 | If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is. 6 | 7 | Example: 8 | 9 | ``` 10 | Given this linked list: 1->2->3->4->5 11 | 12 | For k = 2, you should return: 2->1->4->3->5 13 | 14 | For k = 3, you should return: 3->2->1->4->5 15 | ``` 16 | 17 | Note: 18 | 19 | Only constant extra memory is allowed. 20 | 21 | You may not alter the values in the list's nodes, only nodes itself may be changed. -------------------------------------------------------------------------------- /doc/001-100/028-implement-strstr.md: -------------------------------------------------------------------------------- 1 | Implement strStr(). 2 | 3 | Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 4 | 5 | Example 1: 6 | 7 | ``` 8 | Input: haystack = "hello", needle = "ll" 9 | Output: 2 10 | ``` 11 | 12 | Example 2: 13 | 14 | ``` 15 | Input: haystack = "aaaaa", needle = "bba" 16 | Output: -1 17 | ``` 18 | 19 | Clarification: 20 | 21 | What should we return when needle is an empty string? This is a great question to ask during an interview. 22 | 23 | For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C's strstr() and Java's indexOf(). -------------------------------------------------------------------------------- /doc/001-100/029-divide-two-integers.md: -------------------------------------------------------------------------------- 1 | Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator. 2 | 3 | Return the quotient after dividing dividend by divisor. 4 | 5 | The integer division should truncate toward zero, which means losing its fractional part. 6 | 7 | For example, truncate(8.345) = 8 and truncate(-2.7335) = -2. 8 | 9 | Example 1: 10 | 11 | ``` 12 | Input: dividend = 10, divisor = 3 13 | Output: 3 14 | Explanation: 10/3 = truncate(3.33333..) = 3. 15 | ``` 16 | 17 | Example 2: 18 | 19 | ``` 20 | Input: dividend = 7, divisor = -3 21 | Output: -2 22 | Explanation: 7/-3 = truncate(-2.33333..) = -2. 23 | ``` 24 | 25 | Note: 26 | 27 | Both dividend and divisor will be 32-bit signed integers. 28 | 29 | The divisor will never be 0. 30 | 31 | Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−2^31, 2^31 − 1]. 32 | 33 | For the purpose of this problem, assume that your function returns 2^31 − 1 when the division result overflows. 34 | -------------------------------------------------------------------------------- /doc/001-100/030-substring-with-concatenation-of-all-words.md: -------------------------------------------------------------------------------- 1 | 串联所有单词的子串 2 | 3 | 给定一个字符串 s 和一些长度相同的单词 words。 4 | 5 | 找出 s 中恰好可以由 words 中所有单词串联形成的子串的起始位置。 6 | 7 | 注意子串要与words 中的单词完全匹配,中间不能有其他字符,但不需要考虑 words 中单词串联的顺序。 8 | 9 | 示例 1: 10 | 11 | ``` 12 | 输入: 13 | s = "barfoothefoobarman", 14 | words = ["foo","bar"] 15 | 输出:[0,9] 16 | 解释: 17 | 从索引 0 和 9 开始的子串分别是 "barfoo" 和 "foobar" 。 18 | 输出的顺序不重要, [9,0] 也是有效答案。 19 | ``` 20 | 21 | 示例 2: 22 | 23 | ``` 24 | 输入: 25 | s = "wordgoodgoodgoodbestword", 26 | words = ["word","good","best","word"] 27 | 输出:[] 28 | ``` 29 | 30 | 来源:力扣(LeetCode) 31 | 链接:https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words 32 | 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 -------------------------------------------------------------------------------- /doc/001-100/032-longest-valid-parentheses.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/longest-valid-parentheses/ 2 | 3 | Given a string containing just the characters '(' and ')', 4 | return the length of the longest valid (well-formed) parentheses substring. 5 | 6 | ## EX 7 | 8 | Example 1: 9 | 10 | ``` 11 | Input: s = "(()" 12 | Output: 2 13 | Explanation: The longest valid parentheses substring is "()". 14 | ``` 15 | 16 | Example 2: 17 | 18 | ``` 19 | Input: s = ")()())" 20 | Output: 4 21 | Explanation: The longest valid parentheses substring is "()()". 22 | ``` 23 | 24 | Example 3: 25 | 26 | ``` 27 | Input: s = "" 28 | Output: 0 29 | ``` 30 | 31 | ## Constraints: 32 | 33 | 0 <= s.length <= 3 * 104 34 | s[i] is '(', or ')'. 35 | -------------------------------------------------------------------------------- /doc/001-100/034-find-first-and-last-position-of-element-in-sorted-array.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ 2 | 3 | Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value. 4 | 5 | If target is not found in the array, return [-1, -1]. 6 | 7 | Follow up: Could you write an algorithm with O(log n) runtime complexity? 8 | 9 | 10 | 11 | Example 1: 12 | 13 | Input: nums = [5,7,7,8,8,10], target = 8 14 | Output: [3,4] 15 | Example 2: 16 | 17 | Input: nums = [5,7,7,8,8,10], target = 6 18 | Output: [-1,-1] 19 | Example 3: 20 | 21 | Input: nums = [], target = 0 22 | Output: [-1,-1] 23 | 24 | 25 | Constraints: 26 | 27 | 0 <= nums.length <= 105 28 | -109 <= nums[i] <= 109 29 | nums is a non-decreasing array. 30 | -109 <= target <= 109 -------------------------------------------------------------------------------- /doc/001-100/035-search-insert-position.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/search-insert-position/ 2 | 3 | Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. 4 | 5 | You must write an algorithm with O(log n) runtime complexity. 6 | 7 | ## EX 8 | 9 | Example 1: 10 | 11 | ``` 12 | Input: nums = [1,3,5,6], target = 5 13 | Output: 2 14 | ``` 15 | 16 | Example 2: 17 | 18 | ``` 19 | Input: nums = [1,3,5,6], target = 2 20 | Output: 1 21 | ``` 22 | 23 | Example 3: 24 | 25 | ``` 26 | Input: nums = [1,3,5,6], target = 7 27 | Output: 4 28 | ``` 29 | 30 | ## Constraints: 31 | 32 | 1 <= nums.length <= 10^4 33 | -10^4 <= nums[i] <= 10^4 34 | nums contains distinct values sorted in ascending order. 35 | -10^4 <= target <= 10^4 36 | -------------------------------------------------------------------------------- /doc/001-100/040-combination-sum-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/combination-sum-ii/ 2 | 3 | 4 | Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target. 5 | 6 | Each number in candidates may only be used once in the combination. 7 | 8 | Note: The solution set must not contain duplicate combinations. 9 | 10 | 11 | 12 | Example 1: 13 | 14 | Input: candidates = [10,1,2,7,6,1,5], target = 8 15 | Output: 16 | [ 17 | [1,1,6], 18 | [1,2,5], 19 | [1,7], 20 | [2,6] 21 | ] 22 | Example 2: 23 | 24 | Input: candidates = [2,5,2,1,2], target = 5 25 | Output: 26 | [ 27 | [1,2,2], 28 | [5] 29 | ] 30 | 31 | 32 | Constraints: 33 | 34 | 1 <= candidates.length <= 100 35 | 1 <= candidates[i] <= 50 36 | 1 <= target <= 30 -------------------------------------------------------------------------------- /doc/001-100/041-first-missing-positive.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/first-missing-positive/ 2 | 3 | Given an unsorted integer array nums, return the smallest missing positive integer. 4 | 5 | You must implement an algorithm that runs in O(n) time and uses constant extra space. 6 | 7 | ## Ex 8 | 9 | Example 1: 10 | 11 | ``` 12 | Input: nums = [1,2,0] 13 | Output: 3 14 | Explanation: The numbers in the range [1,2] are all in the array. 15 | ``` 16 | 17 | Example 2: 18 | 19 | ``` 20 | Input: nums = [3,4,-1,1] 21 | Output: 2 22 | Explanation: 1 is in the array but 2 is missing. 23 | ``` 24 | 25 | Example 3: 26 | 27 | ``` 28 | Input: nums = [7,8,9,11,12] 29 | Output: 1 30 | Explanation: The smallest positive integer 1 is missing. 31 | ``` 32 | 33 | ## Constraints: 34 | 35 | 1 <= nums.length <= 10^5 36 | 37 | -2^31 <= nums[i] <= 2^31 - 1 38 | -------------------------------------------------------------------------------- /doc/001-100/042-trapping-rain-water.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/trapping-rain-water/ 2 | 3 | 4 | 42. Trapping Rain Water 5 | 6 | Given n non-negative integers representing an elevation map where the width of each bar is 1, 7 | compute how much water it can trap after raining. 8 | 9 | ## EX 10 | 11 | Example 1: 12 | 13 | ``` 14 | Input: height = [0,1,0,2,1,0,1,3,2,1,2,1] 15 | Output: 6 16 | Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. 17 | ``` 18 | 19 | Example 2: 20 | 21 | ``` 22 | Input: height = [4,2,0,3,2,5] 23 | Output: 9 24 | ``` 25 | 26 | ## Constraints: 27 | 28 | n == height.length 29 | 30 | 1 <= n <= 2 * 10^4 31 | 32 | 0 <= height[i] <= 10^5 33 | -------------------------------------------------------------------------------- /doc/001-100/043-multiply-strings.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/multiply-strings/ 2 | 3 | 4 | Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string. 5 | 6 | Note: You must not use any built-in BigInteger library or convert the inputs to integer directly. 7 | 8 | 9 | 10 | Example 1: 11 | 12 | Input: num1 = "2", num2 = "3" 13 | Output: "6" 14 | 15 | Example 2: 16 | 17 | Input: num1 = "123", num2 = "456" 18 | Output: "56088" 19 | 20 | 21 | Constraints: 22 | 23 | 1 <= num1.length, num2.length <= 200 24 | num1 and num2 consist of digits only. 25 | Both num1 and num2 do not contain any leading zero, except the number 0 itself. 26 | -------------------------------------------------------------------------------- /doc/001-100/044-wildcard-matching.md: -------------------------------------------------------------------------------- 1 | 44. Wildcard Matching 2 | 3 | Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where: 4 | 5 | '?' Matches any single character. 6 | 7 | '*' Matches any sequence of characters (including the empty sequence). 8 | 9 | The matching should cover the entire input string (not partial). 10 | 11 | ## Ex 12 | 13 | Example 1: 14 | 15 | ``` 16 | Input: s = "aa", p = "a" 17 | Output: false 18 | Explanation: "a" does not match the entire string "aa". 19 | ``` 20 | 21 | Example 2: 22 | 23 | ``` 24 | Input: s = "aa", p = "*" 25 | Output: true 26 | Explanation: '*' matches any sequence. 27 | ``` 28 | 29 | Example 3: 30 | 31 | ``` 32 | Input: s = "cb", p = "?a" 33 | Output: false 34 | Explanation: '?' matches 'c', but the second letter is 'a', which does not match 'b'. 35 | ``` 36 | 37 | ## Constraints: 38 | 39 | 0 <= s.length, p.length <= 2000 40 | 41 | s contains only lowercase English letters. 42 | 43 | p contains only lowercase English letters, '?' or '*'. 44 | 45 | -------------------------------------------------------------------------------- /doc/001-100/045-jump-game-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/jump-game-ii/ 2 | 3 | 4 | Given an array of non-negative integers nums, you are initially positioned at the first index of the array. 5 | 6 | Each element in the array represents your maximum jump length at that position. 7 | 8 | Your goal is to reach the last index in the minimum number of jumps. 9 | 10 | You can assume that you can always reach the last index. 11 | 12 | 13 | 14 | Example 1: 15 | 16 | Input: nums = [2,3,1,1,4] 17 | Output: 2 18 | Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index. 19 | Example 2: 20 | 21 | Input: nums = [2,3,0,1,4] 22 | Output: 2 23 | 24 | 25 | Constraints: 26 | 27 | 1 <= nums.length <= 1000 28 | 0 <= nums[i] <= 105 -------------------------------------------------------------------------------- /doc/001-100/046-permutations.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/permutations/ 2 | 3 | 4 | Given an array nums of distinct integers, return all the possible permutations. 5 | 6 | You can return the answer in any order. 7 | 8 | 9 | 10 | Example 1: 11 | 12 | Input: nums = [1,2,3] 13 | Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] 14 | Example 2: 15 | 16 | Input: nums = [0,1] 17 | Output: [[0,1],[1,0]] 18 | Example 3: 19 | 20 | Input: nums = [1] 21 | Output: [[1]] 22 | 23 | 24 | Constraints: 25 | 26 | 1 <= nums.length <= 6 27 | -10 <= nums[i] <= 10 28 | All the integers of nums are unique. 29 | -------------------------------------------------------------------------------- /doc/001-100/047-permutations-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/permutations-ii/ 2 | 3 | 4 | Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order. 5 | 6 | 7 | 8 | Example 1: 9 | 10 | Input: nums = [1,1,2] 11 | Output: 12 | [[1,1,2], 13 | [1,2,1], 14 | [2,1,1]] 15 | Example 2: 16 | 17 | Input: nums = [1,2,3] 18 | Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] 19 | 20 | 21 | Constraints: 22 | 23 | 1 <= nums.length <= 8 24 | -10 <= nums[i] <= 10 -------------------------------------------------------------------------------- /doc/001-100/048-rotate-image.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/rotate-image/ 2 | 3 | You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). 4 | 5 | You have to rotate the image in-place, which means you have to modify the input 2D matrix directly. 6 | 7 | DO NOT allocate another 2D matrix and do the rotation. 8 | 9 | Example 1: 10 | 11 |  12 | 13 | 14 | ``` 15 | Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] 16 | Output: [[7,4,1],[8,5,2],[9,6,3]] 17 | ``` 18 | 19 | Example 2: 20 | 21 |  22 | 23 | ``` 24 | Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]] 25 | Output: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]] 26 | ``` 27 | 28 | ps: 实际上这是图片处理非常有用的一种算法,常见的图片旋转就是这么实现的。 29 | 30 | Constraints: 31 | 32 | matrix.length == n 33 | matrix[i].length == n 34 | 1 <= n <= 20 35 | -1000 <= matrix[i][j] <= 1000 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /doc/001-100/049-group-anagrams.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/group-anagrams/ 2 | 3 | Given an array of strings strs, group the anagrams together. You can return the answer in any order. 4 | 5 | An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. 6 | 7 | 8 | 9 | Example 1: 10 | 11 | Input: strs = ["eat","tea","tan","ate","nat","bat"] 12 | Output: [["bat"],["nat","tan"],["ate","eat","tea"]] 13 | Example 2: 14 | 15 | Input: strs = [""] 16 | Output: [[""]] 17 | Example 3: 18 | 19 | Input: strs = ["a"] 20 | Output: [["a"]] 21 | 22 | 23 | Constraints: 24 | 25 | 1 <= strs.length <= 104 26 | 0 <= strs[i].length <= 100 27 | strs[i] consists of lower-case English letters. 28 | -------------------------------------------------------------------------------- /doc/001-100/050-powerxn.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/powx-n/ 2 | 3 | Implement pow(x, n), which calculates x raised to the power n (i.e. xn). 4 | 5 | 6 | 7 | Example 1: 8 | 9 | Input: x = 2.00000, n = 10 10 | Output: 1024.00000 11 | Example 2: 12 | 13 | Input: x = 2.10000, n = 3 14 | Output: 9.26100 15 | Example 3: 16 | 17 | Input: x = 2.00000, n = -2 18 | Output: 0.25000 19 | Explanation: 2-2 = 1/22 = 1/4 = 0.25 20 | 21 | 22 | Constraints: 23 | 24 | -100.0 < x < 100.0 25 | -231 <= n <= 231-1 26 | -104 <= xn <= 104 -------------------------------------------------------------------------------- /doc/001-100/051-n-queens.md: -------------------------------------------------------------------------------- 1 | The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. 2 | 3 | Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any order. 4 | 5 | Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space, respectively. 6 | 7 | ## EX 8 | 9 | Example 1: 10 | 11 |  12 | 13 | ``` 14 | Input: n = 4 15 | Output: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]] 16 | Explanation: There exist two distinct solutions to the 4-queens puzzle as shown above 17 | ``` 18 | 19 | Example 2: 20 | 21 | ``` 22 | Input: n = 1 23 | Output: [["Q"]] 24 | ``` 25 | 26 | ## Constraints: 27 | 28 | 1 <= n <= 9 29 | -------------------------------------------------------------------------------- /doc/001-100/052-n-queens-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/n-queens-ii/ 2 | 3 | The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. 4 | 5 | Given an integer n, return the number of distinct solutions to the n-queens puzzle. 6 | 7 | ## EX 8 | 9 | Example 1: 10 | 11 |  12 | 13 | ``` 14 | Input: n = 4 15 | Output: 2 16 | Explanation: There are two distinct solutions to the 4-queens puzzle as shown. 17 | ``` 18 | 19 | Example 2: 20 | 21 | ``` 22 | Input: n = 1 23 | Output: 1 24 | ``` 25 | 26 | ## Constraints: 27 | 28 | 1 <= n <= 9 29 | 30 | PS: 个人感觉这一题的设计比较失败,在 51 的基础上,很容易解出来。 31 | -------------------------------------------------------------------------------- /doc/001-100/053-maximum-subarray.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/maximum-subarray/ 2 | 3 | Given an integer array nums, find the subarray with the largest sum, and return its sum. 4 | 5 | Example 1: 6 | 7 | ``` 8 | Input: nums = [-2,1,-3,4,-1,2,1,-5,4] 9 | Output: 6 10 | Explanation: The subarray [4,-1,2,1] has the largest sum 6. 11 | ``` 12 | 13 | Example 2: 14 | 15 | ``` 16 | Input: nums = [1] 17 | Output: 1 18 | Explanation: The subarray [1] has the largest sum 1. 19 | ``` 20 | 21 | Example 3: 22 | 23 | ``` 24 | Input: nums = [5,4,-1,7,8] 25 | Output: 23 26 | Explanation: The subarray [5,4,-1,7,8] has the largest sum 23. 27 | ``` 28 | 29 | Constraints: 30 | 31 | 1 <= nums.length <= 10^5 32 | -104 <= nums[i] <= 10^4 33 | 34 | Follow up: If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle. 35 | -------------------------------------------------------------------------------- /doc/001-100/054-spiral-matrix.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/spiral-matrix 2 | 3 | Given an m x n matrix, return all elements of the matrix in spiral order. 4 | 5 | Example 1: 6 | 7 |  8 | 9 | ``` 10 | Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] 11 | Output: [1,2,3,6,9,8,7,4,5] 12 | ``` 13 | 14 | Example 2: 15 | 16 | 17 |  18 | 19 | ``` 20 | Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] 21 | Output: [1,2,3,4,8,12,11,10,9,5,6,7] 22 | ``` 23 | 24 | Constraints: 25 | 26 | m == matrix.length 27 | n == matrix[i].length 28 | 1 <= m, n <= 10 29 | -100 <= matrix[i][j] <= 100 -------------------------------------------------------------------------------- /doc/001-100/055-jump-game.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/jump-game/ 2 | 3 | Given an array of non-negative integers nums, you are initially positioned at the first index of the array. 4 | 5 | Each element in the array represents your maximum jump length at that position. 6 | 7 | Determine if you are able to reach the last index. 8 | 9 | 10 | 11 | Example 1: 12 | 13 | Input: nums = [2,3,1,1,4] 14 | Output: true 15 | Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index. 16 | Example 2: 17 | 18 | Input: nums = [3,2,1,0,4] 19 | Output: false 20 | Explanation: You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index. 21 | 22 | 23 | Constraints: 24 | 25 | 1 <= nums.length <= 3 * 10^4 26 | 0 <= nums[i] <= 105 -------------------------------------------------------------------------------- /doc/001-100/056-merge-intervals.md: -------------------------------------------------------------------------------- 1 | Given an array of intervals where intervals[i] = [starti, endi], 2 | merge all overlapping intervals, and return an array of the 3 | non-overlapping intervals that cover all the intervals in the input. 4 | 5 | 6 | 7 | Example 1: 8 | 9 | Input: intervals = [[1,3],[2,6],[8,10],[15,18]] 10 | Output: [[1,6],[8,10],[15,18]] 11 | Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6]. 12 | Example 2: 13 | 14 | Input: intervals = [[1,4],[4,5]] 15 | Output: [[1,5]] 16 | Explanation: Intervals [1,4] and [4,5] are considered overlapping. 17 | 18 | 19 | Constraints: 20 | 21 | 1 <= intervals.length <= 104 22 | intervals[i].length == 2 23 | 0 <= starti <= endi <= 104 -------------------------------------------------------------------------------- /doc/001-100/058-length-of-last-word.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/length-of-last-word/ 2 | 3 | Given a string s consisting of words and spaces, return the length of the last word in the string. 4 | 5 | A word is a maximal substring consisting of non-space characters only. 6 | 7 | Example 1: 8 | 9 | ``` 10 | Input: s = "Hello World" 11 | Output: 5 12 | Explanation: The last word is "World" with length 5. 13 | ``` 14 | 15 | Example 2: 16 | ``` 17 | Input: s = " fly me to the moon " 18 | Output: 4 19 | Explanation: The last word is "moon" with length 4. 20 | ``` 21 | 22 | Example 3: 23 | 24 | ``` 25 | Input: s = "luffy is still joyboy" 26 | Output: 6 27 | Explanation: The last word is "joyboy" with length 6. 28 | ``` 29 | 30 | Constraints: 31 | 32 | 1 <= s.length <= 10^4 33 | s consists of only English letters and spaces ' '. 34 | There will be at least one word in s. 35 | -------------------------------------------------------------------------------- /doc/001-100/059-spiral-matrix-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/spiral-matrix-ii/ 2 | 3 | Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order. 4 | 5 | 6 | 7 | Example 1: 8 | 9 |  10 | 11 | Input: n = 3 12 | Output: [[1,2,3],[8,9,4],[7,6,5]] 13 | Example 2: 14 | 15 | Input: n = 1 16 | Output: [[1]] 17 | 18 | 19 | Constraints: 20 | 21 | 1 <= n <= 20 -------------------------------------------------------------------------------- /doc/001-100/060-permutation-sequence.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/permutation-sequence/ 2 | 3 | 4 | The set [1, 2, 3, ..., n] contains a total of n! unique permutations. 5 | 6 | By listing and labeling all of the permutations in order, we get the following sequence for n = 3: 7 | 8 | "123" 9 | "132" 10 | "213" 11 | "231" 12 | "312" 13 | "321" 14 | Given n and k, return the kth permutation sequence. 15 | 16 | 17 | 18 | Example 1: 19 | 20 | Input: n = 3, k = 3 21 | Output: "213" 22 | Example 2: 23 | 24 | Input: n = 4, k = 9 25 | Output: "2314" 26 | Example 3: 27 | 28 | Input: n = 3, k = 1 29 | Output: "123" 30 | 31 | 32 | Constraints: 33 | 34 | 1 <= n <= 9 35 | 1 <= k <= n! -------------------------------------------------------------------------------- /doc/001-100/061-rotate-list.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/rotate-list/ 2 | 3 | Given the head of a linked list, rotate the list to the right by k places. 4 | 5 | 6 | 7 | Example 1: 8 | 9 |  10 | 11 | Input: head = [1,2,3,4,5], k = 2 12 | Output: [4,5,1,2,3] 13 | 14 | Constraints: 15 | 16 | The number of nodes in the list is in the range [0, 500]. 17 | -100 <= Node.val <= 100 18 | 0 <= k <= 2 * 109 -------------------------------------------------------------------------------- /doc/001-100/064-minimum-path-sum.md: -------------------------------------------------------------------------------- 1 | https://leetcode-cn.com/problems/minimum-path-sum/ 2 | 3 | Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. 4 | 5 | Note: You can only move either down or right at any point in time. 6 | 7 | Example 1: 8 | 9 |  10 | 11 | Input: grid = [[1,3,1],[1,5,1],[4,2,1]] 12 | Output: 7 13 | Explanation: Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum. 14 | Example 2: 15 | 16 | Input: grid = [[1,2,3],[4,5,6]] 17 | Output: 12 18 | 19 | 20 | Constraints: 21 | 22 | m == grid.length 23 | n == grid[i].length 24 | 1 <= m, n <= 200 25 | 0 <= grid[i][j] <= 100 -------------------------------------------------------------------------------- /doc/001-100/067-add-binary.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/add-binary/ 2 | 3 | Given two binary strings a and b, return their sum as a binary string. 4 | 5 | ## EX 6 | 7 | Example 1: 8 | 9 | ``` 10 | Input: a = "11", b = "1" 11 | Output: "100" 12 | ``` 13 | 14 | Example 2: 15 | 16 | ``` 17 | Input: a = "1010", b = "1011" 18 | Output: "10101" 19 | ``` 20 | 21 | ## Constraints: 22 | 23 | 1 <= a.length, b.length <= 10^4 24 | 25 | a and b consist only of '0' or '1' characters. 26 | 27 | Each string does not contain leading zeros except for the zero itself. -------------------------------------------------------------------------------- /doc/001-100/070-climbing-stairs.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/climbing-stairs/ 2 | 3 | You are climbing a staircase. It takes n steps to reach the top. 4 | 5 | Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 6 | 7 | 8 | 9 | Example 1: 10 | 11 | Input: n = 2 12 | Output: 2 13 | Explanation: There are two ways to climb to the top. 14 | 1. 1 step + 1 step 15 | 2. 2 steps 16 | Example 2: 17 | 18 | Input: n = 3 19 | Output: 3 20 | Explanation: There are three ways to climb to the top. 21 | 1. 1 step + 1 step + 1 step 22 | 2. 1 step + 2 steps 23 | 3. 2 steps + 1 step 24 | 25 | 26 | Constraints: 27 | 28 | 1 <= n <= 45 -------------------------------------------------------------------------------- /doc/001-100/073-set-matrix-zeroes.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/set-matrix-zeroes/ 2 | 3 | Given an m x n matrix. If an element is 0, set its entire row and column to 0. Do it in-place. 4 | 5 | Follow up: 6 | 7 | A straight forward solution using O(mn) space is probably a bad idea. 8 | A simple improvement uses O(m + n) space, but still not the best solution. 9 | Could you devise a constant space solution? 10 | 11 | 12 | Example 1: 13 | 14 |  15 | 16 | 17 | Input: matrix = [[1,1,1],[1,0,1],[1,1,1]] 18 | Output: [[1,0,1],[0,0,0],[1,0,1]] 19 | Example 2: 20 | 21 |  22 | 23 | Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]] 24 | Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]] 25 | 26 | 27 | Constraints: 28 | 29 | m == matrix.length 30 | n == matrix[0].length 31 | 1 <= m, n <= 200 32 | -231 <= matrix[i][j] <= 231 - 1 -------------------------------------------------------------------------------- /doc/001-100/074-search-a-2d-matrix.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/search-a-2d-matrix/ 2 | 3 | Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: 4 | 5 | Integers in each row are sorted from left to right. 6 | The first integer of each row is greater than the last integer of the previous row. 7 | 8 | 9 | Example 1: 10 | 11 | 12 | Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3 13 | Output: true 14 | Example 2: 15 | 16 | 17 | Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13 18 | Output: false 19 | 20 | 21 | Constraints: 22 | 23 | m == matrix.length 24 | n == matrix[i].length 25 | 1 <= m, n <= 100 26 | -10^4 <= matrix[i][j], target <= 10^4 27 | -------------------------------------------------------------------------------- /doc/001-100/075-sort-colors.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/sort-colors/ 2 | 3 | Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue. 4 | 5 | We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively. 6 | 7 | 8 | 9 | Example 1: 10 | 11 | Input: nums = [2,0,2,1,1,0] 12 | Output: [0,0,1,1,2,2] 13 | Example 2: 14 | 15 | Input: nums = [2,0,1] 16 | Output: [0,1,2] 17 | Example 3: 18 | 19 | Input: nums = [0] 20 | Output: [0] 21 | Example 4: 22 | 23 | Input: nums = [1] 24 | Output: [1] 25 | 26 | 27 | Constraints: 28 | 29 | n == nums.length 30 | 1 <= n <= 300 31 | nums[i] is 0, 1, or 2. -------------------------------------------------------------------------------- /doc/001-100/077-combinations.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/combinations/ 2 | 3 | 4 | Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. 5 | 6 | You may return the answer in any order. 7 | 8 | 9 | 10 | Example 1: 11 | 12 | Input: n = 4, k = 2 13 | Output: 14 | [ 15 | [2,4], 16 | [3,4], 17 | [2,3], 18 | [1,2], 19 | [1,3], 20 | [1,4], 21 | ] 22 | Example 2: 23 | 24 | Input: n = 1, k = 1 25 | Output: [[1]] 26 | 27 | 28 | Constraints: 29 | 30 | 1 <= n <= 20 31 | 1 <= k <= n -------------------------------------------------------------------------------- /doc/001-100/078-subsets.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/subsets/ 2 | 3 | Given an integer array nums of unique elements, return all possible subsets (the power set). 4 | 5 | The solution set must not contain duplicate subsets. Return the solution in any order. 6 | 7 | 8 | 9 | Example 1: 10 | 11 | Input: nums = [1,2,3] 12 | Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]] 13 | Example 2: 14 | 15 | Input: nums = [0] 16 | Output: [[],[0]] 17 | 18 | 19 | Constraints: 20 | 21 | 1 <= nums.length <= 10 22 | -10 <= nums[i] <= 10 23 | All the numbers of nums are unique. -------------------------------------------------------------------------------- /doc/001-100/081-search-in-rotated-sorted-array-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/search-in-rotated-sorted-array-ii/ 2 | 3 | There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values). 4 | 5 | Before being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). For example, [0,1,2,4,4,4,5,6,6,7] might be rotated at pivot index 5 and become [4,5,6,6,7,0,1,2,4,4]. 6 | 7 | Given the array nums after the rotation and an integer target, return true if target is in nums, or false if it is not in nums. 8 | 9 | 10 | 11 | Example 1: 12 | 13 | Input: nums = [2,5,6,0,0,1,2], target = 0 14 | Output: true 15 | Example 2: 16 | 17 | Input: nums = [2,5,6,0,0,1,2], target = 3 18 | Output: false 19 | 20 | 21 | Constraints: 22 | 23 | 1 <= nums.length <= 5000 24 | -10^4 <= nums[i] <= 10^4 25 | nums is guaranteed to be rotated at some pivot. 26 | -10^4 <= target <= 10^4 -------------------------------------------------------------------------------- /doc/001-100/082-remove-duplicates-from-sorted-list-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ 2 | 3 | Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well. 4 | 5 | 6 | 7 | Example 1: 8 | 9 |  10 | 11 | Input: head = [1,2,3,3,4,4,5] 12 | Output: [1,2,5] 13 | Example 2: 14 | 15 |  16 | 17 | Input: head = [1,1,1,2,3] 18 | Output: [2,3] 19 | 20 | 21 | Constraints: 22 | 23 | The number of nodes in the list is in the range [0, 300]. 24 | -100 <= Node.val <= 100 25 | The list is guaranteed to be sorted in ascending order. 26 | -------------------------------------------------------------------------------- /doc/001-100/083-remove-duplicates-from-sorted-list.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/remove-duplicates-from-sorted-list/ 2 | 3 | Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. 4 | 5 | 6 | ## EX 7 | 8 | Example 1: 9 | 10 |  11 | 12 | ``` 13 | Input: head = [1,1,2] 14 | Output: [1,2] 15 | ``` 16 | 17 | Example 2: 18 | 19 |  20 | 21 | ``` 22 | Input: head = [1,1,2,3,3] 23 | Output: [1,2,3] 24 | ``` 25 | 26 | ## Constraints: 27 | 28 | The number of nodes in the list is in the range [0, 300]. 29 | 30 | -100 <= Node.val <= 100 31 | 32 | The list is guaranteed to be sorted in ascending order. 33 | 34 | -------------------------------------------------------------------------------- /doc/001-100/084-largest-rectangle-in-histogram.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/largest-rectangle-in-histogram/description/ 2 | 3 | 84. Largest Rectangle in Histogram 4 | 5 | Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, return the area of the largest rectangle in the histogram. 6 | 7 | ## EX 8 | 9 | Example 1: 10 | 11 |  12 | 13 | ``` 14 | Input: heights = [2,1,5,6,2,3] 15 | Output: 10 16 | Explanation: The above is a histogram where width of each bar is 1. 17 | The largest rectangle is shown in the red area, which has an area = 10 units. 18 | ``` 19 | 20 | Example 2: 21 | 22 |  23 | 24 | ``` 25 | Input: heights = [2,4] 26 | Output: 4 27 | ``` 28 | 29 | ## Constraints: 30 | 31 | 1 <= heights.length <= 10^5 32 | 33 | 0 <= heights[i] <= 10^4 34 | -------------------------------------------------------------------------------- /doc/001-100/085-maximal-rectangle.md: -------------------------------------------------------------------------------- 1 | # 85. Maximal Rectangle 2 | 3 | Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. 4 | 5 | ## Ex 6 | 7 | Example 1: 8 | 9 |  10 | 11 | ``` 12 | Input: matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]] 13 | Output: 6 14 | Explanation: The maximal rectangle is shown in the above picture. 15 | ``` 16 | 17 | Example 2: 18 | 19 | ``` 20 | Input: matrix = [["0"]] 21 | Output: 0 22 | ``` 23 | 24 | Example 3: 25 | 26 | ``` 27 | Input: matrix = [["1"]] 28 | Output: 1 29 | ``` 30 | 31 | ## Constraints: 32 | 33 | rows == matrix.length 34 | 35 | cols == matrix[i].length 36 | 37 | 1 <= row, cols <= 200 38 | 39 | matrix[i][j] is '0' or '1'. -------------------------------------------------------------------------------- /doc/001-100/086-partition-list.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/partition-list/ 2 | 3 | Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. 4 | 5 | You should preserve the original relative order of the nodes in each of the two partitions. 6 | 7 | 8 | 9 | Example 1: 10 | 11 |  12 | 13 | Input: head = [1,4,3,2,5,2], x = 3 14 | Output: [1,2,2,4,3,5] 15 | Example 2: 16 | 17 | Input: head = [2,1], x = 2 18 | Output: [1,2] 19 | 20 | 21 | Constraints: 22 | 23 | The number of nodes in the list is in the range [0, 200]. 24 | -100 <= Node.val <= 100 25 | -200 <= x <= 200 -------------------------------------------------------------------------------- /doc/001-100/089-grey-code.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/gray-code/ 2 | 3 | The gray code is a binary numeral system where two successive values differ in only one bit. 4 | 5 | Given an integer n representing the total number of bits in the code, return any sequence of gray code. 6 | 7 | A gray code sequence must begin with 0. 8 | 9 | 10 | 11 | Example 1: 12 | 13 | Input: n = 2 14 | Output: [0,1,3,2] 15 | Explanation: 16 | 00 - 0 17 | 01 - 1 18 | 11 - 3 19 | 10 - 2 20 | [0,2,3,1] is also a valid gray code sequence. 21 | 00 - 0 22 | 10 - 2 23 | 11 - 3 24 | 01 - 1 25 | Example 2: 26 | 27 | Input: n = 1 28 | Output: [0,1] 29 | 30 | 31 | Constraints: 32 | 33 | 1 <= n <= 16 -------------------------------------------------------------------------------- /doc/001-100/090-subsets-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/subsets-ii/ 2 | 3 | Given an integer array nums that may contain duplicates, return all possible subsets (the power set). 4 | 5 | The solution set must not contain duplicate subsets. Return the solution in any order. 6 | 7 | 8 | 9 | Example 1: 10 | 11 | Input: nums = [1,2,2] 12 | Output: [[],[1],[1,2],[1,2,2],[2],[2,2]] 13 | Example 2: 14 | 15 | Input: nums = [0] 16 | Output: [[],[0]] 17 | 18 | 19 | Constraints: 20 | 21 | 1 <= nums.length <= 10 22 | -10 <= nums[i] <= 10 -------------------------------------------------------------------------------- /doc/001-100/092-reverse-linked-list-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/reverse-linked-list-ii/ 2 | 3 | 4 | Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list. 5 | 6 | 7 | 8 | Example 1: 9 | 10 |  11 | 12 | Input: head = [1,2,3,4,5], left = 2, right = 4 13 | Output: [1,4,3,2,5] 14 | Example 2: 15 | 16 | Input: head = [5], left = 1, right = 1 17 | Output: [5] 18 | 19 | 20 | Constraints: 21 | 22 | The number of nodes in the list is n. 23 | 1 <= n <= 500 24 | -500 <= Node.val <= 500 25 | 1 <= left <= right <= n 26 | 27 | 28 | Follow up: Could you do it in one pass? 29 | -------------------------------------------------------------------------------- /doc/001-100/094-binary-tree-inorder-traversal.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/binary-tree-inorder-traversal/ 2 | 3 | Given the root of a binary tree, return the inorder traversal of its nodes' values. 4 | 5 | 6 | 7 | Example 1: 8 | 9 |  10 | 11 | Input: root = [1,null,2,3] 12 | Output: [1,3,2] 13 | Example 2: 14 | 15 | Input: root = [] 16 | Output: [] 17 | Example 3: 18 | 19 | Input: root = [1] 20 | Output: [1] 21 | Example 4: 22 | 23 |  24 | 25 | Input: root = [1,2] 26 | Output: [2,1] 27 | Example 5: 28 | 29 |  30 | 31 | Input: root = [1,null,2] 32 | Output: [1,2] 33 | 34 | 35 | Constraints: 36 | 37 | The number of nodes in the tree is in the range [0, 100]. 38 | -100 <= Node.val <= 100 39 | 40 | 41 | Follow up: 42 | 43 | Recursive solution is trivial, could you do it iteratively? -------------------------------------------------------------------------------- /doc/001-100/095-unique-binary-search-trees-ii.md: -------------------------------------------------------------------------------- 1 | 给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种? 2 | 3 | 示例: 4 | 5 | 输入: 3 6 | 输出: 5 7 | 解释: 8 | 给定 n = 3, 一共有 5 种不同结构的二叉搜索树: 9 | 10 | 1 3 3 2 1 11 | \ / / / \ \ 12 | 3 2 1 1 3 2 13 | / / \ \ 14 | 2 1 2 3 15 | 16 | 来源:力扣(LeetCode) 17 | 链接:https://leetcode-cn.com/problems/unique-binary-search-trees 18 | 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 -------------------------------------------------------------------------------- /doc/001-100/096-unique-binary-search-trees.md: -------------------------------------------------------------------------------- 1 | Given an integer n, return the number of structurally unique BST's (binary search trees) which has exactly n nodes of unique values from 1 to n. 2 | 3 | 4 | 5 | Example 1: 6 | 7 | 8 | Input: n = 3 9 | Output: 5 10 | Example 2: 11 | 12 | Input: n = 1 13 | Output: 1 14 | 15 | 16 | Constraints: 17 | 18 | 1 <= n <= 19 -------------------------------------------------------------------------------- /doc/001-100/097-interleaving-string.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/interleaving-string/ 2 | 3 | Given strings s1, s2, and s3, find whether s3 is formed by an interleaving of s1 and s2. 4 | 5 | An interleaving of two strings s and t is a configuration where they are divided into non-empty substrings such that: 6 | 7 | s = s1 + s2 + ... + sn 8 | t = t1 + t2 + ... + tm 9 | |n - m| <= 1 10 | 11 | The interleaving is s1 + t1 + s2 + t2 + s3 + t3 + ... or t1 + s1 + t2 + s2 + t3 + s3 + ... 12 | 13 | Note: a + b is the concatenation of strings a and b. 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /doc/001-100/098-validate-binary-search-tree.md: -------------------------------------------------------------------------------- 1 | Given the root of a binary tree, determine if it is a valid binary search tree (BST). 2 | 3 | A valid BST is defined as follows: 4 | 5 | The left subtree of a node contains only nodes with keys less than the node's key. 6 | The right subtree of a node contains only nodes with keys greater than the node's key. 7 | Both the left and right subtrees must also be binary search trees. 8 | 9 | 10 | Example 1: 11 |  12 | 13 | Input: root = [2,1,3] 14 | Output: true 15 | Example 2: 16 |  17 | 18 | Input: root = [5,1,4,null,null,3,6] 19 | Output: false 20 | Explanation: The root node's value is 5 but its right child's value is 4. 21 | 22 | 23 | Constraints: 24 | 25 | The number of nodes in the tree is in the range [1, 104]. 26 | -2^31 <= Node.val <= 2^31 - 1 -------------------------------------------------------------------------------- /doc/001-100/100-same-tree.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/same-tree/ 2 | 3 | # 100. same tree 4 | 5 | Given the roots of two binary trees p and q, write a function to check if they are the same or not. 6 | 7 | Two binary trees are considered the same if they are structurally identical, and the nodes have the same value. 8 | 9 | # Example 10 | 11 | Example 1: 12 | 13 |  14 | 15 | ``` 16 | Input: p = [1,2,3], q = [1,2,3] 17 | Output: true 18 | ``` 19 | 20 | Example 2: 21 | 22 |  23 | 24 | ``` 25 | Input: p = [1,2], q = [1,null,2] 26 | Output: false 27 | ``` 28 | 29 | Example 3: 30 | 31 | ``` 32 | Input: p = [1,2,1], q = [1,1,2] 33 | Output: false 34 | ``` 35 | 36 | Constraints: 37 | 38 | The number of nodes in both trees is in the range [0, 100]. 39 | -104 <= Node.val <= 104 40 | -------------------------------------------------------------------------------- /doc/101-200/101-symmetric-tree.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/symmetric-tree/ 2 | 3 | Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center). 4 | 5 | # example 6 | 7 | example1: 8 | 9 |  10 | 11 | ``` 12 | Input: root = [1,2,2,3,4,4,3] 13 | Output: true 14 | ``` 15 | 16 | example2: 17 | 18 |  19 | 20 | ``` 21 | Input: root = [1,2,2,null,3,null,3] 22 | Output: false 23 | ``` 24 | 25 | Constraints: 26 | 27 | The number of nodes in the tree is in the range [1, 1000]. 28 | -100 <= Node.val <= 100 29 | 30 | 31 | Follow up: Could you solve it both recursively and iteratively? 32 | 33 | -------------------------------------------------------------------------------- /doc/101-200/102-binary-tree-level-order-traversal.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/binary-tree-level-order-traversal/ 2 | 3 | Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level). 4 | 5 | 6 | 7 | Example 1: 8 | 9 |  10 | 11 | Input: root = [3,9,20,null,null,15,7] 12 | Output: [[3],[9,20],[15,7]] 13 | Example 2: 14 | 15 | Input: root = [1] 16 | Output: [[1]] 17 | Example 3: 18 | 19 | Input: root = [] 20 | Output: [] 21 | 22 | 23 | Constraints: 24 | 25 | The number of nodes in the tree is in the range [0, 2000]. 26 | -1000 <= Node.val <= 1000 -------------------------------------------------------------------------------- /doc/101-200/103-binary-tree-zigzag-level-order-traversal.md: -------------------------------------------------------------------------------- 1 | Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between). 2 | 3 | 4 | 5 | Example 1: 6 | 7 |  8 | 9 | Input: root = [3,9,20,null,null,15,7] 10 | Output: [[3],[20,9],[15,7]] 11 | Example 2: 12 | 13 | Input: root = [1] 14 | Output: [[1]] 15 | Example 3: 16 | 17 | Input: root = [] 18 | Output: [] 19 | 20 | 21 | Constraints: 22 | 23 | The number of nodes in the tree is in the range [0, 2000]. 24 | -100 <= Node.val <= 100 -------------------------------------------------------------------------------- /doc/101-200/104-maximum-depth-of-binary-tree.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/maximum-depth-of-binary-tree/description/ 2 | 3 | # 104. Maximum Depth of Binary Tree 4 | 5 | Given the root of a binary tree, return its maximum depth. 6 | 7 | A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 8 | 9 | # Example 10 | 11 | example 1: 12 | 13 |  14 | 15 | ``` 16 | Input: root = [3,9,20,null,null,15,7] 17 | Output: 3 18 | ``` 19 | 20 | example 2: 21 | 22 | ``` 23 | Input: root = [1,null,2] 24 | Output: 2 25 | ``` 26 | 27 | # Constraints: 28 | 29 | The number of nodes in the tree is in the range [0, 10^4]. 30 | -100 <= Node.val <= 100 -------------------------------------------------------------------------------- /doc/101-200/105-construct-binary-tree-from-preorder-and-inorder-traversal.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ 2 | 3 | Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, 4 | construct and return the binary tree. 5 | 6 | 7 | 8 | Example 1: 9 | 10 |  11 | 12 | Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7] 13 | Output: [3,9,20,null,null,15,7] 14 | Example 2: 15 | 16 | Input: preorder = [-1], inorder = [-1] 17 | Output: [-1] 18 | 19 | 20 | Constraints: 21 | 22 | 1 <= preorder.length <= 3000 23 | inorder.length == preorder.length 24 | -3000 <= preorder[i], inorder[i] <= 3000 25 | preorder and inorder consist of unique values. 26 | Each value of inorder also appears in preorder. 27 | preorder is guaranteed to be the preorder traversal of the tree. 28 | inorder is guaranteed to be the inorder traversal of the tree. -------------------------------------------------------------------------------- /doc/101-200/106-construct-binary-tree-from-inorder-and-postorder-traversal.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ 2 | 3 | Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the same tree, construct and return the binary tree. 4 | 5 | 6 | 7 | 8 | Example 1: 9 | 10 |  11 | 12 | Input: inorder = [9,3,15,20,7], postorder = [9,15,7,20,3] 13 | Output: [3,9,20,null,null,15,7] 14 | Example 2: 15 | 16 | Input: inorder = [-1], postorder = [-1] 17 | Output: [-1] 18 | 19 | 20 | Constraints: 21 | 22 | 1 <= inorder.length <= 3000 23 | postorder.length == inorder.length 24 | -3000 <= inorder[i], postorder[i] <= 3000 25 | inorder and postorder consist of unique values. 26 | Each value of postorder also appears in inorder. 27 | inorder is guaranteed to be the inorder traversal of the tree. 28 | postorder is guaranteed to be the postorder traversal of the tree. -------------------------------------------------------------------------------- /doc/101-200/107-binary-tree-level-order-traversal-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/binary-tree-level-order-traversal-ii/ 2 | 3 | 4 | Given the root of a binary tree, return the bottom-up level order traversal of its nodes' values. (i.e., from left to right, level by level from leaf to root). 5 | 6 | 7 | 8 | Example 1: 9 | 10 | 11 |  12 | 13 | Input: root = [3,9,20,null,null,15,7] 14 | Output: [[15,7],[9,20],[3]] 15 | Example 2: 16 | 17 | Input: root = [1] 18 | Output: [[1]] 19 | Example 3: 20 | 21 | Input: root = [] 22 | Output: [] 23 | 24 | 25 | Constraints: 26 | 27 | The number of nodes in the tree is in the range [0, 2000]. 28 | -1000 <= Node.val <= 1000 -------------------------------------------------------------------------------- /doc/101-200/108-convert-sorted-array-to-binary-search-tree.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ 2 | 3 | Given an integer array nums where the elements are sorted in ascending order, convert it to a 4 | height-balanced binary search tree. 5 | 6 | # Example 7 | 8 | Example 1: 9 | 10 |  11 | 12 | ``` 13 | Input: nums = [-10,-3,0,5,9] 14 | Output: [0,-3,9,-10,null,5] 15 | Explanation: [0,-10,5,null,-3,null,9] is also accepted: 16 | ``` 17 | 18 |  19 | 20 | Example 2: 21 | 22 |  23 | 24 | ``` 25 | Input: nums = [1,3] 26 | Output: [3,1] 27 | Explanation: [1,null,3] and [3,1] are both height-balanced BSTs. 28 | ``` 29 | 30 | # Constraints: 31 | 32 | 1 <= nums.length <= 10^4 33 | -10^4 <= nums[i] <= 10^4 34 | nums is sorted in a strictly increasing order. 35 | 36 | PS: 这一题也可以结合无顺序作为考点,不过难度不大。 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /doc/101-200/109-convert-sorted-list-to-binary-search-tree.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/ 2 | 3 | Given the head of a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 4 | 5 | For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 6 | 7 | 8 | 9 | Example 1: 10 | 11 |  12 | 13 | Input: head = [-10,-3,0,5,9] 14 | Output: [0,-3,9,-10,null,5] 15 | Explanation: One possible answer is [0,-3,9,-10,null,5], which represents the shown height balanced BST. 16 | Example 2: 17 | 18 | Input: head = [] 19 | Output: [] 20 | Example 3: 21 | 22 | Input: head = [0] 23 | Output: [0] 24 | Example 4: 25 | 26 | Input: head = [1,3] 27 | Output: [3,1] 28 | 29 | 30 | Constraints: 31 | 32 | The number of nodes in head is in the range [0, 2 * 104]. 33 | -10^5 <= Node.val <= 10^5 34 | -------------------------------------------------------------------------------- /doc/101-200/110-balanced-binary-tree.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/balanced-binary-tree/description/ 2 | 3 | Given a binary tree, determine if it is height-balanced . 4 | 5 | # Example 6 | 7 | Example 1: 8 | 9 | 10 |  11 | 12 | ``` 13 | Input: root = [3,9,20,null,null,15,7] 14 | Output: true 15 | ``` 16 | 17 | Example 2: 18 | 19 |  20 | 21 | ``` 22 | Input: root = [1,2,2,3,3,null,null,4,4] 23 | Output: false 24 | ``` 25 | 26 | Example 3: 27 | 28 | ``` 29 | Input: root = [] 30 | Output: true 31 | ``` 32 | 33 | # Constraints: 34 | 35 | The number of nodes in the tree is in the range [0, 5000]. 36 | -10^4 <= Node.val <= 10^4 37 | 38 | -------------------------------------------------------------------------------- /doc/101-200/111-minimum-depth-of-binary-tree.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/minimum-depth-of-binary-tree/ 2 | 3 | Given a binary tree, find its minimum depth. 4 | 5 | The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 6 | 7 | Note: A leaf is a node with no children. 8 | 9 | # Example 10 | 11 | Example 1: 12 | 13 |  14 | 15 | ``` 16 | Input: root = [3,9,20,null,null,15,7] 17 | Output: 2 18 | ``` 19 | 20 | Example 2: 21 | 22 | ``` 23 | Input: root = [2,null,3,null,4,null,5,null,6] 24 | Output: 5 25 | ``` 26 | 27 | # Constraints: 28 | 29 | The number of nodes in the tree is in the range [0, 10^5]. 30 | -1000 <= Node.val <= 1000 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /doc/101-200/112-path-sum.md: -------------------------------------------------------------------------------- 1 | Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum. 2 | 3 | A leaf is a node with no children. 4 | 5 | 6 | 7 | Example 1: 8 | 9 |  10 | 11 | Input: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22 12 | Output: true 13 | Example 2: 14 | 15 |  16 | 17 | Input: root = [1,2,3], targetSum = 5 18 | Output: false 19 | Example 3: 20 | 21 | Input: root = [1,2], targetSum = 0 22 | Output: false 23 | 24 | 25 | Constraints: 26 | 27 | The number of nodes in the tree is in the range [0, 5000]. 28 | -1000 <= Node.val <= 1000 29 | -1000 <= targetSum <= 1000 -------------------------------------------------------------------------------- /doc/101-200/113-path-sum-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/path-sum-ii/ 2 | 3 | Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where each path's sum equals targetSum. 4 | 5 | A leaf is a node with no children. 6 | 7 | 8 | 9 | Example 1: 10 | 11 |  12 | 13 | Input: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22 14 | Output: [[5,4,11,2],[5,8,4,5]] 15 | Example 2: 16 | 17 |  18 | 19 | Input: root = [1,2,3], targetSum = 5 20 | Output: [] 21 | Example 3: 22 | 23 | Input: root = [1,2], targetSum = 0 24 | Output: [] 25 | 26 | 27 | Constraints: 28 | 29 | The number of nodes in the tree is in the range [0, 5000]. 30 | -1000 <= Node.val <= 1000 31 | -1000 <= targetSum <= 1000 32 | -------------------------------------------------------------------------------- /doc/101-200/115-distinct-subsequences.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/distinct-subsequences/ 2 | 3 | 4 | Given two strings s and t, return the number of distinct subsequences of s which equals t. 5 | 6 | The test cases are generated so that the answer fits on a 32-bit signed integer. 7 | 8 | 9 | Example 1: 10 | 11 | Input: s = "rabbbit", t = "rabbit" 12 | Output: 3 13 | Explanation: 14 | As shown below, there are 3 ways you can generate "rabbit" from s. 15 | rabbbit 16 | rabbbit 17 | rabbbit 18 | 19 | bbb 这3个去掉任何一个都是方式。所以一共有3种。 20 | 21 | Example 2: 22 | 23 | Input: s = "babgbag", t = "bag" 24 | Output: 5 25 | Explanation: 26 | As shown below, there are 5 ways you can generate "bag" from s. 27 | babgbag 28 | babgbag 29 | babgbag 30 | babgbag 31 | babgbag 32 | 33 | # Constraints: 34 | 35 | 1 <= s.length, t.length <= 1000 36 | s and t consist of English letters 37 | -------------------------------------------------------------------------------- /doc/101-200/118-pascals-triangle.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/pascals-triangle/ 2 | 3 | Given an integer numRows, return the first numRows of Pascal's triangle. 4 | 5 | In Pascal's triangle, each number is the sum of the two numbers directly above it as shown: 6 | 7 |  8 | 9 | ## Example 10 | 11 | Example 1: 12 | 13 | ``` 14 | Input: numRows = 5 15 | Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]] 16 | ``` 17 | 18 | Example 2: 19 | 20 | ``` 21 | Input: numRows = 1 22 | Output: [[1]] 23 | ``` 24 | 25 | ## Constraints: 26 | 27 | 1 <= numRows <= 30 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /doc/101-200/119-pascals-triangle-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/pascals-triangle-ii/ 2 | 3 | Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle. 4 | 5 | In Pascal's triangle, each number is the sum of the two numbers directly above it as shown: 6 | 7 |  8 | 9 | ## Ex 10 | 11 | Example 1: 12 | 13 | ``` 14 | Input: rowIndex = 3 15 | Output: [1,3,3,1] 16 | ``` 17 | 18 | Example 2: 19 | 20 | ``` 21 | Input: rowIndex = 0 22 | Output: [1] 23 | ``` 24 | 25 | Example 3: 26 | 27 | ``` 28 | Input: rowIndex = 1 29 | Output: [1,1] 30 | ``` 31 | 32 | ## Constraints: 33 | 34 | 0 <= rowIndex <= 33 35 | 36 | 37 | Follow up: Could you optimize your algorithm to use only O(rowIndex) extra space? -------------------------------------------------------------------------------- /doc/101-200/120-triangle.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/triangle/ 2 | 3 | Given a triangle array, return the minimum path sum from top to bottom. 4 | 5 | For each step, you may move to an adjacent number of the row below. 6 | 7 | More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row. 8 | 9 | 10 | 11 | Example 1: 12 | 13 | ``` 14 | Input: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]] 15 | Output: 11 16 | Explanation: The triangle looks like: 17 | 2 18 | 3 4 19 | 6 5 7 20 | 4 1 8 3 21 | The minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11 (underlined above). 22 | ``` 23 | 24 | Example 2: 25 | 26 | ``` 27 | Input: triangle = [[-10]] 28 | Output: -10 29 | ``` 30 | 31 | Constraints: 32 | 33 | 1 <= triangle.length <= 200 34 | triangle[0].length == 1 35 | triangle[i].length == triangle[i - 1].length + 1 36 | -104 <= triangle[i][j] <= 104 37 | 38 | 39 | Follow up: Could you do this using only O(n) extra space, where n is the total number of rows in the triangle? -------------------------------------------------------------------------------- /doc/101-200/121-best-time-to-buy-and-sell-stock.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ 2 | 3 | You are given an array prices where prices[i] is the price of a given stock on the ith day. 4 | 5 | You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. 6 | 7 | Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. 8 | 9 | ## EX 10 | 11 | Example 1: 12 | 13 | ``` 14 | Input: prices = [7,1,5,3,6,4] 15 | Output: 5 16 | Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-1 = 5. 17 | Note that buying on day 2 and selling on day 1 is not allowed because you must buy before you sell. 18 | ``` 19 | 20 | Example 2: 21 | 22 | ``` 23 | Input: prices = [7,6,4,3,1] 24 | Output: 0 25 | Explanation: In this case, no transactions are done and the max profit = 0. 26 | ``` 27 | 28 | ## Constraints: 29 | 30 | 1 <= prices.length <= 10^5 31 | 0 <= prices[i] <= 10^4 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /doc/101-200/128-longest-consecutive-sequence.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/longest-consecutive-sequence/ 2 | 3 | Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. 4 | 5 | You must write an algorithm that runs in O(n) time. 6 | 7 | ## Ex 8 | 9 | Example 1: 10 | 11 | ``` 12 | Input: nums = [100,4,200,1,3,2] 13 | Output: 4 14 | Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4. 15 | ``` 16 | 17 | Example 2: 18 | 19 | ``` 20 | Input: nums = [0,3,7,2,5,8,4,6,0,1] 21 | Output: 9 22 | ``` 23 | 24 | ## Constraints: 25 | 26 | 0 <= nums.length <= 10^5 27 | 28 | -10^9 <= nums[i] <= 10^9 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /doc/101-200/131-palindrome-partitioning.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/palindrome-partitioning/ 2 | 3 | Given a string s, partition s such that every substring of the partition is a palindrome. 4 | 5 | Return all possible palindrome partitioning of s. 6 | 7 | A palindrome string is a string that reads the same backward as forward. 8 | 9 | 10 | Example 1: 11 | 12 | ``` 13 | Input: s = "aab" 14 | Output: [["a","a","b"],["aa","b"]] 15 | ``` 16 | 17 | Example 2: 18 | 19 | ``` 20 | Input: s = "a" 21 | Output: [["a"]] 22 | ``` 23 | 24 | Constraints: 25 | 26 | 1 <= s.length <= 16 27 | s contains only lowercase English letters. -------------------------------------------------------------------------------- /doc/101-200/132-palindrome-partitioning-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/palindrome-partitioning-ii/ 2 | 3 | Given a string s, partition s such that every substring of the partition is a palindrome. 4 | 5 | Return the minimum cuts needed for a palindrome partitioning of s. 6 | 7 | ## Ex 8 | 9 | Example 1: 10 | 11 | ``` 12 | Input: s = "aab" 13 | Output: 1 14 | Explanation: The palindrome partitioning ["aa","b"] could be produced using 1 cut. 15 | ``` 16 | 17 | Example 2: 18 | 19 | ``` 20 | Input: s = "a" 21 | Output: 0 22 | ``` 23 | 24 | Example 3: 25 | 26 | 27 | ``` 28 | Input: s = "ab" 29 | Output: 1 30 | ``` 31 | 32 | ## Constraints: 33 | 34 | 1 <= s.length <= 2000 35 | s consists of lowercase English letters only. 36 | 37 | 38 | -------------------------------------------------------------------------------- /doc/101-200/136-single-number.md: -------------------------------------------------------------------------------- 1 | Given a non-empty array of integers nums, every element appears twice except for one. Find that single one. 2 | 3 | Follow up: Could you implement a solution with a linear runtime complexity and without using extra memory? 4 | 5 | 6 | 7 | Example 1: 8 | 9 | Input: nums = [2,2,1] 10 | Output: 1 11 | Example 2: 12 | 13 | Input: nums = [4,1,2,1,2] 14 | Output: 4 15 | Example 3: 16 | 17 | Input: nums = [1] 18 | Output: 1 19 | 20 | 21 | Constraints: 22 | 23 | 1 <= nums.length <= 3 * 10^4 24 | -3 * 10^4 <= nums[i] <= 3 * 10^4 25 | 26 | Each element in the array appears twice except for one element which appears only once. -------------------------------------------------------------------------------- /doc/101-200/137-single-number-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/single-number-ii/ 2 | 3 | Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it. 4 | 5 | 6 | 7 | Example 1: 8 | 9 | Input: nums = [2,2,3,2] 10 | Output: 3 11 | Example 2: 12 | 13 | Input: nums = [0,1,0,1,0,1,99] 14 | Output: 99 15 | 16 | 17 | Constraints: 18 | 19 | 1 <= nums.length <= 3 * 104 20 | -2^31 <= nums[i] <= 2^31 - 1 21 | 22 | Each element in nums appears exactly three times except for one element which appears once. 23 | 24 | 25 | Follow up: Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? -------------------------------------------------------------------------------- /doc/101-200/143-reorder-list.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/reorder-list/ 2 | 3 | You are given the head of a singly linked-list. The list can be represented as: 4 | 5 | L0 → L1 → … → Ln - 1 → Ln 6 | 7 | Reorder the list to be on the following form: 8 | 9 | L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → … 10 | 11 | You may not modify the values in the list's nodes. Only nodes themselves may be changed. 12 | 13 | 14 | ## Ex 15 | 16 | Example 1: 17 | 18 | ``` 19 | Input: head = [1,2,3,4] 20 | Output: [1,4,2,3] 21 | ``` 22 | 23 | Example 2: 24 | 25 | ``` 26 | Input: head = [1,2,3,4,5] 27 | Output: [1,5,2,4,3] 28 | ``` 29 | 30 | ## Constraints: 31 | 32 | The number of nodes in the list is in the range [1, 5 * 10^4]. 33 | 34 | 1 <= Node.val <= 1000 35 | -------------------------------------------------------------------------------- /doc/101-200/144-binary-tree-preorder-traversal.md: -------------------------------------------------------------------------------- 1 | Given the root of a binary tree, return the preorder traversal of its nodes' values. 2 | 3 | 4 | 5 | Example 1: 6 | 7 |  8 | 9 | Input: root = [1,null,2,3] 10 | Output: [1,2,3] 11 | Example 2: 12 | 13 | Input: root = [] 14 | Output: [] 15 | Example 3: 16 | 17 | Input: root = [1] 18 | Output: [1] 19 | Example 4: 20 | 21 |  22 | 23 | Input: root = [1,2] 24 | Output: [1,2] 25 | Example 5: 26 | 27 |  28 | 29 | Input: root = [1,null,2] 30 | Output: [1,2] 31 | 32 | 33 | Constraints: 34 | 35 | The number of nodes in the tree is in the range [0, 100]. 36 | -100 <= Node.val <= 100 37 | 38 | 39 | Follow up: Recursive solution is trivial, could you do it iteratively? 40 | 41 | -------------------------------------------------------------------------------- /doc/101-200/145-binary-tree-postorder-traversal.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/binary-tree-postorder-traversal/ 2 | 3 | Given the root of a binary tree, return the postorder traversal of its nodes' values. 4 | 5 | 6 | 7 | Example 1: 8 | 9 |  10 | 11 | Input: root = [1,null,2,3] 12 | Output: [3,2,1] 13 | Example 2: 14 | 15 | Input: root = [] 16 | Output: [] 17 | Example 3: 18 | 19 | Input: root = [1] 20 | Output: [1] 21 | Example 4: 22 | 23 |  24 | 25 | Input: root = [1,2] 26 | Output: [2,1] 27 | Example 5: 28 | 29 |  30 | 31 | Input: root = [1,null,2] 32 | Output: [2,1] 33 | 34 | 35 | Constraints: 36 | 37 | The number of the nodes in the tree is in the range [0, 100]. 38 | -100 <= Node.val <= 100 39 | 40 | 41 | Follow up: 42 | 43 | Recursive solution is trivial, could you do it iteratively? -------------------------------------------------------------------------------- /doc/101-200/148-sort-list.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/sort-list/description/ 2 | 3 | Given the head of a linked list, return the list after sorting it in ascending order. 4 | 5 | 6 | 7 | Example 1: 8 | 9 | 10 | Input: head = [4,2,1,3] 11 | Output: [1,2,3,4] 12 | Example 2: 13 | 14 | 15 | Input: head = [-1,5,3,4,0] 16 | Output: [-1,0,3,4,5] 17 | Example 3: 18 | 19 | Input: head = [] 20 | Output: [] 21 | 22 | 23 | Constraints: 24 | 25 | The number of nodes in the list is in the range [0, 5 * 104]. 26 | -105 <= Node.val <= 105 27 | 28 | 29 | Follow up: Can you sort the linked list in O(n logn) time and O(1) memory (i.e. constant space)? 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /doc/101-200/149-max-points-on-a-line.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/max-points-on-a-line/description/ 2 | 3 | Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line. 4 | 5 | 6 | 7 | Example 1: 8 | 9 |  10 | 11 | ``` 12 | Input: points = [[1,1],[2,2],[3,3]] 13 | Output: 3 14 | ``` 15 | 16 | Example 2: 17 | 18 |  19 | 20 | ``` 21 | Input: points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]] 22 | Output: 4 23 | ``` 24 | 25 | Constraints: 26 | 27 | 1 <= points.length <= 300 28 | points[i].length == 2 29 | -10^4 <= xi, yi <= 10^4 30 | All the points are unique. 31 | -------------------------------------------------------------------------------- /doc/101-200/152-maximum-product-subarray.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/maximum-product-subarray/ 2 | 3 | 4 | Given an integer array nums, find a subarray that has the largest product, and return the product. 5 | 6 | The test cases are generated so that the answer will fit in a 32-bit integer. 7 | 8 | ## EX 9 | 10 | Example 1: 11 | 12 | ``` 13 | Input: nums = [2,3,-2,4] 14 | Output: 6 15 | Explanation: [2,3] has the largest product 6. 16 | ``` 17 | 18 | Example 2: 19 | 20 | ``` 21 | Input: nums = [-2,0,-1] 22 | Output: 0 23 | Explanation: The result cannot be 2, because [-2,-1] is not a subarray. 24 | ``` 25 | 26 | 27 | ## Constraints: 28 | 29 | 1 <= nums.length <= 2 * 10^4 30 | 31 | -10 <= nums[i] <= 10 32 | 33 | The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. -------------------------------------------------------------------------------- /doc/101-200/164-maximum-gap.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/maximum-gap/ 2 | 3 | Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains less than two elements, return 0. 4 | 5 | You must write an algorithm that runs in linear time and uses linear extra space. 6 | 7 | 8 | 9 | Example 1: 10 | 11 | ``` 12 | Input: nums = [3,6,9,1] 13 | Output: 3 14 | Explanation: The sorted form of the array is [1,3,6,9], either (3,6) or (6,9) has the maximum difference 3. 15 | ``` 16 | 17 | Example 2: 18 | 19 | ``` 20 | Input: nums = [10] 21 | Output: 0 22 | Explanation: The array contains less than 2 elements, therefore return 0. 23 | ``` 24 | 25 | Constraints: 26 | 27 | 1 <= nums.length <= 10^5 28 | 29 | 0 <= nums[i] <= 10^9 -------------------------------------------------------------------------------- /doc/101-200/166-fraction-to-recurring-decimal.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/fraction-to-recurring-decimal/ 2 | 3 | Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. 4 | 5 | If the fractional part is repeating, enclose the repeating part in parentheses. 6 | 7 | If multiple answers are possible, return any of them. 8 | 9 | It is guaranteed that the length of the answer string is less than 104 for all the given inputs. 10 | 11 | 12 | ## EX 13 | 14 | Example 1: 15 | 16 | ``` 17 | Input: numerator = 1, denominator = 2 18 | Output: "0.5" 19 | ``` 20 | 21 | Example 2: 22 | 23 | ``` 24 | Input: numerator = 2, denominator = 1 25 | Output: "2" 26 | ``` 27 | 28 | Example 3: 29 | 30 | ``` 31 | Input: numerator = 4, denominator = 333 32 | Output: "0.(012)" 33 | ``` 34 | 35 | ## Constraints: 36 | 37 | -2^31 <= numerator, denominator <= 2^31 - 1 38 | 39 | denominator != 0 -------------------------------------------------------------------------------- /doc/101-200/168-excel-sheet-column-title.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/excel-sheet-column-title/ 2 | 3 | Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet. 4 | 5 | For example: 6 | 7 | A -> 1 8 | B -> 2 9 | C -> 3 10 | ... 11 | Z -> 26 12 | AA -> 27 13 | AB -> 28 14 | ... 15 | 16 | 17 | Example 1: 18 | 19 | Input: columnNumber = 1 20 | Output: "A" 21 | 22 | Example 2: 23 | 24 | Input: columnNumber = 28 25 | Output: "AB" 26 | Example 3: 27 | 28 | Input: columnNumber = 701 29 | Output: "ZY" 30 | 31 | 32 | Constraints: 33 | 34 | 1 <= columnNumber <= 2^31 - 1 -------------------------------------------------------------------------------- /doc/101-200/169-excel-sheet-column-number.md: -------------------------------------------------------------------------------- 1 | Given a string columnTitle that represents the column title as appears in an Excel sheet, return its corresponding column number. 2 | 3 | For example: 4 | 5 | A -> 1 6 | B -> 2 7 | C -> 3 8 | ... 9 | Z -> 26 10 | AA -> 27 11 | AB -> 28 12 | ... 13 | 14 | 15 | Example 1: 16 | 17 | Input: columnTitle = "A" 18 | Output: 1 19 | Example 2: 20 | 21 | Input: columnTitle = "AB" 22 | Output: 28 23 | Example 3: 24 | 25 | Input: columnTitle = "ZY" 26 | Output: 701 27 | 28 | 29 | Constraints: 30 | 31 | 1 <= columnTitle.length <= 7 32 | columnTitle consists only of uppercase English letters. 33 | columnTitle is in the range ["A", "FXSHRXW"]. -------------------------------------------------------------------------------- /doc/101-200/169-majority-element.md: -------------------------------------------------------------------------------- 1 | https://leetcode-cn.com/problems/majority-element/ 2 | 3 | 给定一个大小为 n 的数组,找到其中的多数元素。多数元素是指在数组中出现次数 大于 ⌊ n/2 ⌋ 的元素。 4 | 5 | 你可以假设数组是非空的,并且给定的数组总是存在多数元素。 6 | 7 | 示例 1: 8 | 9 | 输入:[3,2,3] 10 | 输出:3 11 | 示例 2: 12 | 13 | 输入:[2,2,1,1,1,2,2] 14 | 输出:2 15 | 16 | 17 | 进阶: 18 | 19 | 尝试设计时间复杂度为 O(n)、空间复杂度为 O(1) 的算法解决此问题。 20 | 21 | 来源:力扣(LeetCode) 22 | 链接:https://leetcode-cn.com/problems/majority-element 23 | 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 -------------------------------------------------------------------------------- /doc/101-200/172-factorial-trailing-zeroes.md: -------------------------------------------------------------------------------- 1 | Given an integer n, return the number of trailing zeroes in n!. 2 | 3 | Note that n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1. 4 | 5 | 6 | 7 | Example 1: 8 | 9 | ``` 10 | Input: n = 3 11 | Output: 0 12 | Explanation: 3! = 6, no trailing zero. 13 | ``` 14 | 15 | Example 2: 16 | 17 | ``` 18 | Input: n = 5 19 | Output: 1 20 | Explanation: 5! = 120, one trailing zero. 21 | ``` 22 | 23 | Example 3: 24 | 25 | ``` 26 | Input: n = 0 27 | Output: 0 28 | ``` 29 | 30 | Constraints: 31 | 32 | 0 <= n <= 10^4 33 | 34 | 35 | Follow up: Could you write a solution that works in logarithmic time complexity? -------------------------------------------------------------------------------- /doc/101-200/179-largest-number.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/largest-number/ 2 | 3 | Given a list of non-negative integers nums, arrange them such that they form the largest number and return it. 4 | 5 | Since the result may be very large, so you need to return a string instead of an integer. 6 | 7 | ## EX 8 | 9 | Example 1: 10 | 11 | ``` 12 | Input: nums = [10,2] 13 | Output: "210" 14 | ``` 15 | 16 | Example 2: 17 | 18 | ``` 19 | Input: nums = [3,30,34,5,9] 20 | Output: "9534330" 21 | ``` 22 | 23 | Constraints: 24 | 25 | 1 <= nums.length <= 100 26 | 27 | 0 <= nums[i] <= 10^9 -------------------------------------------------------------------------------- /doc/101-200/187-repeated-dna-sequences.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/repeated-dna-sequences/description/ 2 | 3 | The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'. 4 | 5 | For example, "ACGAATTCCG" is a DNA sequence. 6 | When studying DNA, it is useful to identify repeated sequences within the DNA. 7 | 8 | Given a string s that represents a DNA sequence, return all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule. You may return the answer in any order. 9 | 10 | 11 | 12 | Example 1: 13 | 14 | Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT" 15 | Output: ["AAAAACCCCC","CCCCCAAAAA"] 16 | Example 2: 17 | 18 | Input: s = "AAAAAAAAAAAAA" 19 | Output: ["AAAAAAAAAA"] 20 | 21 | 22 | Constraints: 23 | 24 | 1 <= s.length <= 10^5 25 | 26 | s[i] is either 'A', 'C', 'G', or 'T'. 27 | -------------------------------------------------------------------------------- /doc/101-200/189-rotate-array.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/rotate-array/ 2 | 3 | Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. 4 | 5 | Example 1: 6 | 7 | ``` 8 | Input: nums = [1,2,3,4,5,6,7], k = 3 9 | Output: [5,6,7,1,2,3,4] 10 | Explanation: 11 | rotate 1 steps to the right: [7,1,2,3,4,5,6] 12 | rotate 2 steps to the right: [6,7,1,2,3,4,5] 13 | rotate 3 steps to the right: [5,6,7,1,2,3,4] 14 | ``` 15 | 16 | Example 2: 17 | 18 | ``` 19 | Input: nums = [-1,-100,3,99], k = 2 20 | Output: [3,99,-1,-100] 21 | Explanation: 22 | rotate 1 steps to the right: [99,-1,-100,3] 23 | rotate 2 steps to the right: [3,99,-1,-100] 24 | ``` 25 | 26 | Constraints: 27 | 28 | 1 <= nums.length <= 10^5 29 | -2^31 <= nums[i] <= 2^31 - 1 30 | 0 <= k <= 10^5 31 | 32 | 33 | Follow up: 34 | 35 | Try to come up with as many solutions as you can. There are at least three different ways to solve this problem. 36 | Could you do it in-place with O(1) extra space? -------------------------------------------------------------------------------- /doc/101-200/198-house-robber.md: -------------------------------------------------------------------------------- 1 | You are a professional robber planning to rob houses along a street. 2 | 3 | Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night. 4 | 5 | Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police. 6 | 7 | Example 1: 8 | 9 | ``` 10 | Input: nums = [1,2,3,1] 11 | Output: 4 12 | Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3). 13 | Total amount you can rob = 1 + 3 = 4. 14 | ``` 15 | 16 | Example 2: 17 | 18 | ``` 19 | Input: nums = [2,7,9,3,1] 20 | Output: 12 21 | Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1). 22 | Total amount you can rob = 2 + 9 + 1 = 12. 23 | ``` 24 | 25 | Constraints: 26 | 27 | 1 <= nums.length <= 100 28 | 29 | 0 <= nums[i] <= 400 30 | -------------------------------------------------------------------------------- /doc/101-200/199-binary-tree-right-side-view.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/binary-tree-right-side-view/ 2 | 3 | Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. 4 | 5 | 6 | ## EX 7 | 8 | Example 1: 9 | 10 |  11 | 12 | ``` 13 | Input: root = [1,2,3,null,5,null,4] 14 | Output: [1,3,4] 15 | ``` 16 | 17 | Example 2: 18 | 19 | ``` 20 | Input: root = [1,null,3] 21 | Output: [1,3] 22 | ``` 23 | 24 | Example 3: 25 | 26 | ``` 27 | Input: root = [] 28 | Output: [] 29 | ``` 30 | 31 | ## Constraints: 32 | 33 | The number of nodes in the tree is in the range [0, 100]. 34 | 35 | -100 <= Node.val <= 100 36 | -------------------------------------------------------------------------------- /doc/101-200/200-number-of-islands.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/number-of-islands/ 2 | 3 | Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. 4 | 5 | An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. 6 | 7 | You may assume all four edges of the grid are all surrounded by water. 8 | 9 | ## EX 10 | 11 | Example 1: 12 | 13 | ``` 14 | Input: grid = [ 15 | ["1","1","1","1","0"], 16 | ["1","1","0","1","0"], 17 | ["1","1","0","0","0"], 18 | ["0","0","0","0","0"] 19 | ] 20 | Output: 1 21 | ``` 22 | 23 | Example 2: 24 | 25 | ``` 26 | Input: grid = [ 27 | ["1","1","0","0","0"], 28 | ["1","1","0","0","0"], 29 | ["0","0","1","0","0"], 30 | ["0","0","0","1","1"] 31 | ] 32 | 33 | Output: 3 34 | ``` 35 | 36 | ## Constraints: 37 | 38 | m == grid.length 39 | n == grid[i].length 40 | 1 <= m, n <= 300 41 | grid[i][j] is '0' or '1'. -------------------------------------------------------------------------------- /doc/1300-1400/1305-all-elements-in-two-binary-search-trees.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/all-elements-in-two-binary-search-trees/ 2 | 3 | Given two binary search trees root1 and root2. 4 | 5 | Return a list containing all the integers from both trees sorted in ascending order. 6 | 7 | 8 | 9 | Example 1: 10 | 11 |  12 | 13 | Input: root1 = [2,1,4], root2 = [1,0,3] 14 | Output: [0,1,1,2,3,4] 15 | Example 2: 16 | 17 | Input: root1 = [0,-10,10], root2 = [5,1,7,0,2] 18 | Output: [-10,0,0,1,2,5,7,10] 19 | Example 3: 20 | 21 | Input: root1 = [], root2 = [5,1,7,0,2] 22 | Output: [0,1,2,5,7] 23 | Example 4: 24 | 25 | Input: root1 = [0,-10,10], root2 = [] 26 | Output: [-10,0,10] 27 | Example 5: 28 | 29 |  30 | 31 | Input: root1 = [1,null,8], root2 = [8,1] 32 | Output: [1,1,8,8] 33 | 34 | 35 | Constraints: 36 | 37 | Each tree has at most 5000 nodes. 38 | Each node's value is between [-10^5, 10^5]. -------------------------------------------------------------------------------- /doc/200-300/201-bitwise-and-of-numbers-range.md: -------------------------------------------------------------------------------- 1 | Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive. 2 | 3 | 4 | 5 | Example 1: 6 | 7 | ``` 8 | Input: left = 5, right = 7 9 | Output: 4 10 | ``` 11 | 12 | Example 2: 13 | 14 | ``` 15 | Input: left = 0, right = 0 16 | Output: 0 17 | ``` 18 | 19 | Example 3: 20 | 21 | ``` 22 | Input: left = 1, right = 2147483647 23 | Output: 0 24 | ``` 25 | 26 | Constraints: 27 | 28 | 0 <= left <= right <= 2^31 - 1 -------------------------------------------------------------------------------- /doc/200-300/202-happy-number.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/happy-number/description/ 2 | 3 | Write an algorithm to determine if a number n is happy. 4 | 5 | A happy number is a number defined by the following process: 6 | 7 | Starting with any positive integer, replace the number by the sum of the squares of its digits. 8 | 9 | Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. 10 | 11 | Those numbers for which this process ends in 1 are happy. 12 | 13 | Return true if n is a happy number, and false if not. 14 | 15 | Example 1: 16 | 17 | ``` 18 | Input: n = 19 19 | Output: true 20 | Explanation: 21 | 1^2 + 9^2 = 82 22 | 8^2 + 2^2 = 68 23 | 6^2 + 8^2 = 100 24 | 1^2 + 0^2 + 0^2 = 1 25 | ``` 26 | 27 | Example 2: 28 | 29 | ``` 30 | Input: n = 2 31 | Output: false 32 | ``` 33 | 34 | Constraints: 35 | 36 | 1 <= n <= 2^31 - 1 37 | 38 | -------------------------------------------------------------------------------- /doc/200-300/203-remove-linked-list-elements.md: -------------------------------------------------------------------------------- 1 | Given the head of a linked list and an integer val, remove all the nodes of the linked list that has Node.val == val, and return the new head. 2 | 3 | ## EX 4 | 5 | Example 1: 6 | 7 | ``` 8 | Input: head = [1,2,6,3,4,5,6], val = 6 9 | Output: [1,2,3,4,5] 10 | ``` 11 | 12 | Example 2: 13 | 14 | ``` 15 | Input: head = [], val = 1 16 | Output: [] 17 | ``` 18 | 19 | Example 3: 20 | 21 | ``` 22 | Input: head = [7,7,7,7], val = 7 23 | Output: [] 24 | ``` 25 | 26 | ## Constraints: 27 | 28 | The number of nodes in the list is in the range [0, 104]. 29 | 30 | 1 <= Node.val <= 50 31 | 32 | 0 <= val <= 50 -------------------------------------------------------------------------------- /doc/200-300/204-count-primes.md: -------------------------------------------------------------------------------- 1 | Given an integer n, return the number of prime numbers that are strictly less than n. 2 | 3 | 4 | 5 | Example 1: 6 | 7 | ``` 8 | Input: n = 10 9 | Output: 4 10 | Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7. 11 | ``` 12 | 13 | Example 2: 14 | 15 | ``` 16 | Input: n = 0 17 | Output: 0 18 | ``` 19 | 20 | Example 3: 21 | 22 | ``` 23 | Input: n = 1 24 | Output: 0 25 | ``` 26 | 27 | Constraints: 28 | 29 | 0 <= n <= 5 * 10^6 -------------------------------------------------------------------------------- /doc/200-300/205-isomorphic-strings.md: -------------------------------------------------------------------------------- 1 | Given two strings s and t, determine if they are isomorphic. 2 | 3 | Two strings s and t are isomorphic if the characters in s can be replaced to get t. 4 | 5 | All occurrences of a character must be replaced with another character while preserving the order of characters. 6 | 7 | No two characters may map to the same character, but a character may map to itself. 8 | 9 | Example 1: 10 | 11 | ``` 12 | Input: s = "egg", t = "add" 13 | Output: true 14 | ``` 15 | 16 | 17 | Example 2: 18 | 19 | ``` 20 | Input: s = "foo", t = "bar" 21 | Output: false 22 | ``` 23 | 24 | Example 3: 25 | 26 | ``` 27 | Input: s = "paper", t = "title" 28 | Output: true 29 | ``` 30 | 31 | Constraints: 32 | 33 | 1 <= s.length <= 5 * 10^4 34 | t.length == s.length 35 | s and t consist of any valid ascii character. -------------------------------------------------------------------------------- /doc/200-300/206-reverse-linked-list.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/reverse-linked-list/ 2 | 3 | Given the head of a singly linked list, reverse the list, and return the reversed list. 4 | 5 | Example 1: 6 | 7 |  8 | 9 | ``` 10 | Input: head = [1,2,3,4,5] 11 | Output: [5,4,3,2,1] 12 | ``` 13 | 14 | Example 2: 15 | 16 |  17 | 18 | ``` 19 | Input: head = [1,2] 20 | Output: [2,1] 21 | ``` 22 | 23 | Example 3: 24 | 25 | ``` 26 | Input: head = [] 27 | Output: [] 28 | ``` 29 | 30 | Constraints: 31 | 32 | The number of nodes in the list is the range [0, 5000]. 33 | 34 | -5000 <= Node.val <= 5000 35 | 36 | 37 | Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both? 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /doc/200-300/206-single-number-iii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/single-number-iii/ 2 | 3 | Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order. 4 | 5 | Follow up: Your algorithm should run in linear runtime complexity. Could you implement it using only constant space complexity? 6 | 7 | 8 | 9 | Example 1: 10 | 11 | Input: nums = [1,2,1,3,2,5] 12 | Output: [3,5] 13 | Explanation: [5, 3] is also a valid answer. 14 | Example 2: 15 | 16 | Input: nums = [-1,0] 17 | Output: [-1,0] 18 | Example 3: 19 | 20 | Input: nums = [0,1] 21 | Output: [1,0] 22 | 23 | 24 | Constraints: 25 | 26 | 2 <= nums.length <= 3 * 10^4 27 | -2^31 <= nums[i] <= 2^31 - 1 28 | 29 | Each integer in nums will appear twice, only two integers will appear once. -------------------------------------------------------------------------------- /doc/200-300/208-implement-trie-prefix-tree.md: -------------------------------------------------------------------------------- 1 | Trie(发音类似 "try")或者说 前缀树 是一种树形数据结构,用于高效地存储和检索字符串数据集中的键。 2 | 3 | 这一数据结构有相当多的应用情景,例如自动补完和拼写检查。 4 | 5 | 请你实现 Trie 类: 6 | 7 | Trie() 初始化前缀树对象。 8 | void insert(String word) 向前缀树中插入字符串 word 。 9 | boolean search(String word) 如果字符串 word 在前缀树中,返回 true(即,在检索之前已经插入);否则,返回 false 。 10 | boolean startsWith(String prefix) 如果之前已经插入的字符串 word 的前缀之一为 prefix ,返回 true ;否则,返回 false 。 11 | 12 | 13 | 示例: 14 | 15 | ``` 16 | 输入 17 | ["Trie", "insert", "search", "search", "startsWith", "insert", "search"] 18 | [[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]] 19 | 输出 20 | [null, null, true, false, true, null, true] 21 | 22 | 解释 23 | Trie trie = new Trie(); 24 | trie.insert("apple"); 25 | trie.search("apple"); // 返回 True 26 | trie.search("app"); // 返回 False 27 | trie.startsWith("app"); // 返回 True 28 | trie.insert("app"); 29 | trie.search("app"); // 返回 True 30 | ``` 31 | 32 | 提示: 33 | 34 | 1 <= word.length, prefix.length <= 2000 35 | 36 | word 和 prefix 仅由小写英文字母组成 37 | 38 | insert、search 和 startsWith 调用次数 总计 不超过 3 * 10^4 次 39 | -------------------------------------------------------------------------------- /doc/200-300/209-minimum-size-subarray-sum.md: -------------------------------------------------------------------------------- 1 | Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. 2 | 3 | If there is no such subarray, return 0 instead. 4 | 5 | Example 1: 6 | 7 | ``` 8 | Input: target = 7, nums = [2,3,1,2,4,3] 9 | Output: 2 10 | Explanation: The subarray [4,3] has the minimal length under the problem constraint. 11 | ``` 12 | 13 | Example 2: 14 | 15 | ``` 16 | Input: target = 4, nums = [1,4,4] 17 | Output: 1 18 | ``` 19 | 20 | Example 3: 21 | 22 | ``` 23 | Input: target = 11, nums = [1,1,1,1,1,1,1,1] 24 | Output: 0 25 | ``` 26 | 27 | 28 | Constraints: 29 | 30 | 1 <= target <= 10^9 31 | 1 <= nums.length <= 10^5 32 | 1 <= nums[i] <= 10^4 33 | 34 | 35 | Follow up: If you have figured out the O(n) solution, try coding another solution of which the time complexity is O(n log(n)). -------------------------------------------------------------------------------- /doc/200-300/213-house-robber-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.cn/problems/house-robber-ii/ 2 | 3 | # 213. 打家劫舍 II 4 | 5 | 你是一个专业的小偷,计划偷窃沿街的房屋,每间房内都藏有一定的现金。 6 | 7 | **这个地方所有的房屋都围成一圈,这意味着第一个房屋和最后一个房屋是紧挨着的。** 8 | 9 | 同时,相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警 。 10 | 11 | 给定一个代表每个房屋存放金额的非负整数数组,计算你 在不触动警报装置的情况下 ,今晚能够偷窃到的最高金额。 12 | 13 | ## 例子 14 | 15 | 示例 1: 16 | 17 | ``` 18 | 输入:nums = [2,3,2] 19 | 输出:3 20 | 解释:你不能先偷窃 1 号房屋(金额 = 2),然后偷窃 3 号房屋(金额 = 2), 因为他们是相邻的。 21 | ``` 22 | 23 | 示例 2: 24 | 25 | ``` 26 | 输入:nums = [1,2,3,1] 27 | 输出:4 28 | 解释:你可以先偷窃 1 号房屋(金额 = 1),然后偷窃 3 号房屋(金额 = 3)。 29 | 偷窃到的最高金额 = 1 + 3 = 4 。 30 | ``` 31 | 32 | 示例 3: 33 | 34 | ``` 35 | 输入:nums = [1,2,3] 36 | 输出:3 37 | ``` 38 | 39 | ## 提示: 40 | 41 | 1 <= nums.length <= 100 42 | 43 | 0 <= nums[i] <= 1000 44 | -------------------------------------------------------------------------------- /doc/200-300/214-shortest-palindrome.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/shortest-palindrome/ 2 | 3 | You are given a string s. You can convert s to a palindrome by adding characters in front of it. 4 | 5 | Return the shortest palindrome you can find by performing this transformation. 6 | 7 | Example 1: 8 | 9 | ``` 10 | Input: s = "aacecaaa" 11 | Output: "aaacecaaa" 12 | ``` 13 | 14 | Example 2: 15 | 16 | ``` 17 | Input: s = "abcd" 18 | Output: "dcbabcd" 19 | ``` 20 | 21 | Constraints: 22 | 23 | 0 <= s.length <= 5 * 10^4 24 | s consists of lowercase English letters only. 25 | 26 | -------------------------------------------------------------------------------- /doc/200-300/215-kth-largest-element-in-an-array.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/kth-largest-element-in-an-array/ 2 | 3 | Given an integer array nums and an integer k, return the kth largest element in the array. 4 | 5 | Note that it is the kth largest element in the sorted order, not the kth distinct element. 6 | 7 | 8 | 9 | Example 1: 10 | 11 | Input: nums = [3,2,1,5,6,4], k = 2 12 | Output: 5 13 | Example 2: 14 | 15 | Input: nums = [3,2,3,1,2,4,5,5,6], k = 4 16 | Output: 4 17 | 18 | 19 | Constraints: 20 | 21 | 1 <= k <= nums.length <= 10^4 22 | 23 | -10^4 <= nums[i] <= 10^4 -------------------------------------------------------------------------------- /doc/200-300/217-contains-duplicate.md: -------------------------------------------------------------------------------- 1 | Given an integer array nums, return true if any value appears at least twice in the array, 2 | and return false if every element is distinct. 3 | 4 | 5 | Example 1: 6 | 7 | Input: nums = [1,2,3,1] 8 | Output: true 9 | Example 2: 10 | 11 | Input: nums = [1,2,3,4] 12 | Output: false 13 | Example 3: 14 | 15 | Input: nums = [1,1,1,3,3,4,3,2,4,2] 16 | Output: true 17 | 18 | 19 | Constraints: 20 | 21 | 1 <= nums.length <= 10^5 22 | -10^9 <= nums[i] <= 10^9 23 | 24 | https://leetcode.com/problems/contains-duplicate/ -------------------------------------------------------------------------------- /doc/200-300/229-majority-element-ii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/majority-element-ii/ 2 | 3 | Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. 4 | 5 | Follow-up: Could you solve the problem in linear time and in O(1) space? 6 | 7 | 8 | 9 | Example 1: 10 | 11 | Input: nums = [3,2,3] 12 | Output: [3] 13 | Example 2: 14 | 15 | Input: nums = [1] 16 | Output: [1] 17 | Example 3: 18 | 19 | Input: nums = [1,2] 20 | Output: [1,2] 21 | 22 | 23 | Constraints: 24 | 25 | 1 <= nums.length <= 5 * 10^4 26 | 27 | -10^9 <= nums[i] <= 10^9 -------------------------------------------------------------------------------- /doc/200-300/233-number-of-digit-one.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/number-of-digit-one/ 2 | 3 | Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n. 4 | 5 | 6 | 7 | Example 1: 8 | 9 | Input: n = 13 10 | Output: 6 11 | Example 2: 12 | 13 | Input: n = 0 14 | Output: 0 15 | 16 | 17 | Constraints: 18 | 19 | 0 <= n <= 2 * 10^9 -------------------------------------------------------------------------------- /doc/200-300/257-binary-tree-paths.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/binary-tree-paths/ 2 | 3 | Given the root of a binary tree, return all root-to-leaf paths in any order. 4 | 5 | A leaf is a node with no children. 6 | 7 | 8 | 9 | Example 1: 10 | 11 |  12 | 13 | Input: root = [1,2,3,null,5] 14 | Output: ["1->2->5","1->3"] 15 | Example 2: 16 | 17 | Input: root = [1] 18 | Output: ["1"] 19 | 20 | 21 | Constraints: 22 | 23 | The number of nodes in the tree is in the range [1, 100]. 24 | -100 <= Node.val <= 100 -------------------------------------------------------------------------------- /doc/206-reverse-linked-list.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/reverse-linked-list/ 2 | 3 | Given the head of a singly linked list, reverse the list, and return the reversed list. 4 | 5 | 6 | 7 | Example 1: 8 | 9 | 10 | Input: head = [1,2,3,4,5] 11 | Output: [5,4,3,2,1] 12 | Example 2: 13 | 14 | 15 | Input: head = [1,2] 16 | Output: [2,1] 17 | Example 3: 18 | 19 | Input: head = [] 20 | Output: [] 21 | 22 | 23 | Constraints: 24 | 25 | The number of nodes in the list is the range [0, 5000]. 26 | -5000 <= Node.val <= 5000 27 | 28 | 29 | Follow up: A linked list can be reversed either iteratively or recursively. 30 | 31 | Could you implement both? -------------------------------------------------------------------------------- /doc/300-400/347-top-k-frequent-elements.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/top-k-frequent-elements/ 2 | 3 | Given an integer array nums and an integer k, return the k most frequent elements. 4 | 5 | You may return the answer in any order. 6 | 7 | Example 1: 8 | 9 | Input: nums = [1,1,1,2,2,3], k = 2 10 | Output: [1,2] 11 | 12 | Example 2: 13 | 14 | Input: nums = [1], k = 1 15 | Output: [1] 16 | 17 | 18 | Constraints: 19 | 20 | 1 <= nums.legth <= 10^5 21 | 22 | k is in the range [1, the number of unique elements in the array]. 23 | 24 | It is guaranteed that the answer is unique. 25 | 26 | 27 | Follow up: Your algorithm's time complexity must be better than O(n log n), where n is the array's size. -------------------------------------------------------------------------------- /doc/400-500/437-path-sum-iii.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/path-sum-iii/ 2 | 3 | You are given a binary tree in which each node contains an integer value. 4 | 5 | Find the number of paths that sum to a given value. 6 | 7 | The path does not need to start or end at the root or a leaf, but it must go downwards (traveling only from parent nodes to child nodes). 8 | 9 | The tree has no more than 1,000 nodes and the values are in the range -1,000,000 to 1,000,000. 10 | 11 | Example: 12 | 13 | ``` 14 | root = [10,5,-3,3,2,null,11,3,-2,null,1], sum = 8 15 | 16 | 10 17 | / \ 18 | 5 -3 19 | / \ \ 20 | 3 2 11 21 | / \ \ 22 | 3 -2 1 23 | ``` 24 | 25 | Return 3. The paths that sum to 8 are: 26 | 27 | 1. 5 -> 3 28 | 2. 5 -> 2 -> 1 29 | 3. -3 -> 11 -------------------------------------------------------------------------------- /doc/500-600/509-fibonacci-number.md: -------------------------------------------------------------------------------- 1 | 斐波那契数,通常用 F(n) 表示,形成的序列称为 斐波那契数列 。该数列由 0 和 1 开始,后面的每一项数字都是前面两项数字的和。也就是: 2 | 3 | F(0) = 0,F(1) = 1 4 | F(n) = F(n - 1) + F(n - 2),其中 n > 1 5 | 给你 n ,请计算 F(n) 。 6 | 7 | 8 | 9 | 示例 1: 10 | 11 | 输入:2 12 | 输出:1 13 | 解释:F(2) = F(1) + F(0) = 1 + 0 = 1 14 | 示例 2: 15 | 16 | 输入:3 17 | 输出:2 18 | 解释:F(3) = F(2) + F(1) = 1 + 1 = 2 19 | 示例 3: 20 | 21 | 输入:4 22 | 输出:3 23 | 解释:F(4) = F(3) + F(2) = 2 + 1 = 3 24 | 25 | 26 | 提示: 27 | 28 | 0 <= n <= 30 29 | 30 | 来源:力扣(LeetCode) 31 | 链接:https://leetcode-cn.com/problems/fibonacci-number 32 | 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 -------------------------------------------------------------------------------- /doc/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/houbb/leetcode/ca063827c05660d16a1e545d818903068467e2b7/doc/README.md -------------------------------------------------------------------------------- /src/main/java/com/github/houbb/leetcode/F000T100/T009_PalindromeNumber.java: -------------------------------------------------------------------------------- 1 | package com.github.houbb.leetcode.F000T100; 2 | 3 | /** 4 | * @author binbin.hou 5 | * @since 1.0.0 6 | */ 7 | public class T009_PalindromeNumber { 8 | 9 | /** 10 | * 优化思路 11 | *
12 | * 可以使用字符串,中间往两边均摊的方法。 13 | *
14 | * Runtime: 7 ms, faster than 76.19% of Java online submissions for Palindrome Number.
15 | * Memory Usage: 38.5 MB, less than 92.10% of Java online submissions for Palindrome Number.
16 | *
17 | * @param x 数字
18 | * @return 结果
19 | * @since v1
20 | */
21 | public boolean isPalindrome(int x) {
22 | String string = String.valueOf(x);
23 | final int length = string.length();
24 | int mid = length >> 1;
25 |
26 | // 从中间往两边均摊
27 | for (int i = 0; i < mid; i++) {
28 | if (string.charAt(i) != string.charAt(length - i - 1)) {
29 | return false;
30 | }
31 | }
32 | return true;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/github/houbb/leetcode/F000T100/T009_PalindromeNumberV2.java:
--------------------------------------------------------------------------------
1 | package com.github.houbb.leetcode.F000T100;
2 |
3 | /**
4 | * @author binbin.hou
5 | * @since 1.0.0
6 | */
7 | public class T009_PalindromeNumberV2 {
8 |
9 | /**
10 | * 最佳解法
11 | *
12 | * 【效果】
13 | *
14 | * @param x 数字
15 | * @return 结果
16 | * @since best
17 | */
18 | public boolean isPalindrome(int x) {
19 | int temp = x;
20 | int ds = 0;
21 | while (temp > 0) {
22 | // 直接反向操作,计算逆序的数值
23 | ds = ds * 10 + (temp % 10);
24 |
25 | // 保留的高位
26 | temp /= 10;
27 | }
28 |
29 | return (x - ds) == 0;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/github/houbb/leetcode/F000T100/T026_RemoveDuplicatesFromSortedArray.java:
--------------------------------------------------------------------------------
1 | package com.github.houbb.leetcode.F000T100;
2 |
3 | /**
4 | * @author binbin.hou
5 | * @since 1.0.0
6 | */
7 | public class T026_RemoveDuplicatesFromSortedArray {
8 |
9 | /**
10 | * 思路
11 | *
12 | * 1. 返回的结果要对
13 | * 2. 返回的长度对应的数组要唯一。
14 | *
15 | * 【效果】
16 | * Runtime: 0 ms, faster than 100.00% of Java online submissions for Remove Duplicates from Sorted Array.
17 | * Memory Usage: 41.3 MB, less than 59.78% of Java online submissions for Remove Duplicates from Sorted Array.
18 | *
19 | * @param nums 数组
20 | * @return 结果
21 | * @since v1
22 | */
23 | public int removeDuplicates(int[] nums) {
24 | int i = 0;
25 | for (int n : nums) {
26 | // 将后面不同的元素复制过来
27 | if (i == 0 || n > nums[i-1]) {
28 | nums[i++] = n;
29 | }
30 | }
31 | return i;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/github/houbb/leetcode/F000T100/T026_RemoveDuplicatesFromSortedArrayV2.java:
--------------------------------------------------------------------------------
1 | package com.github.houbb.leetcode.F000T100;
2 |
3 | /**
4 | * @author binbin.hou
5 | * @since 1.0.0
6 | */
7 | public class T026_RemoveDuplicatesFromSortedArrayV2 {
8 |
9 | /**
10 | * 思路
11 | *
12 | * 1. 返回的结果要对
13 | * 2. 返回的长度对应的数组要唯一。
14 | *
15 | * @param nums 数组
16 | * @return 结果
17 | * @since v1
18 | */
19 | public int removeDuplicates(int[] nums) {
20 | int i = 0;
21 | for (int n : nums) {
22 | // 前兩個元素不用考慮
23 | // 大于上一个,或者等于上一个且大于上上个
24 | if ((i == 0 || i == 1) || (n > nums[i-1] || (n > nums[i-2] && n == nums[i-1]))) {
25 | nums[i++] = n;
26 | }
27 | }
28 | return i;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/github/houbb/leetcode/F000T100/T035_SearchInsertPosition.java:
--------------------------------------------------------------------------------
1 | package com.github.houbb.leetcode.F000T100;
2 |
3 | /**
4 | * @author d
5 | * @since 1.0.0
6 | */
7 | public class T035_SearchInsertPosition {
8 |
9 | /**
10 | * 先处理 O(n) 的方式,直接遍历,很简单
11 | *
12 | * 100%,老实说,这一题的测试用例没有区分度。
13 | *
14 | * @param nums
15 | * @param target
16 | * @return
17 | */
18 | public int searchInsert(int[] nums, int target) {
19 | for(int i = 0; i < nums.length; i++) {
20 | int value = nums[i];
21 |
22 | if(target == value) {
23 | return i;
24 | }
25 |
26 | if(target < value) {
27 | return i;
28 | }
29 | }
30 |
31 | // 放在最后
32 | return nums.length;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/github/houbb/leetcode/F000T100/T062_UniquePaths.java:
--------------------------------------------------------------------------------
1 | package com.github.houbb.leetcode.F000T100;
2 |
3 | /**
4 | * @author binbin.hou
5 | * @since 1.0.0
6 | */
7 | public class T062_UniquePaths {
8 |
9 | public int uniquePaths(int m, int n) {
10 | int[][] dp = new int[m][n];
11 |
12 | for(int i = 0; i < m; i++) {
13 | for(int j = 0; j < n; j++) {
14 | // 这种其实是不符合条件的,不过我们设定初始值 dp[0][0] = 1
15 | if(i == 0 || j == 0) {
16 | dp[i][j] = 1;
17 | } else {
18 | dp[i][j] = dp[i-1][j] + dp[i][j-1];
19 | }
20 | }
21 | }
22 |
23 | // 返回所有可能的结果
24 | return dp[m-1][n-1];
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/com/github/houbb/leetcode/F000T100/T069_Sqrtx.java:
--------------------------------------------------------------------------------
1 | package com.github.houbb.leetcode.F000T100;
2 |
3 | public class T069_Sqrtx {
4 |
5 | /**
6 | * math.sqrt 的实现原理到底是什么?
7 | *
8 | * 最简单的方式,从 i=1开始迭代
9 | * @param x 数字
10 | * @return 结果
11 | */
12 | public int mySqrt(int x) {
13 | if(x == 0) {
14 | return 0;
15 | }
16 |
17 | for(int i = 1; i <= x; i++) {
18 | // 用除法,替代乘法,避免越界
19 | int div = x / i;
20 | if(div == i) {
21 | return i;
22 | }
23 | if(div < i) {
24 | return i-1;
25 | }
26 | }
27 |
28 | return 0;
29 | }
30 |
31 | public static void main(String[] args) {
32 | T069_Sqrtx sqrtx = new T069_Sqrtx();
33 |
34 | System.out.println(sqrtx.mySqrt(4));
35 | System.out.println(sqrtx.mySqrt(8));
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/github/houbb/leetcode/F000T100/T088_MergeSortedArray.java:
--------------------------------------------------------------------------------
1 | package com.github.houbb.leetcode.F000T100;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.List;
6 |
7 | public class T088_MergeSortedArray {
8 |
9 | /**
10 | * 合并
11 | *
12 | * @param nums1
13 | * @param m
14 | * @param nums2
15 | * @param n
16 | */
17 | public void merge(int[] nums1, int m, int[] nums2, int n) {
18 | // 最后的结果放在 nums1 里面...
19 |
20 | List project: leetcode-LongestCommonPrefixTest create on 2020/6/11 22:32 project: leetcode-RemoveNthNodeFromEndOfListTest create on 2020/6/16 22:12 > threeSum(int[] nums) {
15 | Set
> res = new HashSet<>();
16 |
17 | final int n = nums.length;
18 | for(int i = 0; i < n; i++){
19 | for(int j = i+1; j < n; j++) {
20 | for(int k = j+1; k < n; k++) {
21 | if(nums[i]+nums[j]+nums[k] == 0) {
22 | List
> fourSum(int[] nums, int target) {
9 | Set
> res = new HashSet<>();
10 |
11 | final int n = nums.length;
12 | for(int i = 0; i < n; i++) {
13 | for(int j = i+1; j < n; j++) {
14 | for(int k = j+1; k < n; k++) {
15 | for(int l = k+1; l < n; l++) {
16 | if(nums[i] + nums[j] + nums[k] + nums[l] == target) {
17 | List