├── .gitignore
├── .idea
├── .gitignore
├── Data_Structure_Demo03.iml
├── aws.xml
├── checkstyle-idea.xml
├── compiler.xml
├── encodings.xml
├── git_toolbox_prj.xml
├── jarRepositories.xml
├── jpa-buddy.xml
├── misc.xml
├── modules.xml
├── setting.xml
├── sonarlint
│ └── issuestore
│ │ ├── 0
│ │ ├── 7
│ │ │ └── 07c4a297613af8e1c0cad22a3dd6980483604993
│ │ ├── b
│ │ │ └── 0b254e7545574216406e39652769f9838fb6d4e3
│ │ └── e
│ │ │ └── 0e2d5e943fb0ba0e9e21918bf98ed77f55a127ca
│ │ ├── 2
│ │ └── 6
│ │ │ └── 26c396588b2458a954b767018e763575e57dc9f6
│ │ ├── 3
│ │ └── 6
│ │ │ └── 366262d0a6a58b2a19a0c1afd3a17980c7b149c8
│ │ ├── 4
│ │ └── f
│ │ │ └── 4f6e6a5dcf8687c45ef19eae7747c66c87dff21f
│ │ ├── 5
│ │ └── 3
│ │ │ └── 53f83880527ccd54f2016a1ace55f18fb16a5205
│ │ ├── 8
│ │ └── d
│ │ │ └── 8d3d15e619e025684b8d4d55213cce21405bc61d
│ │ ├── 9
│ │ ├── 2
│ │ │ └── 92513f27320deeb9f01943f822cbe77eddf8ba73
│ │ └── d
│ │ │ └── 9d1285124cc6e366657924a2bcec45e25c843e6e
│ │ ├── a
│ │ └── 8
│ │ │ └── a8a09f2c5e56bc52746937a31c67fb2fd9f5d411
│ │ ├── f
│ │ ├── 1
│ │ │ └── f17ca5bb773c72da0c5b4ec1ee7ebdd8013a0cb0
│ │ └── 4
│ │ │ ├── f4c43a051654c4b5e41040d2821920de6838ff25
│ │ │ └── f4f70628310297cd6a84f2cf4986c275a911d7f1
│ │ └── index.pb
├── uiDesigner.xml
├── vcs.xml
└── workspace.xml
├── Demo1
├── pom.xml
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── shf
│ │ ├── Main.java
│ │ ├── Recursion
│ │ └── Test.java
│ │ └── sort
│ │ ├── BubbleSort.java
│ │ ├── CountSort.java
│ │ ├── DataChecker.java
│ │ ├── InsertionSort.java
│ │ ├── MergeSort.java
│ │ ├── QuickSort.java
│ │ ├── RadixSort.java
│ │ ├── SelectionSort.java
│ │ ├── ShellSort.java
│ │ └── utils
│ │ ├── Print.java
│ │ └── Swap.java
└── target
│ └── classes
│ └── com
│ └── shf
│ ├── Main.class
│ ├── Recursion
│ └── Test.class
│ └── sort
│ ├── BubbleSort.class
│ ├── CountSort.class
│ ├── DataChecker.class
│ ├── InsertionSort.class
│ ├── MergeSort.class
│ ├── QuickSort.class
│ ├── RadixSort.class
│ ├── SelectionSort.class
│ ├── ShellSort.class
│ └── utils
│ ├── Print.class
│ └── Swap.class
├── out
└── production
│ └── algorithm-primary-main
│ ├── class01
│ ├── Code01_PrintBinary.class
│ ├── Code02_SumOfFactorial.class
│ ├── Code03_Sort.class
│ ├── Code04_SelectionSort.class
│ ├── Code05_BubbleSort.class
│ └── Code06_InsertionSort.class
│ ├── class02
│ ├── Code01_PreSum$RangeSum1.class
│ ├── Code01_PreSum$RangeSum2.class
│ ├── Code01_PreSum.class
│ ├── Code02_RandToRand$RandomBox.class
│ ├── Code02_RandToRand.class
│ ├── Code03_Comp.class
│ ├── Code03_EqualProbabilityRandom$RandomBox.class
│ └── Code03_EqualProbabilityRandom.class
│ ├── class03
│ ├── Code01_BSExist.class
│ ├── Code02_BSNearLeft.class
│ ├── Code03_BSNearRight.class
│ ├── Code04_BSAwesome.class
│ ├── Code05_HashMapTreeMap$Node.class
│ └── Code05_HashMapTreeMap.class
│ ├── class04
│ ├── Code01_ReverseList$DoubleNode.class
│ ├── Code01_ReverseList$Node.class
│ ├── Code01_ReverseList.class
│ ├── Code02_LinkedListToQueueAndStack$MyQueue.class
│ ├── Code02_LinkedListToQueueAndStack$MyStack.class
│ ├── Code02_LinkedListToQueueAndStack$Node.class
│ ├── Code02_LinkedListToQueueAndStack.class
│ ├── Code03_DoubleLinkedListToDeque$MyDeque.class
│ ├── Code03_DoubleLinkedListToDeque$Node.class
│ ├── Code03_DoubleLinkedListToDeque.class
│ ├── Code04_ReverseNodesInKGroup$ListNode.class
│ ├── Code04_ReverseNodesInKGroup.class
│ ├── Code05_AddTwoNumbers$ListNode.class
│ ├── Code05_AddTwoNumbers.class
│ ├── Code06_MergeTwoSortedLinkedList$ListNode.class
│ └── Code06_MergeTwoSortedLinkedList.class
│ ├── class05
│ ├── Code01_BitMap1$BitMap.class
│ ├── Code01_BitMap1.class
│ ├── Code02_BitMap2$BitMap.class
│ ├── Code02_BitMap2.class
│ └── Code03_BitAddMinusMultiDiv.class
│ ├── class06
│ ├── Code01_MergeKSortedLists$ListNode.class
│ ├── Code01_MergeKSortedLists$ListNodeComparator.class
│ ├── Code01_MergeKSortedLists.class
│ ├── Code02_SameTree$TreeNode.class
│ ├── Code02_SameTree.class
│ ├── Code03_SymmetricTree$TreeNode.class
│ ├── Code03_SymmetricTree.class
│ ├── Code04_MaximumDepthOfBinaryTree$TreeNode.class
│ ├── Code04_MaximumDepthOfBinaryTree.class
│ ├── Code05_ConstructBinaryTreeFromPreorderAndInorderTraversal$TreeNode.class
│ ├── Code05_ConstructBinaryTreeFromPreorderAndInorderTraversal.class
│ ├── ShowComparator$AgeComparator.class
│ ├── ShowComparator$IdComparator.class
│ ├── ShowComparator$Student.class
│ ├── ShowComparator.class
│ ├── ShowComparator2$IdComparator.class
│ ├── ShowComparator2$MyComparator.class
│ ├── ShowComparator2$Student.class
│ ├── ShowComparator2.class
│ ├── TraversalBinaryTree$Node.class
│ └── TraversalBinaryTree.class
│ ├── class07
│ ├── Code01_BinaryTreeLevelOrderTraversalII$TreeNode.class
│ ├── Code01_BinaryTreeLevelOrderTraversalII.class
│ ├── Code02_BalancedBinaryTree$Info.class
│ ├── Code02_BalancedBinaryTree$TreeNode.class
│ ├── Code02_BalancedBinaryTree.class
│ ├── Code03_PathSum$TreeNode.class
│ ├── Code03_PathSum.class
│ ├── Code04_PathSumII$TreeNode.class
│ ├── Code04_PathSumII.class
│ ├── Code05_IsBinarySearchTree$Info.class
│ ├── Code05_IsBinarySearchTree$TreeNode.class
│ └── Code05_IsBinarySearchTree.class
│ └── class08
│ ├── Code01_GetMax.class
│ ├── Code02_MergeSort.class
│ ├── Code03_PartitionAndQuickSort$Job.class
│ └── Code03_PartitionAndQuickSort.class
├── publicclass2020
└── src
│ ├── class001
│ ├── Code01_PosArrayToBST.java
│ └── Code02_ContainAllCharExactly.java
│ ├── class002
│ ├── Code01_MakeNo.java
│ └── Code02_KthMinPair.java
│ ├── class003
│ ├── Code01_LongestNoRepeatSubstring.java
│ ├── Code02_HowManyTypes.java
│ └── Code03_SubsquenceMaxModM.java
│ ├── class004
│ ├── Code01_QueryHobby.java
│ └── Code02_MergeRecord.java
│ ├── class005
│ ├── Code01_RotateString.java
│ └── Code02_RestoreWays.java
│ ├── class006
│ ├── Code01_Power2Diffs.java
│ └── Code02_Water.java
│ ├── class007
│ ├── Code01_RandToRand.java
│ ├── Code02_EqualProbabilityRandom.java
│ ├── Code03_FindHalfMajority.java
│ └── Code04_FindKMajor.java
│ ├── class008
│ ├── Code01_JumpGameII.java
│ └── Code02_LongestConsecutiveSequence.java
│ ├── class009
│ ├── Code01_SetMatrixZeroes.java
│ ├── Code02_SearchA2DMatrixII.java
│ └── Code03_LongestOnes.java
│ ├── class010
│ ├── Code01_SwapWithoutTmp.java
│ ├── Code02_GetMax.java
│ └── Code03_EvenTimesOddTimes.java
│ ├── class011
│ ├── Code01_CopyListWithRandom.java
│ └── Code02_JumpMinTimes.java
│ ├── class012
│ └── Code01_MoneyProblem.java
│ ├── class013
│ ├── Code01_PalindromeNumber.java
│ └── Code03_LongestNoRepeatSubstring.java
│ ├── class014
│ ├── Code01_CoverMax.java
│ └── Code02_MaxDistance.java
│ ├── class015
│ ├── Code01_CordCoverMaxPoint.java
│ ├── Code02_ColorLeftRight.java
│ ├── Code03_MaxABSBetweenLeftAndRight.java
│ └── Code04_TrappingRainWater.java
│ ├── class016
│ ├── Code01_RandToRand.java
│ ├── Code02_EqualProbabilityRandom.java
│ ├── Code03_FindHalfMajority.java
│ └── Code04_FindKMajor.java
│ ├── class017
│ ├── Code01_SubArrayMaxSum.java
│ └── Code02_SubMatrixMaxSum.java
│ ├── class018
│ ├── Code01_SqrtX.java
│ ├── Code02_PowXN.java
│ └── Code03_ContainerWithMostWater.java
│ ├── class019
│ ├── Code01_RotateImage.java
│ ├── Code02_ZigZagPrintMatrix.java
│ └── Code03_PrintStar.java
│ ├── class020
│ ├── Code01_RotateString.java
│ ├── Code02_HowManyTypes.java
│ ├── Code03_LongestNoRepeatSubstring.java
│ ├── Code04_CoverMax.java
│ └── Code05_MakeNo.java
│ ├── class021
│ ├── Code01_SwapWithoutTmp.java
│ ├── Code02_GetMax.java
│ └── Code03_EvenTimesOddTimes.java
│ ├── class022
│ ├── Code01_MinSwapStep.java
│ ├── Code02_CountFiles.java
│ └── Code03_Cola.java
│ ├── class023
│ └── Code01_FindHalfMajority.java
│ ├── class024
│ ├── Code01_RotateImage.java
│ ├── Code02_ZigZagPrintMatrix.java
│ └── Code03_PrintStar.java
│ ├── class025
│ ├── Code01_Water.java
│ ├── Code02_RandToRand.java
│ └── Code03_EqualProbabilityRandom.java
│ ├── class026
│ ├── Code01_SubArrayMaxSum.java
│ ├── Code02_SubArrayMaxSumFollowUp.java
│ └── Code03_SubMatrixMaxSum.java
│ ├── class027
│ ├── Code01_MinSwapStep.java
│ ├── Code02_CountFiles.java
│ └── Code03_Cola.java
│ ├── class028
│ ├── Code01_RotateString.java
│ ├── Code02_HowManyTypes.java
│ ├── Code03_LongestNoRepeatSubstring.java
│ └── Code04_CoverMax.java
│ ├── class029
│ ├── Code01_AppleMinBags.java
│ ├── Code02_EatGrass.java
│ └── Code03_MaxLeftMaxRight.java
│ ├── class030
│ ├── Code01_IsPalindrome.java
│ ├── Code02_MySqrt.java
│ ├── Code03_UglyNumber.java
│ └── Code04_EnterLoopNode.java
│ ├── class031
│ ├── Code01_SwapWithoutTmp.java
│ ├── Code02_AddMinus.java
│ ├── Code03_GetMax.java
│ └── Code04_MissingNumber.java
│ ├── class032
│ ├── Code01_BinaryTreeLevelOrderTraversal.java
│ ├── Code01_BinaryTreeLevelOrderTraversalII.java
│ ├── Code02_ConstructBinaryTreeFromPreorderAndInorderTraversal.java
│ ├── Code03_PaperFolding.java
│ └── Code04_DiameterOfBinaryTree.java
│ ├── class033
│ ├── Code01_FindHalfMajority.java
│ ├── Code02_RotateImage.java
│ ├── Code03_ZigZagPrintMatrix.java
│ └── Code04_PrintStar.java
│ ├── class034
│ ├── Code01_Water.java
│ ├── Code02_RandToRand.java
│ ├── Code03_EqualProbabilityRandom.java
│ ├── Code04_EvenTimesOddTimes.java
│ └── Code05_MakeNo.java
│ ├── class035
│ ├── Code01_UglyNumber.java
│ ├── Code02_MakeNo.java
│ └── Code03_CoverMax.java
│ ├── class036
│ ├── Code01_LongestNoRepeatSubstring.java
│ ├── Code02_CordCoverMaxPoint.java
│ └── Code03_ColorLeftRight.java
│ ├── class037
│ ├── Code01_MaxABSBetweenLeftAndRight.java
│ ├── Code02_JumpGameII.java
│ └── Code03_FindHalfMajority.java
│ ├── class038
│ ├── Code01_SubArrayMaxSum.java
│ ├── Code02_MaxSumFollowUp.java
│ ├── Code03_MaxSumNoAdjoin.java
│ └── Code04_MissingNumber.java
│ ├── class039
│ ├── Code01_Water.java
│ ├── Code02_RandToRand.java
│ ├── Code03_EqualProbabilityRandom.java
│ ├── Code04_EvenTimesOddTimes.java
│ └── Code05_KM.java
│ ├── class040
│ ├── Code01_PalindromeNumber.java
│ ├── Code02_MaximumProductSubarray.java
│ ├── Code03_CoverMax.java
│ └── Code04_KM.java
│ ├── class041
│ ├── Code01_LongestNoRepeatSubstring.java
│ ├── Code02_CordCoverMaxPoint.java
│ ├── Code03_MaxABSBetweenLeftAndRight.java
│ └── Code04_KM.java
│ ├── class042
│ ├── Code02_ContainAllCharExactly.java
│ └── Code03_FindHalfMajority.java
│ ├── class043
│ ├── Code01_AppleMinBags.java
│ ├── Code02_SplitNumber.java
│ ├── Code03_EatGrass.java
│ └── Code04_FindOddTimesNumber.java
│ ├── class044
│ ├── Code01_SubArrayMaxSum.java
│ ├── Code02_MaxSumFollowUp.java
│ └── Code03_MaxSumNoAdjoin.java
│ ├── class045
│ ├── Code01_MaxLeftMaxRight.java
│ ├── Code02_RotateImage.java
│ ├── Code03_ZigZagPrintMatrix.java
│ └── Code04_MissingNumber.java
│ ├── class046
│ ├── Code01_MergeKSortedLists.java
│ ├── Code02_LongestNoRepeatSubstring.java
│ └── Code03_CordCoverMaxPoint.java
│ ├── class047
│ ├── Code01_Water.java
│ ├── Code02_RandToRand.java
│ ├── Code03_EqualProbabilityRandom.java
│ └── Code04_EvenTimesOddTimes.java
│ ├── class048
│ ├── Code01_SubArrayMaxSum.java
│ ├── Code02_MaxSumFollowUp.java
│ └── Code03_MaxSumNoAdjoin.java
│ ├── class049
│ ├── Code01_AppleMinBags.java
│ ├── Code02_SplitNumber.java
│ └── Code03_EatGrass.java
│ ├── class050
│ ├── Code01_HowManyTypes.java
│ ├── Code02_CordCoverMaxPoint.java
│ ├── Code03_FindHalfMajority.java
│ ├── Code04_ZigZagPrintMatrix.java
│ └── Code05_RotateImage.java
│ ├── class051
│ ├── Code01_LongestNoRepeatSubstring.java
│ └── Code02_CoverMax.java
│ ├── class052
│ ├── Code01_EvenTimesOddTimes.java
│ ├── Code02_KM.java
│ ├── Code03_UglyNumber.java
│ └── Code04_MakeNo.java
│ ├── class053
│ ├── Code01_BestTimeToBuyAndSellStock.java
│ ├── Code02_BestTimeToBuyAndSellStockII.java
│ ├── Code03_BestTimeToBuyAndSellStockIII.java
│ ├── Code04_RabbitsInForest.java
│ ├── Code05_LIS.java
│ └── Code06_EnvelopesProblem.java
│ ├── class054
│ ├── Code01_FindHalfMajority.java
│ ├── Code02_PalindromeNumber.java
│ ├── Code03_Water.java
│ └── Code04_JumpGameII.java
│ ├── class055
│ ├── Code01_LongestNoRepeatSubstring.java
│ ├── Code02_SubArrayMaxSum.java
│ ├── Code03_MaximumProductSubarray.java
│ └── Code04_PaperFolding.java
│ ├── class056
│ ├── Code01_MissingNumber.java
│ ├── Code02_RabbitsInForest.java
│ ├── Code03_LIS.java
│ └── Code04_EnvelopesProblem.java
│ ├── class057
│ ├── Code01_MagicStone.java
│ ├── Code02_CircleCandy.java
│ ├── Code03_ComputeExpressionValue.java
│ └── Code04_Ratio01Split.java
│ ├── class058
│ ├── Code01_MinBoatEvenNumbers.java
│ ├── Code02_MaxKLenSequence.java
│ └── Code03_StoneGameIV.java
│ ├── class059
│ ├── Code01_MagicStone.java
│ ├── Code02_CircleCandy.java
│ ├── Code03_MinBoatEvenNumbers.java
│ ├── Code04_StringKth.java
│ ├── Code05_SubarraySumEqualsK.java
│ └── Code06_Ratio01Split.java
│ ├── class060
│ ├── Code01_MinSwapTimes.java
│ ├── Code02_MaxMeetingScore.java
│ ├── Code03_NextPermutation.java
│ └── Code04_SequenceKDifferentKinds.java
│ ├── class061
│ ├── Code01_HashFunction.java
│ ├── Code02_FillGapMinStep.java
│ └── Code03_Mod3Max.java
│ ├── class062
│ ├── Code01_MonotonousStack.java
│ ├── Code02_LargestRectangleInHistogram.java
│ ├── Code03_ValidSequence.java
│ └── Code04_MaxKLenSequence.java
│ ├── class063
│ ├── Code01_SumNoPositiveMinCost.java
│ └── Code02_SplitBuildingBlock.java
│ ├── class064
│ ├── Code01_LIS.java
│ ├── Code02_EnvelopesProblem.java
│ ├── Code03_MinSwapTimes.java
│ └── Code04_PoemProblem.java
│ ├── class065
│ ├── Code01_CoverMax.java
│ ├── Code02_Heaters.java
│ ├── Code03_TrappingRainWater.java
│ └── Code04_CombinationSumIV.java
│ ├── class066
│ ├── Code01_BestTimeToBuyAndSellStock.java
│ ├── Code02_BestTimeToBuyAndSellStockII.java
│ ├── Code03_BestTimeToBuyAndSellStockIII.java
│ ├── Code04_SplitArrayLargestSum.java
│ └── Code05_KokoEatingBananas.java
│ ├── class067
│ ├── Code01_IsStepSum.java
│ ├── Code02_KokoEatingBananas.java
│ ├── Code03_SplitArrayLargestSum.java
│ ├── Code04_MinimumWindowSubstring.java
│ └── Code05_SubarraysWithKDifferentIntegers.java
│ ├── class068
│ ├── Code01_MagicStone.java
│ ├── Code02_CircleCandy.java
│ └── Code03_MinBoatEvenNumbers.java
│ ├── class069
│ ├── Code01_Hash.java
│ └── Code02_BitMap.java
│ ├── class070
│ ├── Code01_FindTheCelebrity.java
│ ├── Code02_AvoidFloodInTheCity.java
│ ├── Code03_BurstBalloons.java
│ └── SuperWaterKing.java
│ ├── class071
│ ├── Code01_CoverMax.java
│ ├── Code02_Heaters.java
│ ├── Code03_TrappingRainWater.java
│ └── Code04_ExpressionCompute.java
│ ├── class072
│ ├── Code01_SplitApples.java
│ ├── Code02_SplitBuildingBlock.java
│ ├── Code03_BestMeetingPoint.java
│ └── Code04_CombinationSumIV.java
│ ├── class073
│ ├── Code01_CoverMax.java
│ ├── Code02_4KeysKeyboard.java
│ ├── Code03_MinContinuousFragment.java
│ └── Code04_MaxGap.java
│ ├── class074
│ ├── Code01_Mod3Max.java
│ ├── Code02_LetASorted.java
│ ├── Code03_AwayFromBlackHole.java
│ └── Code04_AllSame.java
│ ├── class075
│ ├── Code01_BattleshipsInABoard.java
│ ├── Code02_ShortestSubarrayWithSumAtLeastK.java
│ ├── Code03_BuyThingsAboutCollocation.java
│ └── Code04_BrickAll.java
│ ├── class076
│ ├── Code01_SetAll.java
│ ├── Code02_4KeysKeyboard.java
│ ├── Code03_BrickAll.java
│ ├── Code04_InsertDeleteGetRandom.java
│ ├── Code05_SplitApples.java
│ ├── Code06_SplitStrings.java
│ └── Code07_ShortestSubarrayWithSumAtLeastK.java
│ ├── class077
│ ├── Code01_MonotonousStack.java
│ ├── Code02_AllTimesMinToMax.java
│ ├── Code03_LargestRectangleInHistogram.java
│ └── Code04_ValidSequence.java
│ ├── class078
│ ├── Code01_SplitSameNumberWays.java
│ ├── Code02_NearBiggerNoSameNeighbour.java
│ ├── Code03_MaxTeamNumber.java
│ ├── Code04_MinimumNumberOfDaysToEatNOranges.java
│ ├── Code05_MaxKLenSequence.java
│ ├── Code06_StringCheck.java
│ └── Code07_ShortestSubarrayWithSumAtLeastK.java
│ ├── class079
│ ├── Code01_StringCheck.java
│ ├── Code02_NumberOfDivisibleByM.java
│ ├── Code03_MinWaitingTime.java
│ ├── Code04_LongestUncontinuousSet.java
│ └── Code05_CutDouFu.java
│ ├── class080
│ ├── Code01_FinancialProduct.java
│ ├── Code02_EatFish.java
│ ├── Code03_BuyGoodsHaveDiscount.java
│ └── Code04_JumpToTargets.java
│ ├── class081
│ ├── Code01_ArrangeJob.java
│ ├── Code02_MinTowNumberSumABS.java
│ └── Code03_HowManyWaysFromBottomToTop.java
│ ├── class082
│ ├── Code01_JumpToTargets.java
│ ├── Code02_ArrangeMeetingPosCancelPre.java
│ ├── Code03_MaxScoreMoveInBoard.java
│ ├── Code04_FourNumbersMinusOne.java
│ └── Code05_MaxSumOnReverseArray.java
│ ├── class083
│ ├── Code01_MaxOneNumbers.java
│ ├── Code02_PerfectPairNumber.java
│ ├── Code03_TopMinSubsquenceSum.java
│ └── Code04_TopMaxSubsquenceSum.java
│ ├── class084
│ ├── Code01_MinDepth.java
│ ├── Code02_DiameterOfBinarytree.java
│ ├── Code03_AllJobFinishTime.java
│ └── Code04_ClassicDP.java
│ ├── class085
│ ├── Code01_WhoWin21Balls.java
│ └── Code02_ShortestSubarrayWithSumAtLeastK.java
│ ├── class086
│ ├── Code01_TwoObjectMaxValue.java
│ ├── Code02_ModifyOneNumberModXWays.java
│ ├── Code03_BattleshipsInABoard.java
│ └── Code04_BrickAll.java
│ ├── class087
│ ├── Code01_RedAndWhiteSquares.java
│ ├── Code02_MaxNumberUnderLimit.java
│ └── Code03_NumberOfCannon.java
│ ├── class088
│ ├── Code01_FourNumbersMinusOne.java
│ ├── Code02_MinWaitingTime.java
│ └── Code03_UniqueSubstringsInWraparoundString.java
│ ├── class089
│ ├── Code01_MostStonesRemovedWithSameRowOrColumn.java
│ ├── Code02_ReachingPoints.java
│ └── Code03_NumberOfDifferentSubsequencesGCDs.java
│ ├── class090
│ ├── Code01_LIS.java
│ ├── Code02_MaxAnimalNumber.java
│ └── Code03_EnvelopesProblem.java
│ ├── class091
│ ├── Code01_SetAll.java
│ ├── Code02_Heaters.java
│ ├── Code03_TrappingRainWater.java
│ └── Code04_SplitApples.java
│ ├── class092
│ ├── Code01_ValidParentheses.java
│ ├── Code02_LongestParentheses.java
│ └── Code03_CompleteTreeNodeNumber.java
│ ├── class093
│ ├── Code01_FindDuplicateOnlyOne.java
│ └── Code02_SellingPiecesOfWood.java
│ ├── class094
│ ├── Code01_SortStackUsingRecursive.java
│ ├── Code02_ReversePolishNotation.java
│ └── Code03_RightView.java
│ ├── class095
│ ├── Code01_NumberOfPeopleAwareOfASecret.java
│ ├── Code02_MaxNumberUnderLimit.java
│ └── Code03_SwimInRisingWater.java
│ ├── class096
│ ├── Code01_ParenthesesDye.java
│ ├── Code02_ShortestImpossibleSequenceOfRolls.java
│ ├── Code03_SwimInRisingWater.java
│ └── Code04_LongestOneLetterManyNumberString.java
│ ├── class097
│ ├── Code01_Cakes.java
│ └── Code02_MinAddToMatch.java
│ ├── class098
│ ├── Code01_ChangeToSame.java
│ ├── Code02_MinCostMostE.java
│ └── Code03_TravelMinFuel.java
│ ├── class099
│ ├── Code01_MatchsticksToSquare.java
│ ├── Code02_CutOrPoison.java
│ └── Code03_CorporateFlightBookings.java
│ ├── class100
│ ├── Code01_EvenTimesMaxSubstring.java
│ ├── Code02_MaxLengthSameCharMChanges.java
│ └── Code03_ExaminationPaperWays.java
│ ├── class101
│ ├── Code01_SlidingWindowMaxArray.java
│ ├── Code02_WindPrevent.java
│ └── Code03_DreamCity.java
│ ├── class102
│ ├── Code01_SortGame.java
│ ├── Code02_NLengthMValueLIS3.java
│ └── Code03_LIS.java
│ ├── class103
│ ├── Code01_SoldierFindEnemy.java
│ └── Code02_RedPalindromeGoodStrings.java
│ ├── class104
│ ├── Code01_RedPalindromeGoodStrings.java
│ ├── Code02_MaxSumOnReverseArray.java
│ ├── Code03_ExaminationPaperWays.java
│ ├── Code04_TopMinSubsquenceSum.java
│ ├── Code05_MaxLengthSameCharMChanges.java
│ ├── Code06_EvenTimesMaxSubstring.java
│ └── Code07_SortGame.java
│ ├── class105
│ ├── Code01_EveryQueryUsers.java
│ └── Code02_TwoTeamsSortedMinSwap.java
│ ├── class106
│ ├── Code01_MaximumWidthRamp.java
│ └── Code02_MakeASortedMinSwaps.java
│ ├── class107
│ ├── Code01_ScoreAllMatrix.java
│ ├── Code02_HappyLimitLessGap.java
│ └── Code03_RobotAndClothes.java
│ ├── class108
│ ├── Code01_CordCoverMaxPoint.java
│ ├── Code02_LongestSumSubArrayLengthInPositiveArray.java
│ ├── Code03_LongestSumSubArrayLength.java
│ ├── Code04_SlidingWindowMaxArray.java
│ ├── Code05_WindPrevent.java
│ ├── Code06_RemoveMostKContinuousSameLongest.java
│ ├── Code07_RangesHasDominateNumber.java
│ ├── Code08_LastStoneWeightII.java
│ └── Code09_ScoreAllMatrix.java
│ ├── class109
│ ├── Code01_ThreeEqualParts.java
│ ├── Code02_LongestSumSubArrayLength.java
│ ├── Code03_EvenTimesMaxSubstring.java
│ └── Code04_RemoveMostKContinuousSameLongest.java
│ ├── class110
│ ├── Code01_MoveCityGetMoney.java
│ └── Code02_EntryRoomGetMoney.java
│ ├── class111
│ ├── Code01_ComplementaryPairsInStringArray.java
│ └── Code02_CouplesHoldingHands.java
│ ├── class112
│ ├── Code01_SortArrayByMovingItemsToEmptySpace.java
│ └── Code02_ZigZagConversion.java
│ ├── class113
│ ├── Code01_TravelMinFuel.java
│ ├── Code02_MakingALargeIsland.java
│ └── Code03_MinimumCostToHireKWorkers.java
│ ├── class114
│ ├── Code01_KthMissingPositiveNumber.java
│ ├── Code02_ZigZagConversion.java
│ ├── Code03_MaximumWidthRamp.java
│ ├── Code04_ThreeEqualParts.java
│ ├── Code05_CouplesHoldingHands.java
│ ├── Code06_AbsToArrayFinalLength.java
│ ├── Code07_HeightAfterSubtreeRemoval.java
│ ├── Code08_AsFarFromLandAsPossible.java
│ └── Code09_OrderlyQueue.java
│ ├── class115
│ ├── Code01_StampingTheGrid.java
│ ├── Code02_SumOfSubSequenceWidths.java
│ └── Code03_SumOfDistancesInTree.java
│ ├── class116
│ ├── Code01_MinimumNumberOfDaysToEatNOranges.java
│ ├── Code02_HowManyObtuseAngles.java
│ └── Code03_CherryPickup.java
│ └── class117
│ ├── Code01_CandyProblem.java
│ ├── Code02_ExpressionCompute.java
│ ├── Code03_SmallestRangeCoveringElementsfromKLists.java
│ ├── Code04_MinWindowLength.java
│ ├── Code05_RangesHasDominateNumber.java
│ ├── Code06_RegularExpressionMatch.java
│ ├── Code07_BoatsToSavePeople.java
│ ├── Code08_MaximumProductSubarray.java
│ └── Code09_RotateImage.java
├── trainingcamp源码
├── trainingcamp001-master.zip
├── trainingcamp001-master
│ ├── src
│ │ ├── class01
│ │ │ ├── Code01_SlidingWindowMaxArray.java
│ │ │ ├── Code02_AllLessNumSubArray.java
│ │ │ ├── Code03_MonotonousStack.java
│ │ │ ├── Code04_AllTimesMinToMax.java
│ │ │ ├── Code05_SumOfSubarrayMinimums.java
│ │ │ └── Test.java
│ │ ├── class02
│ │ │ ├── Code01_FibonacciProblem.java
│ │ │ └── Code02_ZeroLeftOneStringNumber.java
│ │ ├── class03
│ │ │ ├── Code01_FindMinKth.java
│ │ │ └── Code02_ReservoirSampling.java
│ │ ├── class04
│ │ │ ├── Code01_KMP.java
│ │ │ ├── Code02_TreeEqual.java
│ │ │ └── Code03_IsRotation.java
│ │ ├── class05
│ │ │ ├── Code01_Manacher.java
│ │ │ └── Code02_AddShortestEnd.java
│ │ ├── class06
│ │ │ ├── Code01_MorrisTraversal.java
│ │ │ └── Code05_MinHeight.java
│ │ ├── class07
│ │ │ ├── Code01_CoverMax.java
│ │ │ ├── Code01_SegmentTree.java
│ │ │ ├── Code02_FallingSquares.java
│ │ │ └── Code04_CoverMax.java
│ │ └── class08
│ │ │ ├── Code01_AC1.java
│ │ │ ├── Code01_AC2.java
│ │ │ └── Code01_RandToRand.java
│ └── trainingcamp001-master.iml
├── trainingcamp002-master.zip
├── trainingcamp002-master
│ ├── src
│ │ ├── class01
│ │ │ ├── Code01_AppleMinBags.java
│ │ │ ├── Code02_EatGrass.java
│ │ │ ├── Code03_MSumToN.java
│ │ │ ├── Code04_RotateMatrix.java
│ │ │ ├── Code05_PrintMatrixSpiralOrder.java
│ │ │ └── Code06_ZigZagPrintMatrix.java
│ │ ├── class02
│ │ │ ├── Code01_LongestSumSubArrayLengthInPositiveArray.java
│ │ │ ├── Code02_LongestSumSubArrayLength.java
│ │ │ └── Code03_LongestLessSumSubArrayLength.java
│ │ ├── class03
│ │ │ ├── Code01_RandomPool.java
│ │ │ └── Code02_Islands.java
│ │ ├── class05
│ │ │ ├── Code01_AVLTreeMap.java
│ │ │ ├── Code01_SizeBalancedTreeMap.java
│ │ │ ├── Code02_SizeBalancedTreeMap.java
│ │ │ ├── Code03_SkipListMap.java
│ │ │ └── Compare.java
│ │ ├── class06
│ │ │ ├── AbstractBinarySearchTree.java
│ │ │ ├── AbstractSelfBalancingBinarySearchTree.java
│ │ │ ├── BinarySearchTree.java
│ │ │ └── RedBlackTree.java
│ │ ├── class07
│ │ │ ├── Code01_CountofRangeSum.java
│ │ │ └── Code02_SlidingWindowMedian.java
│ │ └── class08
│ │ │ ├── Code01_AC.java
│ │ │ ├── Code02_DifferentBTNum.java
│ │ │ ├── Code03_10Ways.java
│ │ │ └── Code04_UniqueBST.java
│ └── trainingcamp002-master.iml
├── trainingcamp003-master.zip
├── trainingcamp003-master
│ ├── src
│ │ ├── class01
│ │ │ ├── Code01_CordCoverMaxPoint.java
│ │ │ ├── Code02_NeedParentheses.java
│ │ │ ├── Code03_ParenthesesDeep.java
│ │ │ ├── Code04_ColorLeftRight.java
│ │ │ ├── Code05_MaxOneBorderSize.java
│ │ │ ├── Code06_MakeNo.java
│ │ │ └── Code07_MaxSumInTree.java
│ │ ├── class02
│ │ │ ├── Code01_FindNumInSortedMatrix.java
│ │ │ ├── Code02_PackingMachine.java
│ │ │ ├── Code03_MaxABSBetweenLeftAndRight.java
│ │ │ ├── Code04_TrappingRainWater.java
│ │ │ ├── Code05_TrappingRainWaterII.java
│ │ │ ├── Code06_PrintUniquePairAndTriad.java
│ │ │ └── Code07_KthMinPair.java
│ │ ├── class03
│ │ │ ├── Code01_ChooseWork.java
│ │ │ ├── Code02_SnacksWays.java
│ │ │ ├── Code03_MinPathSum.java
│ │ │ ├── Code04_LCSubsequence.java
│ │ │ ├── Code05_LCSubstring.java
│ │ │ ├── Code06_TopKTimes.java
│ │ │ ├── Code07_TopKTimesRealTime.java
│ │ │ ├── Main.java
│ │ │ └── TopK.java
│ │ ├── class04
│ │ │ ├── Code01_GetFolderTree.java
│ │ │ ├── Code02_BSTtoDoubleLinkedList.java
│ │ │ ├── Code03_PreAndInArrayToPosArray.java
│ │ │ ├── Code04_LIS.java
│ │ │ ├── Code05_EnvelopesProblem.java
│ │ │ ├── Code06_SubArrayMaxSum.java
│ │ │ └── Code07_SubMatrixMaxSum.java
│ │ ├── class05
│ │ │ ├── Code01_DeleteMinCost.java
│ │ │ ├── Code02_EditCost.java
│ │ │ ├── Code03_CompleteTreeNodeNumber.java
│ │ │ ├── Code04_LeastRecentlyUsedCache.java
│ │ │ ├── Code05_WordMinPaths.java
│ │ │ └── Code06_MaxRevenue.java
│ │ ├── class06
│ │ │ ├── Code01_MaxEOR.java
│ │ │ ├── Code02_ExpressionNumber.java
│ │ │ ├── Code02_MostEOR.java
│ │ │ ├── Code03_JumpGame.java
│ │ │ ├── Code04_TopKSumCrossTwoArrays.java
│ │ │ ├── Code05_Split4Parts.java
│ │ │ ├── Code06_StringCross.java
│ │ │ ├── Code07_PMinParts.java
│ │ │ └── Main.java
│ │ ├── class07
│ │ │ ├── Code01_MinLengthForSort.java
│ │ │ ├── Code02_SmallestUnFormedSum.java
│ │ │ ├── Code03_MinPatches.java
│ │ │ ├── Code04_LargestComponentSizebyCommonFactor.java
│ │ │ ├── Code05_RemoveDuplicateLettersLessLexi.java
│ │ │ ├── Code06_LongestNoRepeatSubstring.java
│ │ │ └── Code07_MaxPointsOneLine.java
│ │ └── class08
│ │ │ ├── Code01_ReceiveAndPrintOrderLine.java
│ │ │ ├── Code02_MoneyWays.java
│ │ │ ├── Code03_OneNumber.java
│ │ │ ├── Code04_MoneyProblem.java
│ │ │ ├── Code05_LongestIntegratedLength.java
│ │ │ └── Code06_PalindromeMinAdd.java
│ └── trainingcamp003-master.iml
├── trainingcamp004-master.zip
├── trainingcamp004-master
│ ├── src
│ │ ├── class01
│ │ │ ├── Code01_LongestIncreasingPath.java
│ │ │ ├── Code02_MaxSubArraySumLessOrEqualK.java
│ │ │ ├── Code03_MaxSumofRectangleNoLargerThanK.java
│ │ │ ├── Code04_WordSearch.java
│ │ │ └── Code05_ExpressionAddOperators.java
│ │ ├── class02
│ │ │ ├── Code01_BestTimetoBuyandSellStock1.java
│ │ │ ├── Code02_BestTimetoBuyandSellStock2.java
│ │ │ ├── Code03_BestTimetoBuyandSellStockFollow.java
│ │ │ ├── Code04_DistinctSubsequences.java
│ │ │ ├── Code05_DungeonGame.java
│ │ │ └── Code06_CherryPickup.java
│ │ ├── class03
│ │ │ ├── Code01_MaxGap.java
│ │ │ ├── Code02_WorldBreak.java
│ │ │ ├── Code03_LongestSumEqualK.java
│ │ │ ├── Code04_KTimesOneTime.java
│ │ │ └── Code05_FindKMajority.java
│ │ ├── class04
│ │ │ ├── Code01_BuildingOutline.java
│ │ │ ├── Code02_FindKthMinNumber.java
│ │ │ ├── Code03_Nim.java
│ │ │ ├── Code04_JosephusProblem.java
│ │ │ ├── Code05_MinBoat.java
│ │ │ ├── Code06_Coffee.java
│ │ │ └── Problem_0218_TheSkylineProblem.java
│ │ ├── class05
│ │ │ ├── Code01_PalindromeSubsequence.java
│ │ │ ├── Code02_SnakeGame.java
│ │ │ ├── Code03_ExpressionCompute.java
│ │ │ └── Code04_PalindromeWays.java
│ │ ├── class06
│ │ │ ├── Code01_SplitNumer1.java
│ │ │ ├── Code01_SplitNumer2.java
│ │ │ ├── Code02_KInversePairs1.java
│ │ │ ├── Code02_KInversePairs2.java
│ │ │ ├── Code03_BiggestBSTTopologyInTree.java
│ │ │ └── Code04_ShuffleProblem.java
│ │ ├── class07
│ │ │ ├── Code01_SDEandPM.java
│ │ │ ├── Code02_RecoverBST.java
│ │ │ ├── Code03_VisibleMountains.java
│ │ │ ├── Code04_SubsquenceMaxModM.java
│ │ │ └── Main.java
│ │ └── class08
│ │ │ ├── Code01_RegularExpressionMatch.java
│ │ │ ├── Code02_FreedomTrail.java
│ │ │ ├── Code03_BurstBalloons.java
│ │ │ ├── Code04_HanoiProblem.java
│ │ │ └── Code05_MinimumCostToMergeStones.java
│ └── trainingcamp004-master.iml
├── trainingcamp005-master.zip
└── trainingcamp005-master
│ ├── src
│ ├── class01
│ │ ├── Problem01_ScrambleString.java
│ │ ├── Problem02_MinWindowLength.java
│ │ ├── Problem03_LFU.java
│ │ └── Problem04_GasStations.java
│ ├── class02
│ │ ├── Code01_PathsToNums.java
│ │ ├── Code02_CandyProblem.java
│ │ ├── Code03_MinCameraCover.java
│ │ └── Code04_MaximumSumof3NonOverlappingSubarrays.java
│ ├── class03
│ │ ├── Code01_NiuNiuSplitField.java
│ │ ├── Code02_BricksFallingWhenHit1.java
│ │ ├── Code02_BricksFallingWhenHit2.java
│ │ ├── Code03_TallestBillboard.java
│ │ ├── Code04_DistinctSubseq.java
│ │ └── Main.java
│ ├── class04
│ │ ├── Code01_SplitArrayLargestSum.java
│ │ ├── Code02_ThrowChessPiecesProblem.java
│ │ ├── Code03_PostOfficeProblem.java
│ │ ├── Code04_MergeRecord.java
│ │ └── Code05_FactorialProblem.java
│ ├── class05
│ │ ├── Code01_PalindromePairs.java
│ │ ├── Code02_LongestConsecutive.java
│ │ ├── Code03_TarjanAndDisjointSetsForLCA.java
│ │ └── Code04_MaximalRectangle.java
│ ├── class06
│ │ ├── Code01_RemoveBoxes.java
│ │ ├── Code02_StrangePrinter.java
│ │ ├── Code03_SmallestRangeCoveringElementsfromKLists.java
│ │ └── Code04_RestoreWays.java
│ ├── class07
│ │ ├── Code01_TSP.java
│ │ └── Code02_PavingTile.java
│ └── class08
│ │ ├── Code01_CreateMaximumNumber.java
│ │ ├── Code02_LastSubstringInLexicographicalOrder.java
│ │ ├── Code03_InsertS2MakeMostAlphabeticalOrder.java
│ │ ├── DC3.java
│ │ └── DC3_Algorithm.pdf
│ └── trainingcamp005-master.iml
├── 全部算法课讲解知识点提纲、题目汇总、PPT合集、学前必读、学习规划
└── class-notes
│ ├── 学前必读
│ ├── 算法和数据结构知识梳理.xmind
│ └── 课堂内容汇总
│ ├── 大厂算法和数据结构刷题班
│ ├── 每周有营养的大厂算法面试题(正在直播)
│ ├── 算法和数据结构体系学习班
│ └── 算法和数据结构新手班
├── 大厂算法和数据结构刷题班
└── coding-for-great-offer
│ └── src
│ ├── class01
│ ├── Code01_CordCoverMaxPoint.java
│ ├── Code02_CountFiles.java
│ ├── Code03_Near2Power.java
│ ├── Code04_MinSwapStep.java
│ ├── Code05_LongestIncreasingPath.java
│ ├── Code06_AOE.java
│ └── Code07_TargetSum.java
│ ├── class02
│ ├── Code01_ChooseWork.java
│ ├── Code02_Cola.java
│ ├── Code03_ReceiveAndPrintOrderLine.java
│ ├── Code04_Drive.java
│ ├── Code05_SetAll.java
│ └── Code06_MinLengthForSort.java
│ ├── class03
│ ├── Code01_LongestSubstringWithoutRepeatingCharacters.java
│ ├── Code02_HowManyTypes.java
│ ├── Code03_Largest1BorderedSquare.java
│ ├── Code04_MaxPairNumber.java
│ ├── Code05_BoatsToSavePeople.java
│ ├── Code06_ClosestSubsequenceSum.java
│ ├── Code07_FreedomTrail.java
│ └── Code08_DistanceKNodes.java
│ ├── class04
│ ├── Code01_QueryHobby.java
│ ├── Code02_SubArrayMaxSum.java
│ ├── Code03_SubMatrixMaxSum.java
│ ├── Code04_SubArrayMaxSumFollowUp.java
│ ├── Code05_CandyProblem.java
│ ├── Code06_MakeNo.java
│ ├── Code07_InterleavingString.java
│ └── Code08_TheSkylineProblem.java
│ ├── class05
│ ├── Code01_ConstructBinarySearchTreeFromPreorderTraversal.java
│ ├── Code02_LeftRightSameTreeNumber.java
│ ├── Code03_EditCost.java
│ ├── Code04_DeleteMinCost.java
│ └── Hash.java
│ ├── class06
│ ├── Code01_MaxXOR.java
│ ├── Code02_MaximumXorOfTwoNumbersInAnArray.java
│ ├── Code03_MaximumXorWithAnElementFromArray.java
│ ├── Code04_MostXorZero.java
│ └── Code05_Nim.java
│ ├── class07
│ ├── Code01_MaxAndValue.java
│ ├── Code02_MinCameraCover.java
│ ├── Code03_MaxGap.java
│ ├── Code04_Power2Diffs.java
│ ├── Code05_WorldBreak.java
│ └── Code06_SplitStringMaxValue.java
│ ├── class08
│ ├── Code01_ExpressionCompute.java
│ ├── Code02_ContainerWithMostWater.java
│ ├── Code03_FindWordInMatrix.java
│ └── Code04_SnakeGame.java
│ ├── class09
│ ├── Code01_LightProblem.java
│ ├── Code02_RemoveInvalidParentheses.java
│ ├── Code03_LIS.java
│ ├── Code04_EnvelopesProblem.java
│ └── Code05_IsStepSum.java
│ ├── class10
│ ├── Code01_JumpGame.java
│ ├── Code02_TopK.java
│ ├── Code03_KInversePairs.java
│ ├── Code04_BSTtoDoubleLinkedList.java
│ └── Code05_BooleanEvaluation.java
│ ├── class11
│ ├── Code01_MinimumInsertionStepsToMakeAStringPalindrome.java
│ └── Code02_PalindromePartitioningII.java
│ ├── class12
│ ├── Code01_ContainAllCharExactly.java
│ ├── Code03_FindKthMinNumber.java
│ ├── Code03_LongestConsecutive.java
│ └── Code04_RegularExpressionMatch.java
│ ├── class13
│ ├── Code01_NCardsABWin.java
│ ├── Code02_SuperWashingMachines.java
│ ├── Code03_ScrambleString.java
│ └── Code04_BricksFallingWhenHit.java
│ ├── class14
│ ├── Code01_Parentheses.java
│ ├── Code02_MaxSubArraySumLessOrEqualK.java
│ ├── Code03_BiggestBSTTopologyInTree.java
│ ├── Code04_CompleteTreeNodeNumber.java
│ ├── Code05_RecoverBinarySearchTree.java
│ └── Code06_MissingNumber.java
│ ├── class15
│ ├── Code01_BestTimeToBuyAndSellStock.java
│ ├── Code02_BestTimeToBuyAndSellStockII.java
│ ├── Code03_BestTimeToBuyAndSellStockIII.java
│ ├── Code04_BestTimeToBuyAndSellStockIV.java
│ ├── Code05_BestTimeToBuyAndSellStockWithCooldown.java
│ └── Code06_BestTimeToBuyAndSellStockWithTransactionFee.java
│ ├── class16
│ ├── Code01_IsSum.java
│ ├── Code02_SmallestUnFormedSum.java
│ ├── Code03_MinPatches.java
│ ├── Code04_MergeRecord.java
│ └── Code05_JosephusProblem.java
│ ├── class17
│ ├── Code01_FindNumInSortedMatrix.java
│ ├── Code02_KthSmallestElementInSortedMatrix.java
│ ├── Code03_PalindromePairs.java
│ ├── Code04_DistinctSubseq.java
│ └── Code05_DistinctSubseqValue.java
│ ├── class18
│ ├── Code01_HanoiProblem.java
│ ├── Code02_ShortestBridge.java
│ ├── Code03_CherryPickup.java
│ └── Code04_TopKSumCrossTwoArrays.java
│ ├── class19
│ ├── Code01_LRUCache.java
│ ├── Code02_LFUCache.java
│ ├── Code03_OneNumber.java
│ ├── Code04_SmallestRangeCoveringElementsfromKLists.java
│ └── Code05_CardsProblem.java
│ ├── class20
│ ├── Code01_PreAndInArrayToPosArray.java
│ ├── Code02_LargestComponentSizebyCommonFactor.java
│ ├── Code03_ShuffleProblem.java
│ └── Code04_PalindromeWays.java
│ ├── class21
│ └── TreeChainPartition.java
│ ├── class22
│ ├── Code01_MaximumSumof3NonOverlappingSubarrays.java
│ ├── Code02_TrappingRainWater.java
│ ├── Code03_TrappingRainWaterII.java
│ ├── Code04_VisibleMountains.java
│ └── Code05_TallestBillboard.java
│ ├── class23
│ ├── Code01_LCATarjanAndTreeChainPartition.java
│ ├── Code02_MaxABSBetweenLeftAndRight.java
│ ├── Code03_LongestIntegratedLength.java
│ ├── Code04_FindKMajority.java
│ └── Code05_MinimumCostToMergeStones.java
│ ├── class24
│ ├── Code01_Split4Parts.java
│ ├── Code02_KthMinPair.java
│ ├── Code03_NotContains4.java
│ ├── Code04_Painting.java
│ ├── Code05_MinWindowLength.java
│ └── Code06_RemoveDuplicateLettersLessLexi.java
│ ├── class25
│ ├── Code01_IPToCIDR.java
│ ├── Code02_3Sum.java
│ ├── Code03_MaxPointsOnALine.java
│ └── Code04_GasStation.java
│ ├── class26
│ ├── Code01_MinRange.java
│ ├── Code02_WordSearchII.java
│ ├── Code03_ExpressionAddOperators.java
│ └── Code04_WordLadderII.java
│ ├── class27
│ ├── Code01_PickBands.java
│ ├── Code02_MinPeople.java
│ ├── Problem_0001_TwoSum.java
│ ├── Problem_0007_ReverseInteger.java
│ └── 说明
│ ├── class28
│ ├── Problem_0008_StringToInteger.java
│ ├── Problem_0012_IntegerToRoman.java
│ ├── Problem_0013_RomanToInteger.java
│ ├── Problem_0014_LongestCommonPrefix.java
│ ├── Problem_0017_LetterCombinationsOfAPhoneNumber.java
│ ├── Problem_0019_RemoveNthNodeFromEndofList.java
│ ├── Problem_0020_ValidParentheses.java
│ ├── Problem_0022_GenerateParentheses.java
│ ├── Problem_0026_RemoveDuplicatesFromSortedArray.java
│ ├── Problem_0034_FindFirstAndLastPositionOfElementInSortedArray.java
│ ├── Problem_0036_ValidSudoku.java
│ ├── Problem_0037_SudokuSolver.java
│ ├── Problem_0038_CountAndSay.java
│ ├── Problem_0049_GroupAnagrams.java
│ └── 说明
│ ├── class29
│ ├── Problem_0033_SearchInRotatedSortedArray.java
│ ├── Problem_0050_PowXN.java
│ ├── Problem_0056_MergeIntervals.java
│ ├── Problem_0062_UniquePaths.java
│ ├── Problem_0066_PlusOne.java
│ ├── Problem_0069_SqrtX.java
│ ├── Problem_0073_SetMatrixZeroes.java
│ └── 说明
│ ├── class30
│ ├── Problem_0079_WordSearch.java
│ ├── Problem_0088_MergeSortedArray.java
│ ├── Problem_0091_DecodeWays.java
│ ├── Problem_0098_ValidateBinarySearchTree.java
│ ├── Problem_0101_SymmetricTree.java
│ ├── Problem_0103_BinaryTreeZigzagLevelOrderTraversal.java
│ ├── Problem_0108_ConvertSortedArrayToBinarySearchTree.java
│ ├── Problem_0116_PopulatingNextRightPointersInEachNode.java
│ ├── Problem_0118_PascalTriangle.java
│ ├── Problem_0119_PascalTriangleII.java
│ ├── Problem_0124_BinaryTreeMaximumPathSum.java
│ ├── Problem_0639_DecodeWaysII.java
│ └── 说明
│ ├── class31
│ ├── Problem_0125_ValidPalindrome.java
│ ├── Problem_0127_WordLadder.java
│ ├── Problem_0130_SurroundedRegions.java
│ ├── Problem_0139_WordBreak.java
│ ├── Problem_0140_WordBreakII.java
│ ├── Problem_0148_SortList.java
│ ├── Problem_0150_EvaluateReversePolishNotation.java
│ └── 说明
│ ├── class32
│ ├── ExaminationPaperWays.java
│ ├── Problem_0152_MaximumProductSubarray.java
│ ├── Problem_0163_MissingRanges.java
│ ├── Problem_0166_FractionToRecurringDecimal.java
│ ├── Problem_0171_ExcelSheetColumnNumber.java
│ ├── Problem_0172_FactorialTrailingZeroes.java
│ ├── Problem_0189_RotateArray.java
│ ├── Problem_0190_ReverseBits.java
│ ├── Problem_0191_NumberOf1Bits.java
│ ├── Problem_0202_HappyNumber.java
│ ├── Problem_0204_CountPrimes.java
│ └── 说明
│ ├── class33
│ ├── Problem_0207_CourseSchedule.java
│ ├── Problem_0210_CourseScheduleII.java
│ ├── Problem_0213_HouseRobberII.java
│ ├── Problem_0237_DeleteNodeInLinkedList.java
│ ├── Problem_0238_ProductOfArrayExceptSelf.java
│ ├── Problem_0242_ValidAnagram.java
│ ├── Problem_0251_Flatten2DVector.java
│ ├── Problem_0269_AlienDictionary.java
│ ├── Problem_0277_FindTheCelebrity.java
│ ├── Problem_0279_PerfectSquares.java
│ ├── Problem_0283_MoveZeroes.java
│ └── 说明
│ ├── class34
│ ├── Problem_0287_FindTheDuplicateNumber.java
│ ├── Problem_0289_GameOfLife.java
│ ├── Problem_0295_FindMedianFromDataStream.java
│ ├── Problem_0315_CountOfSmallerNumbersAfterSelf.java
│ ├── Problem_0324_WiggleSortII.java
│ ├── Problem_0326_PowerOfThree.java
│ ├── Problem_0328_OddEvenLinkedList.java
│ ├── Problem_0340_LongestSubstringWithAtMostKDistinctCharacters.java
│ ├── Problem_0341_FlattenNestedListIterator.java
│ ├── Problem_0348_DesignTicTacToe.java
│ ├── Problem_0380_InsertDeleteGetRandom.java
│ ├── Problem_0384_ShuffleAnArray.java
│ └── 说明
│ ├── class35
│ ├── Code01_StringKth.java
│ ├── Code02_MagicStone.java
│ ├── Code03_WatchMovieMaxTime.java
│ ├── Code04_WalkToEnd.java
│ ├── Code05_CircleCandy.java
│ ├── Problem_0347_TopKFrequentElements.java
│ ├── Problem_0395_LongestSubstringWithAtLeastKRepeatingCharacters.java
│ ├── Problem_0412_FizzBuzz.java
│ ├── Problem_0454_4SumII.java
│ ├── Problem_0673_NumberOfLongestIncreasingSubsequence.java
│ ├── Problem_0687_LongestUnivaluePath.java
│ └── 说明
│ ├── class36
│ ├── Code01_ReverseInvertString.java
│ ├── Code02_Ratio01Split.java
│ ├── Code03_MatchCount.java
│ ├── Code04_ComputeExpressionValue.java
│ ├── Code05_Query3Problems.java
│ ├── Code06_NodeWeight.java
│ ├── Code07_PickAddMax.java
│ ├── Code08_MinBoatEvenNumbers.java
│ ├── Code09_MaxKLenSequence.java
│ ├── Code10_StoneGameIV.java
│ ├── Code11_BusRoutes.java
│ └── 说明
│ ├── class37
│ ├── Code01_ArrangeProject.java
│ ├── Code02_GameForEveryStepWin.java
│ ├── Problem_0114_FlattenBinaryTreeToLinkedList.java
│ ├── Problem_0221_MaximalSquare.java
│ ├── Problem_0226_InvertBinaryTree.java
│ ├── Problem_0337_HouseRobberIII.java
│ ├── Problem_0394_DecodeString.java
│ ├── Problem_0406_QueueReconstructionByHeight.java
│ ├── Problem_0437_PathSumIII.java
│ └── 说明
│ ├── class38
│ ├── Code01_FillGapMinStep.java
│ ├── Code02_GreatWall.java
│ ├── Problem_0438_FindAllAnagramsInAString.java
│ ├── Problem_0448_FindAllNumbersDisappearedInAnArray.java
│ ├── Problem_0617_MergeTwoBinaryTrees.java
│ ├── Problem_0621_TaskScheduler.java
│ ├── Problem_0647_PalindromicSubstrings.java
│ ├── Problem_0739_DailyTemperatures.java
│ ├── Problem_0763_PartitionLabels.java
│ └── 说明
│ ├── class39
│ ├── Code01_01AddValue.java
│ ├── Code02_ValidSequence.java
│ ├── Code03_SequenceKDifferentKinds.java
│ ├── Code04_JumpGameOnMatrix.java
│ └── Code05_0123Disappear.java
│ ├── class40
│ ├── Code01_SplitTo01.java
│ ├── Code02_Mod3Max.java
│ ├── Code03_MaxMeetingScore.java
│ ├── Code04_LetASorted.java
│ └── Code05_AllSame.java
│ ├── class41
│ ├── Code01_MinSwapTimes.java
│ ├── Code02_PoemProblem.java
│ ├── Code03_MagicGoToAim.java
│ └── Problem_0031_NextPermutation.java
│ ├── class42
│ ├── Problem_0265_PaintHouseII.java
│ ├── Problem_0272_ClosestBinarySearchTreeValueII.java
│ ├── Problem_0273_IntegerToEnglishWords.java
│ ├── Problem_0296_BestMeetingPoint.java
│ └── Problem_0335_SelfCrossing.java
│ ├── class43
│ ├── Code01_SumNoPositiveMinCost.java
│ └── Code02_MinCostToYeahArray.java
│ ├── class44
│ ├── Problem_0248_StrobogrammaticNumberIII.java
│ ├── Problem_0317_ShortestDistanceFromAllBuildings.java
│ └── Problem_0992_SubarraysWithKDifferentIntegers.java
│ ├── class45
│ ├── Code01_SplitBuildingBlock.java
│ ├── Problem_0291_WordPatternII.java
│ ├── Problem_0403_FrogJump.java
│ └── Problem_2035_PartitionArrayIntoTwoArraysToMinimizeSumDifference.java
│ ├── class46
│ ├── Problem_0363_MaxSumOfRectangleNoLargerThanK.java
│ ├── Problem_0391_PerfectRectangle.java
│ ├── Problem_0411_MinimumUniqueWordAbbreviation.java
│ └── Problem_0425_WordSquares.java
│ ├── class47
│ ├── Code01_DynamicSegmentTree.java
│ ├── Code02_DynamicSegmentTree.java
│ ├── Problem_0315_CountOfSmallerNumbersAfterSelf.java
│ ├── Problem_0358_RearrangeStringKDistanceApart.java
│ ├── Problem_0428_SerializeAndDeserializeNaryTree.java
│ ├── Problem_0465_OptimalAccountBalancing.java
│ └── Problem_0475_Heaters.java
│ ├── class48
│ ├── Code01_MinKthPairMinusABS.java
│ ├── Problem_0472_ConcatenatedWords.java
│ ├── Problem_0483_SmallestGoodBase.java
│ └── Problem_0499_TheMazeIII.java
│ ├── class49
│ ├── Problem_0377_CombinationSumIV.java
│ ├── Problem_0440_KthSmallestInLexicographicalOrder.java
│ ├── Problem_0446_ArithmeticSlicesIISubsequence.java
│ ├── Problem_0489_RobotRoomCleaner.java
│ ├── Problem_0527_WordAbbreviation.java
│ ├── Problem_0548_SplitArrayEithEqualSum.java
│ └── Problem_0564_FindTheClosestPalindrome.java
│ ├── class50
│ ├── Problem_0568_MaximumVacationDays.java
│ ├── Problem_0587_ErectTheFence.java
│ ├── Problem_0588_DesignInMemoryFileSystem.java
│ └── Problem_0600_NonnegativeIntegersWithoutConsecutiveOnes.java
│ ├── class51
│ ├── LCP_0003_Robot.java
│ ├── Problem_0630_CourseScheduleIII.java
│ ├── Problem_0642_DesignSearchAutocompleteSystem.java
│ ├── Problem_0875_KokoEatingBananas.java
│ └── Problem_1035_UncrossedLines.java
│ └── class52
│ ├── Problem_0656_CoinPath.java
│ ├── Problem_0683_KEmptySlots.java
│ └── Problem_1488_AvoidFloodInTheCity.java
├── 左程云算法 源码
├── Algorithm-master.zip
├── Algorithm-master
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── .settings
│ │ └── org.eclipse.jdt.core.prefs
│ ├── Algorithm-master.iml
│ └── src
│ │ ├── Test
│ │ ├── CountSortTest.java
│ │ ├── DualPivotQuickSort.java
│ │ └── RadixSortTest.java
│ │ └── com
│ │ └── mashibing
│ │ ├── BinarySearch.java
│ │ ├── BubbleSort.java
│ │ ├── CountSort.java
│ │ ├── DataChecker.java
│ │ ├── InsertionSort.java
│ │ ├── MergeSort.java
│ │ ├── QuickSort.java
│ │ ├── RadixSort.java
│ │ ├── SelectionSort.java
│ │ ├── ShellSort.java
│ │ ├── TTT.java
│ │ ├── T_0001_BigO.java
│ │ ├── linkedlist
│ │ ├── BiDirLL.java
│ │ ├── BiDirLoopLL.java
│ │ ├── Node.java
│ │ ├── OneDirLoopLL.java
│ │ └── SimpleLL.java
│ │ └── search
│ │ └── BinarySearch.java
├── algorithmbasic2020-master.zip
└── algorithmbasic2020-master
│ ├── algorithmbasic2020-master.iml
│ └── src
│ ├── class01
│ ├── Code01_SelectionSort.java
│ ├── Code02_BubbleSort.java
│ ├── Code03_InsertionSort.java
│ ├── Code04_BSExist.java
│ ├── Code05_BSNearLeft.java
│ ├── Code05_BSNearRight.java
│ ├── Code06_BSAwesome.java
│ ├── Code07_EvenTimesOddTimes.java
│ └── Test.java
│ ├── class02
│ ├── Code01_ReverseList.java
│ ├── Code02_DeleteGivenValue.java
│ ├── Code03_DoubleEndsQueueToStackAndQueue.java
│ ├── Code04_RingArray.java
│ ├── Code05_GetMinStack.java
│ ├── Code06_TwoStacksImplementQueue.java
│ ├── Code07_TwoQueueImplementStack.java
│ ├── Code08_GetMax.java
│ └── HashMapAndSortedMap.java
│ ├── class03
│ ├── Code01_MergeSort.java
│ ├── Code02_SmallSum.java
│ └── Code03_PartitionAndQuickSort.java
│ ├── class04
│ ├── Code01_Comparator.java
│ ├── Code02_Heap01.java
│ ├── Code03_Heap02.java
│ ├── Code04_HeapSort.java
│ ├── Code05_SortArrayDistanceLessK.java
│ └── Test.java
│ ├── class05
│ ├── Code01_TrieTree.java
│ ├── Code02_TrieTree.java
│ ├── Code03_CountSort.java
│ └── Code04_RadixSort.java
│ ├── class06
│ ├── Code01_LinkedListMid.java
│ ├── Code02_IsPalindromeList.java
│ ├── Code03_SmallerEqualBigger.java
│ ├── Code04_CopyListWithRandom.java
│ ├── Code05_FindFirstIntersectNode.java
│ └── Test.java
│ ├── class07
│ ├── Code01_RecursiveTraversalBT.java
│ ├── Code02_UnRecursiveTraversalBT.java
│ ├── Code03_LevelTraversalBT.java
│ ├── Code04_SerializeAndReconstructTree.java
│ ├── Code05_PrintBinaryTree.java
│ ├── Code06_TreeMaxWidth.java
│ ├── Code07_SuccessorNode.java
│ └── Code08_PaperFolding.java
│ ├── class08
│ ├── Code01_IsBalanced.java
│ ├── Code02_IsFull.java
│ ├── Code03_IsBST.java
│ ├── Code04_MaxSubBSTSize.java
│ ├── Code05_MaxSubBSTHead.java
│ ├── Code06_IsCBT.java
│ ├── Code07_lowestAncestor.java
│ ├── Code08_MaxDistance.java
│ └── Code09_MaxHappy.java
│ ├── class09
│ ├── Code01_LowestLexicography.java
│ ├── Code02_Light.java
│ ├── Code03_LessMoneySplitGold.java
│ ├── Code04_BestArrange.java
│ └── Code05_IPO.java
│ ├── class10
│ ├── Code01_UnionFind.java
│ ├── Code02_BFS.java
│ ├── Code02_DFS.java
│ ├── Code03_TopologySort.java
│ ├── Code04_Kruskal.java
│ ├── Code05_Prim.java
│ ├── Code06_Dijkstra.java
│ ├── Code07_MergeUsers.java
│ ├── Edge.java
│ ├── Graph.java
│ ├── GraphGenerator.java
│ └── Node.java
│ ├── class11
│ ├── Code01_Hanoi.java
│ ├── Code02_PrintAllSubsquences.java
│ ├── Code03_PrintAllPermutations.java
│ ├── Code04_ReverseStackUsingRecursive.java
│ ├── Code06_ConvertToLetterString.java
│ ├── Code07_Knapsack.java
│ ├── Code08_CardsInLine.java
│ └── Code09_NQueens.java
│ └── class12
│ ├── Code01_RobotWalk.java
│ ├── Code02_StickersToSpellWord.java
│ ├── Code03_Knapsack.java
│ ├── Code04_CardsInLine.java
│ ├── Code05_PalindromeSubsequence.java
│ ├── Code06_Coffee.java
│ ├── Code07_HorseJump.java
│ ├── Code08_MinPathSum.java
│ └── Code09_CoinsWay.java
├── 每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)
└── weekly-problems
│ └── src
│ ├── class_2021_11_4_week
│ ├── Code01_RetainTree.java
│ ├── Code02_GuessNumberHigherOrLowerII.java
│ └── Code03_StartToEndBinaryOneTarget.java
│ ├── class_2021_12_1_week
│ ├── Code01_XtoYMinDistance.java
│ ├── Code02_4KeysKeyboard.java
│ └── Code03_RedundantConnectionII.java
│ ├── class_2021_12_2_week
│ ├── Code01_FindAllPeopleWithSecret.java
│ ├── Code02_AwayFromBlackHole.java
│ ├── Code03_MagicSum.java
│ ├── Code04_LowestCommonAncestorOfABinaryTreeIV.java
│ └── Code05_Colors.java
│ ├── class_2021_12_3_week
│ ├── Code01_RightMoveInBinaryTree.java
│ ├── Code02_BinaryNegate.java
│ ├── Code03_OneCountsInKSystem.java
│ ├── Code04_CutOffTreesForGolfEvent.java
│ └── Code05_MinContinuousFragment.java
│ ├── class_2021_12_4_week
│ ├── Code01_FiveNodesListNumbers.java
│ ├── Code02_MergeArea.java
│ ├── Code03_HowManyObtuseAngles.java
│ ├── Code04_MaximumNumberOfVisiblePoints.java
│ └── Code05_SplitApples.java
│ ├── class_2021_12_5_week
│ ├── Code01_LoudAndRich.java
│ ├── Code02_DoAllJobs.java
│ └── Code03_WaysToBuildWall.java
│ ├── class_2022_01_1_week
│ ├── Code01_ABDisappear.java
│ ├── Code02_CatAndMouse.java
│ ├── Code03_MaximumScoreFromPerformingMultiplicationOperations.java
│ ├── Code04_MinDistanceFromLeftUpToRightDownWalk4Directions.java
│ └── Problem_0913_CatAndMouse.java
│ ├── class_2022_01_2_week
│ ├── Code01_StringCounts.java
│ ├── Code02_BrickAll.java
│ ├── Code03_StringNumberConvertBinaryAndHexadecimal.java
│ ├── Code04_MinimumOperationsToMakeTheArrayKIncreasing.java
│ ├── Code05_MagicTowSubarrayMakeMaxSum.java
│ └── Code06_QuietSum.java
│ ├── class_2022_01_3_week
│ ├── Code01_AStarAlgorithm.java
│ ├── Code02_EscapeALargeMaze.java
│ └── Code03_ShortestSubarrayWithSumAtLeastK.java
│ ├── class_2022_01_4_week
│ ├── Code01_BuyThingsAboutCollocation.java
│ ├── Code02_SplitToMArraysMinScore.java
│ ├── Code03_RandomPickWithBlacklist.java
│ └── Code04_BattleshipsInABoard.java
│ ├── class_2022_02_2_week
│ ├── Code01_24Game.java
│ ├── Code02_DesignBitset.java
│ ├── Code03_FindKthSmallestPairDistance.java
│ ├── Code04_ReachingPoints.java
│ └── Code05_RecoverTheOriginalArray.java
│ ├── class_2022_02_3_week
│ ├── Code01_CheapestFlightsWithinKStops.java
│ ├── Code02_MinimumNumberOfDaysToEatNOranges.java
│ ├── Code03_RobotBoundedInCircle.java
│ ├── Code04_MaxTeamNumber.java
│ └── Code05_StoneGameIX.java
│ ├── class_2022_02_4_week
│ ├── Code01_SplitSameNumberWays.java
│ ├── Code02_NearBiggerNoSameNeighbour.java
│ ├── Code03_PartitionArrayForMaximumSum.java
│ ├── Code04_NumberOfDescendingTriples.java
│ └── Code05_GroupsOfStrings.java
│ ├── class_2022_03_1_week
│ ├── Code01_StronglyConnectedComponents.java
│ ├── Code02_NetworkOfSchools.java
│ ├── Code03_PopularCows.java
│ └── Code04_IgniteMinBombs.java
│ ├── class_2022_03_2_week
│ ├── Code01_MeetingCheck.java
│ ├── Code02_StringCheck.java
│ ├── Code03_AiFill.java
│ ├── Code04_SameTeams.java
│ ├── Code05_NumberOfDivisibleByM.java
│ ├── Code06_JobMinDays.java
│ ├── Code07_MinWaitingTime.java
│ └── Code08_TimeNSpace1LowestCommonAncestor.java
│ ├── class_2022_03_3_week
│ ├── Code01_LongestUncontinuousSet.java
│ ├── Code02_CutDouFu.java
│ ├── Code03_MaxSumOnReverseArray.java
│ ├── Code04_ArrangeAddGetMax.java
│ ├── Code05_EatFish.java
│ ├── Code06_FinancialProduct.java
│ └── Code07_CoopDevelop.java
│ ├── class_2022_03_4_week
│ ├── Code01_ArrangeJob.java
│ ├── Code02_BuyGoodsHaveDiscount.java
│ ├── Code03_MinTowNumberSumABS.java
│ ├── Code04_JumpToTargets.java
│ ├── Code05_HowManyWaysFromBottomToTop.java
│ ├── Code06_LongestContinuousTrees.java
│ ├── Code07_IrregularSudoku.java
│ └── Code08_EggXtoY.java
│ ├── class_2022_03_5_week
│ ├── Code01_KMAlgorithm.java
│ ├── Code02_ToAllSpace.java
│ ├── Code03_MaximumAndSumOfArray.java
│ └── Code04_KillAllSameTime.java
│ ├── class_2022_04_1_week
│ ├── Code01_FourNumbersMinusOne.java
│ ├── Code02_MaxOrSmallestSubarray.java
│ ├── Code03_ArrangeMeetingPosCancelPre.java
│ ├── Code04_MaxScoreMoveInBoard.java
│ ├── Code05_PickKnumbersNearTowNumberMaxDiff.java
│ ├── Code06_TopMinSubsquenceSum.java
│ └── Code07_TopMaxSubsquenceSum.java
│ ├── class_2022_04_2_week
│ ├── Code01_SumOfValuesAboutPrimes.java
│ ├── Code02_MinDistanceFromLeftUpToRightDown.java
│ ├── Code03_MaxSumDividedBy7.java
│ ├── Code04_AllJobFinishTime.java
│ ├── Code05_TowLongestSubarraySame01Number.java
│ ├── Code06_PerfectPairNumber.java
│ └── Code07_MaxMoneyMostMin.java
│ ├── class_2022_04_3_week
│ ├── Code01_MaxOneNumbers.java
│ ├── Code02_RMQ.java
│ ├── Code03_ValidSortedArrayWays.java
│ ├── Code04_SumEvenSubNumber.java
│ └── Code05_ModKSubstringNumbers.java
│ ├── class_2022_05_1_week
│ ├── Code01_JumMinSameValue.java
│ ├── Code02_WhoWin21Balls.java
│ ├── Code03_FindDuplicateOnlyOne.java
│ ├── Code04_SumOfQuadraticSum.java
│ └── Code05_PalindromeStringNoLessKLenNoOverlapingMaxParts.java
│ ├── class_2022_05_2_week
│ ├── Code01_TwoObjectMaxValue.java
│ ├── Code02_ModifyOneNumberModXWays.java
│ ├── Code03_SortedSubsequenceMaxSum.java
│ ├── Code04_OneEdgeMagicMinPathSum.java
│ └── Code05_RedAndWhiteSquares.java
│ ├── class_2022_05_3_week
│ ├── Code01_MaxNumberUnderLimit.java
│ ├── Code02_RemoveNumbersNotIncreasingAll.java
│ ├── Code03_NumberOfCannon.java
│ └── Code04_MinJumpUsePre.java
│ ├── class_2022_05_4_week
│ ├── Code01_SomeDPFromVT.java
│ ├── Code02_MinSetForEveryRange.java
│ ├── Code03_MaxIncreasingSubarrayCanDeleteContinuousPart.java
│ └── Code04_ABCSameNumber.java
│ ├── class_2022_06_1_week
│ ├── Code01_WhereWillTheBallFall.java
│ ├── Code02_UniqueSubstringsInWraparoundString.java
│ ├── Code03_NumberOfAtoms.java
│ └── Code04_SubstringWithLargestVariance.java
│ ├── class_2022_06_2_week
│ ├── Code01_MostStonesRemovedWithSameRowOrColumn.java
│ ├── Code02_Solution.HEIC
│ ├── Code02_SumOfTotalStrengthOfWizards.java
│ ├── Code03_NumberOfDifferentSubsequencesGCDs.java
│ └── Code04_ConsecutiveNumbersSum.java
│ ├── class_2022_06_3_week
│ ├── Code01_MaxChunksToMakeSortedII.java
│ ├── Code02_SellingPiecesOfWood.java
│ ├── Code03_RangeModule1.java
│ ├── Code03_RangeModule2.java
│ └── Code04_StarNumber.java
│ ├── class_2022_06_4_week
│ ├── Code01_MinimumWindowSubsequence.java
│ ├── Code02_StackNotSplit.java
│ ├── Code03_MaxAnimalNumber.java
│ └── Code04_MinimizeMaxDistanceToGasStation.java
│ ├── class_2022_07_1_week
│ ├── Code01_WindPrevent.java
│ ├── Code02_MinimumScoreAfterRemovalsOnATree.java
│ └── Code03_NumberOfPeopleAwareOfASecret.java
│ ├── class_2022_07_2_week
│ ├── Code01_DistinctSubseqValue.java
│ ├── Code02_WaysSubsqenceXToY.java
│ ├── Code03_SwimInRisingWater.java
│ ├── Code04_EmployeeFreeTime.java
│ ├── Code05_LineSweepAlgorithm1.java
│ └── Code05_LineSweepAlgorithm2.java
│ ├── class_2022_07_3_week
│ ├── Code01_SetIntersectionSizeAtLeastTwo.java
│ ├── Code02_ValidParenthesisString.java
│ ├── Code03_TopKFrequentElements.java
│ └── Code04_SpecialBinaryString.java
│ ├── class_2022_07_4_week
│ ├── Code01_WaysWiggle.java
│ ├── Code02_MatchsticksToSquare.java
│ └── Code03_TheNumberOfGoodSubsets.java
│ ├── class_2022_08_1_week
│ ├── Code01_SidingPuzzle1.java
│ ├── Code01_SidingPuzzle2.java
│ ├── Code02_WaterKing.java
│ ├── Code03_OnlineMajorityElementInSubarray.java
│ ├── Code04_ShortestImpossibleSequenceOfRolls.java
│ ├── Code05_LongestOneLetterManyNumberString.java
│ └── Code06_SortStackUsingRecursive.java
│ ├── class_2022_08_2_week
│ ├── Code01_ParenthesesDye.java
│ ├── Code02_TreeDye.java
│ ├── Code03_ReversePolishNotation.java
│ ├── Code04_ClosestTwoPoints1.java
│ └── Code04_ClosestTwoPoints2.java
│ ├── class_2022_08_3_week
│ ├── Code01_LongestCycleInGraph1.java
│ ├── Code01_LongestCycleInGraph2.java
│ ├── Code02_CutOrPoison.java
│ ├── Code03_MaxStack.java
│ ├── Code04_CorporateFlightBookings.java
│ └── Code05_SmallestRotationWithHighestScore.java
│ ├── class_2022_08_4_week
│ ├── Code01_MaxXFromStock.java
│ ├── Code02_ChangeToSame.java
│ ├── Code03_FindPosition.java
│ ├── Code04_MaxPalindromeNumber.java
│ ├── Code05_TravelMinFuel.java
│ └── Code06_MinCostMostE.java
│ ├── class_2022_08_5_week
│ ├── Code01_Cakes.java
│ ├── Code02_MinAddToMatch.java
│ ├── Code03_SubarrayMakeSrotedMaxSum.java
│ └── Code04_DreamCity.java
│ ├── class_2022_09_1_week
│ ├── Code01_LongestIdealString.java
│ ├── Code02_MoveCityGetMoney.java
│ ├── Code03_RobotAndClothes.java
│ ├── Code04_QueryTopKSum.java
│ └── Code05_IsGraphBipartite.java
│ ├── class_2022_09_2_week
│ ├── Code01_SortGame.java
│ ├── Code02_NLengthMValueLIS3.java
│ ├── Code03_EvenTimesMaxSubstring.java
│ ├── Code04_RunThroughZero1.java
│ └── Code04_RunThroughZero2.java
│ ├── class_2022_09_3_week
│ ├── Code01_BlackWhiteChess.java
│ ├── Code02_EntryRoomGetMoney.java
│ ├── Code03_AllNumbersModToZeroMinTimes.java
│ ├── Code04_ExaminationPaperWays.java
│ ├── Code05_MaxLengthSameCharMChanges.java
│ └── Code06_RedPalindromeGoodStrings.java
│ ├── class_2022_09_4_week
│ ├── Code01_RobotDeliverGoods.java
│ ├── Code02_SetAllOneMinTimes.java
│ ├── Code03_MostSeats.java
│ ├── Code04_PaintingGridWithThreeDifferentColors.java
│ └── Code05_EveryQueryUsers.java
│ ├── class_2022_10_1_week
│ ├── Code01_CriticalConnectionsInANetwork.java
│ ├── Code02_CaptureStrongHold.java
│ ├── Code03_MakeASortedMinSwaps.java
│ └── Code04_TwoTeamsSortedMinSwap.java
│ ├── class_2022_10_2_week
│ ├── Code01_RangesHasDominateNumber.java
│ ├── Code02_BestMedianPickAdjacent.java
│ ├── Code03_FindMazeMinPath.java
│ ├── Code04_ShortestPathToGetAllKeys.java
│ └── Code05_SoldierFindEnemy.java
│ ├── class_2022_10_3_week
│ ├── Code01_MaximumWidthRamp.java
│ ├── Code02_ThreeEqualParts.java
│ ├── Code03_AddToSorted.java
│ ├── Code04_EveryNodePickMostkEdgesMaxValue.java
│ └── Code05_RemoveSubstringRestPalindrome.java
│ ├── class_2022_10_4_week
│ ├── Code01_MaxPrimePairs.java
│ ├── Code02_MostTrailingZerosTurnLeftOfRightAtMostOnce.java
│ ├── Code03_MinimumCostToCutAStick.java
│ ├── Code04_NumberOfIncreasingRoadsThree.java
│ ├── Code05_CountDifferentPalindromicSubsequences.java
│ ├── Code06_StoreManager.java
│ └── Code07_RemoveMostKContinuousSameLongest.java
│ ├── class_2022_11_1_week
│ ├── Code01_DessertPriceClosedTarget.java
│ ├── Code02_ScoreAllMatrix.java
│ ├── Code03_HappyLimitLessGap.java
│ ├── Code04_ValueNoMoreXDigitsToY.java
│ └── Code05_CreateMinNumberFromPattern.java
│ ├── class_2022_11_3_week
│ ├── Code01_ComplementaryPairsInStringArray.java
│ ├── Code02_CouplesHoldingHands.java
│ ├── Code03_SortArrayByMovingItemsToEmptySpace.java
│ ├── Code04_PrefixAndSuffixSearch.java
│ └── Code05_FarAwaySuggestion.java
│ ├── class_2022_11_4_week
│ ├── Code01_AbsToArrayFinalLength.java
│ ├── Code02_LastStoneWeightII.java
│ ├── Code03_MinOperationsMakeSimilar.java
│ ├── Code04_SplitArrayWithSameAverage.java
│ └── Code05_PickBestToGetInValue.java
│ ├── class_2022_11_5_week
│ ├── Code01_FinishOrdersEndTimes.java
│ ├── Code02_ZigZagConversion.java
│ ├── Code03_SumOfSubSequenceWidths.java
│ └── Code04_NthDigit.java
│ ├── class_2022_12_1_week
│ ├── Code01_CountSpecialIntegers.java
│ ├── Code02_HeightAfterSubtreeRemoval.java
│ ├── Code03_SumOfDistancesInTree.java
│ ├── Code04_MinimumTotalDistanceTraveled.java
│ └── Code05_ArithmeticProgressionGame.java
│ ├── class_2022_12_2_week
│ ├── Code01_PrisonersEscapeGame.java
│ ├── Code02_MakingALargeIsland.java
│ ├── Code03_CountUniqueCharactersOfAllSubstrings.java
│ ├── Code04_StoneGameVII.java
│ └── Code05_LinkedListInBinaryTree.java
│ ├── class_2022_12_4_week
│ ├── Code01_StampingTheGrid.java
│ ├── Code02_ClearAndPresentDanger.java
│ ├── Code03_ShortestPathVisitingAllNodes.java
│ ├── Code04_AsFarFromLandAsPossible.java
│ ├── Code05_RaceCar.java
│ └── Code06_KSimilarStrings.java
│ ├── class_2023_01_1_week
│ ├── Code01_KthMissingPositiveNumber.java
│ ├── Code02_NthMagicalNumber.java
│ ├── Code03_MinimumCostToHireKWorkers.java
│ ├── Code04_MinimumNumberOfRefuelingStops.java
│ ├── Code05_OrderlyQueue.java
│ └── Code06_ValidPermutationsForDiSequence.java
│ ├── class_2023_01_2_week
│ ├── Code01_SimilarStringGroups.java
│ ├── Code02_MaximumFrequencyStack.java
│ ├── Code03_MinimumNumberOfMovesToMakePalindrome.java
│ ├── Code04_SwapRowOrColMakeDiagonalAllOne.java
│ └── Code05_BusStationsMinLevelNumbers.java
│ ├── class_2023_02_1_week
│ ├── Code01_MinimizeDeviationInArray.java
│ ├── Code02_MinimizeMalwareSpreadII.java
│ ├── Code03_SuperPalindromes.java
│ ├── Code04_FourKindsPaperQueryWays.java
│ └── Code05_NumberOfMusicPlaylists.java
│ └── class_2023_02_2_week
│ ├── Code01_LeastOperatorsToExpressNumber.java
│ └── Code02_StampingTheSequence.java
├── 算法和数据结构体系学习班
└── algorithmbasic2020
│ └── src
│ ├── class01
│ ├── Code01_SelectionSort.java
│ ├── Code02_BubbleSort.java
│ ├── Code03_InsertionSort.java
│ ├── Code04_BSExist.java
│ ├── Code05_BSNearLeft.java
│ ├── Code05_BSNearRight.java
│ └── Code06_BSAwesome.java
│ ├── class02
│ ├── Code01_Swap.java
│ ├── Code02_EvenTimesOddTimes.java
│ └── Code03_KM.java
│ ├── class03
│ ├── Code01_ReverseList.java
│ ├── Code02_DeleteGivenValue.java
│ ├── Code03_DoubleEndsQueueToStackAndQueue.java
│ ├── Code04_RingArray.java
│ ├── Code05_GetMinStack.java
│ ├── Code06_TwoStacksImplementQueue.java
│ ├── Code07_TwoQueueImplementStack.java
│ ├── Code08_GetMax.java
│ └── HashMapAndSortedMap.java
│ ├── class04
│ ├── Code01_MergeSort.java
│ ├── Code02_SmallSum.java
│ ├── Code03_ReversePair.java
│ └── Code04_BiggerThanRightTwice.java
│ ├── class05
│ ├── Code01_CountOfRangeSum.java
│ ├── Code02_PartitionAndQuickSort.java
│ ├── Code03_QuickSortRecursiveAndUnrecursive.java
│ └── Code04_DoubleLinkedListQuickSort.java
│ ├── class06
│ ├── Code01_Comparator.java
│ ├── Code02_Heap.java
│ ├── Code03_HeapSort.java
│ └── Code04_SortArrayDistanceLessK.java
│ ├── class07
│ ├── Code01_CoverMax.java
│ ├── Code02_EveryStepShowBoss.java
│ ├── HeapGreater.java
│ └── Inner.java
│ ├── class08
│ ├── Code01_Trie.java
│ ├── Code02_Trie.java
│ ├── Code03_CountSort.java
│ └── Code04_RadixSort.java
│ ├── class09
│ ├── Code01_LinkedListMid.java
│ ├── Code02_IsPalindromeList.java
│ ├── Code03_SmallerEqualBigger.java
│ └── Code04_CopyListWithRandom.java
│ ├── class10
│ ├── Code01_FindFirstIntersectNode.java
│ ├── Code02_RecursiveTraversalBT.java
│ └── Code03_UnRecursiveTraversalBT.java
│ ├── class11
│ ├── Code01_LevelTraversalBT.java
│ ├── Code02_SerializeAndReconstructTree.java
│ ├── Code03_EncodeNaryTreeToBinaryTree.java
│ ├── Code04_PrintBinaryTree.java
│ ├── Code05_TreeMaxWidth.java
│ ├── Code06_SuccessorNode.java
│ └── Code07_PaperFolding.java
│ ├── class12
│ ├── Code01_IsCBT.java
│ ├── Code02_IsBST.java
│ ├── Code03_IsBalanced.java
│ ├── Code04_IsFull.java
│ ├── Code05_MaxSubBSTSize.java
│ └── Code06_MaxDistance.java
│ ├── class13
│ ├── Code01_IsCBT.java
│ ├── Code02_MaxSubBSTHead.java
│ ├── Code03_lowestAncestor.java
│ ├── Code04_MaxHappy.java
│ └── Code05_LowestLexicography.java
│ ├── class14
│ ├── Code01_Light.java
│ ├── Code02_LessMoneySplitGold.java
│ ├── Code03_BestArrange.java
│ ├── Code04_IPO.java
│ └── Code05_UnionFind.java
│ ├── class15
│ ├── Code01_FriendCircles.java
│ ├── Code02_NumberOfIslands.java
│ └── Code03_NumberOfIslandsII.java
│ ├── class16
│ ├── Code01_BFS.java
│ ├── Code02_DFS.java
│ ├── Code03_TopologicalOrderBFS.java
│ ├── Code03_TopologicalOrderDFS1.java
│ ├── Code03_TopologicalOrderDFS2.java
│ ├── Code03_TopologySort.java
│ ├── Code04_Kruskal.java
│ ├── Code05_Prim.java
│ ├── Code06_Dijkstra.java
│ ├── Code06_NetworkDelayTime.java
│ ├── Edge.java
│ ├── Graph.java
│ ├── GraphGenerator.java
│ └── Node.java
│ ├── class17
│ ├── Code01_Dijkstra.java
│ ├── Code02_Hanoi.java
│ ├── Code03_PrintAllSubsquences.java
│ ├── Code04_PrintAllPermutations.java
│ ├── Code05_ReverseStackUsingRecursive.java
│ ├── Edge.java
│ ├── Graph.java
│ └── Node.java
│ ├── class18
│ ├── Code01_RobotWalk.java
│ └── Code02_CardsInLine.java
│ ├── class19
│ ├── Code01_Knapsack.java
│ ├── Code02_ConvertToLetterString.java
│ ├── Code03_StickersToSpellWord.java
│ └── Code04_LongestCommonSubsequence.java
│ ├── class20
│ ├── Code01_PalindromeSubsequence.java
│ ├── Code02_HorseJump.java
│ └── Code03_Coffee.java
│ ├── class21
│ ├── Code01_MinPathSum.java
│ ├── Code02_CoinsWayEveryPaperDifferent.java
│ ├── Code03_CoinsWayNoLimit.java
│ ├── Code04_CoinsWaySameValueSamePapper.java
│ └── Code05_BobDie.java
│ ├── class22
│ ├── Code01_KillMonster.java
│ ├── Code02_MinCoinsNoLimit.java
│ └── Code03_SplitNumber.java
│ ├── class23
│ ├── Code01_SplitSumClosed.java
│ ├── Code02_SplitSumClosedSizeHalf.java
│ └── Code03_NQueens.java
│ ├── class24
│ ├── Code01_SlidingWindowMaxArray.java
│ ├── Code02_AllLessNumSubArray.java
│ ├── Code03_GasStation.java
│ └── Code04_MinCoinsOnePaper.java
│ ├── class25
│ ├── Code01_MonotonousStack.java
│ ├── Code01_MonotonousStackForNowcoder.java
│ ├── Code02_AllTimesMinToMax.java
│ ├── Code03_LargestRectangleInHistogram.java
│ ├── Code04_MaximalRectangle.java
│ └── Code05_CountSubmatricesWithAllOnes.java
│ ├── class26
│ ├── Code01_SumOfSubarrayMinimums.java
│ ├── Code02_FibonacciProblem.java
│ └── Code03_ZeroLeftOneStringNumber.java
│ ├── class27
│ ├── Code01_KMP.java
│ ├── Code02_TreeEqual.java
│ └── Code03_IsRotation.java
│ ├── class28
│ ├── Code01_Manacher.java
│ └── Code02_AddShortestEnd.java
│ ├── class29
│ ├── Code01_FindMinKth.java
│ ├── Code02_MaxTopK.java
│ └── Code03_ReservoirSampling.java
│ ├── class30
│ ├── Code01_MorrisTraversal.java
│ └── Code02_MinDepth.java
│ ├── class31
│ ├── Code01_SegmentTree.java
│ └── Code02_FallingSquares.java
│ ├── class32
│ ├── Code01_IndexTree.java
│ ├── Code02_IndexTree2D.java
│ ├── Code03_AC1.java
│ └── Code04_AC2.java
│ ├── class33
│ └── Hash.java
│ ├── class34
│ └── ReadMe.java
│ ├── class35
│ └── Code01_AVLTreeMap.java
│ ├── class36
│ ├── Code01_SizeBalancedTreeMap.java
│ └── Code02_SkipListMap.java
│ ├── class37
│ ├── Code01_CountofRangeSum.java
│ ├── Code02_SlidingWindowMedian.java
│ ├── Code03_AddRemoveGetIndexGreat.java
│ ├── Code04_QueueReconstructionByHeight.java
│ └── Compare.java
│ ├── class38
│ ├── Code01_AppleMinBags.java
│ ├── Code02_EatGrass.java
│ ├── Code03_MSumToN.java
│ └── Code04_MoneyProblem.java
│ ├── class39
│ ├── Code01_SubsquenceMaxModM.java
│ ├── Code02_SnacksWays.java
│ ├── Code02_SnacksWaysMain1.java
│ ├── Code02_SnacksWaysMain2.java
│ ├── Code03_10Ways.java
│ ├── Code04_DifferentBTNum.java
│ └── IsSum.java
│ ├── class40
│ ├── Code01_LongestSumSubArrayLengthInPositiveArray.java
│ ├── Code02_LongestSumSubArrayLength.java
│ ├── Code03_LongestLessSumSubArrayLength.java
│ ├── Code04_AvgLessEqualValueLongestSubarray.java
│ ├── Code05_PrintMatrixSpiralOrder.java
│ ├── Code06_RotateMatrix.java
│ ├── Code07_ZigZagPrintMatrix.java
│ └── Code08_PrintStar.java
│ ├── class41
│ ├── Code01_BestSplitForAll.java
│ ├── Code02_BestSplitForEveryPosition.java
│ ├── Code03_StoneMerge.java
│ └── Code04_SplitArrayLargestSum.java
│ ├── class42
│ ├── Code01_PostOfficeProblem.java
│ └── Code02_ThrowChessPiecesProblem.java
│ ├── class43
│ ├── Code01_CanIWin.java
│ ├── Code02_TSP.java
│ └── Code03_PavingTile.java
│ ├── class44
│ ├── Code01_LastSubstringInLexicographicalOrder.java
│ ├── DC3.java
│ └── DC3_Algorithm.pdf
│ ├── class45
│ ├── Code01_InsertS2MakeMostAlphabeticalOrder.java
│ ├── Code02_CreateMaximumNumber.java
│ ├── Code03_LongestCommonSubstringConquerByHeight.java
│ └── Code04_LongestRepeatingSubstring.java
│ ├── class46
│ ├── Code01_BurstBalloons.java
│ ├── Code02_RemoveBoxes.java
│ ├── Code03_DeleteAdjacentSameCharacter.java
│ ├── Code04_MaxSumLengthNoMore.java
│ └── Code05_HuffmanTree.java
│ └── class47
│ ├── Code01_StrangePrinter.java
│ ├── Code02_RestoreWays.java
│ └── Code03_DinicAlgorithm.java
└── 算法和数据结构新手班
└── algorithm-primary
└── src
├── class01
├── Code01_PrintBinary.java
├── Code02_SumOfFactorial.java
├── Code03_Sort.java
├── Code04_SelectionSort.java
├── Code05_BubbleSort.java
└── Code06_InsertionSort.java
├── class02
├── Code01_PreSum.java
├── Code02_RandToRand.java
├── Code03_Comp.java
└── Code03_EqualProbabilityRandom.java
├── class03
├── Code01_BSExist.java
├── Code02_BSNearLeft.java
├── Code03_BSNearRight.java
├── Code04_BSAwesome.java
└── Code05_HashMapTreeMap.java
├── class04
├── Code01_ReverseList.java
├── Code02_LinkedListToQueueAndStack.java
├── Code03_DoubleLinkedListToDeque.java
├── Code04_ReverseNodesInKGroup.java
├── Code05_AddTwoNumbers.java
└── Code06_MergeTwoSortedLinkedList.java
├── class05
├── Code01_BitMap1.java
├── Code02_BitMap2.java
└── Code03_BitAddMinusMultiDiv.java
├── class06
├── Code01_MergeKSortedLists.java
├── Code02_SameTree.java
├── Code03_SymmetricTree.java
├── Code04_MaximumDepthOfBinaryTree.java
├── Code05_ConstructBinaryTreeFromPreorderAndInorderTraversal.java
├── ShowComparator.java
├── ShowComparator2.java
└── TraversalBinaryTree.java
├── class07
├── Code01_BinaryTreeLevelOrderTraversalII.java
├── Code02_BalancedBinaryTree.java
├── Code03_PathSum.java
├── Code04_PathSumII.java
└── Code05_IsBinarySearchTree.java
└── class08
├── Code01_GetMax.java
├── Code02_MergeSort.java
└── Code03_PartitionAndQuickSort.java
/.gitignore:
--------------------------------------------------------------------------------
1 | ### Java template
2 | # Compiled class file
3 | *.class
4 |
5 | # Log file
6 | *.log
7 |
8 | # BlueJ files
9 | *.ctxt
10 |
11 | # Mobile Tools for Java (J2ME)
12 | .mtj.tmp/
13 |
14 | # Package Files #
15 | *.jar
16 | *.war
17 | *.nar
18 | *.ear
19 | *.zip
20 | *.tar.gz
21 | *.rar
22 |
23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24 | hs_err_pid*
25 | replay_pid*
26 |
27 | ### Example user template template
28 | ### Example user template
29 |
30 | # IntelliJ project files
31 | .idea
32 | *.iml
33 | out
34 | gen
35 | !/.idea/
36 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/.gitignore
--------------------------------------------------------------------------------
/.idea/Data_Structure_Demo03.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/aws.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/checkstyle-idea.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 10.5.0
5 | JavaOnly
6 | true
7 |
8 |
9 |
10 |
11 | (bundled)
12 | (bundled)
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/git_toolbox_prj.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/jpa-buddy.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/setting.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/0/7/07c4a297613af8e1c0cad22a3dd6980483604993:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/0/7/07c4a297613af8e1c0cad22a3dd6980483604993
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/0/b/0b254e7545574216406e39652769f9838fb6d4e3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/0/b/0b254e7545574216406e39652769f9838fb6d4e3
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/0/e/0e2d5e943fb0ba0e9e21918bf98ed77f55a127ca:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/0/e/0e2d5e943fb0ba0e9e21918bf98ed77f55a127ca
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/2/6/26c396588b2458a954b767018e763575e57dc9f6:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/2/6/26c396588b2458a954b767018e763575e57dc9f6
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/3/6/366262d0a6a58b2a19a0c1afd3a17980c7b149c8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/3/6/366262d0a6a58b2a19a0c1afd3a17980c7b149c8
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/4/f/4f6e6a5dcf8687c45ef19eae7747c66c87dff21f:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/4/f/4f6e6a5dcf8687c45ef19eae7747c66c87dff21f
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/5/3/53f83880527ccd54f2016a1ace55f18fb16a5205:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/5/3/53f83880527ccd54f2016a1ace55f18fb16a5205
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/8/d/8d3d15e619e025684b8d4d55213cce21405bc61d:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/8/d/8d3d15e619e025684b8d4d55213cce21405bc61d
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/9/2/92513f27320deeb9f01943f822cbe77eddf8ba73:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/9/2/92513f27320deeb9f01943f822cbe77eddf8ba73
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/9/d/9d1285124cc6e366657924a2bcec45e25c843e6e:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/9/d/9d1285124cc6e366657924a2bcec45e25c843e6e
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/a/8/a8a09f2c5e56bc52746937a31c67fb2fd9f5d411:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/a/8/a8a09f2c5e56bc52746937a31c67fb2fd9f5d411
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/f/1/f17ca5bb773c72da0c5b4ec1ee7ebdd8013a0cb0:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/f/1/f17ca5bb773c72da0c5b4ec1ee7ebdd8013a0cb0
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/f/4/f4c43a051654c4b5e41040d2821920de6838ff25:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/f/4/f4c43a051654c4b5e41040d2821920de6838ff25
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/f/4/f4f70628310297cd6a84f2cf4986c275a911d7f1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/f/4/f4f70628310297cd6a84f2cf4986c275a911d7f1
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/index.pb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/.idea/sonarlint/issuestore/index.pb
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Demo1/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.shf
8 | Demo1
9 | 1.0-SNAPSHOT
10 |
11 |
12 | 8
13 | 8
14 | UTF-8
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Demo1/src/main/java/com/shf/Main.java:
--------------------------------------------------------------------------------
1 | package com.shf;
2 |
3 | public class Main {
4 | public static void main(String[] args) {
5 | System.out.println("Hello world!");
6 | }
7 | }
--------------------------------------------------------------------------------
/Demo1/src/main/java/com/shf/Recursion/Test.java:
--------------------------------------------------------------------------------
1 | package com.shf.Recursion;
2 |
3 | public class Test {
4 | public static void main(String[] args) {
5 | System.out.println(f(10));
6 | }
7 |
8 | static long f(int n) {
9 | if (n < 1) {
10 | return -1;
11 | }
12 | if (n == 1) {
13 | return 1;
14 | }
15 | return n + f(n - 1);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Demo1/src/main/java/com/shf/sort/BubbleSort.java:
--------------------------------------------------------------------------------
1 | package com.shf.sort;
2 |
3 | import com.shf.sort.utils.Print;
4 | import com.shf.sort.utils.Swap;
5 |
6 | /**
7 | * 冒泡排序 基本不用,太慢
8 | */
9 | public class BubbleSort {
10 | public static void main(String[] args) {
11 | int[] a = {9, 3, 1, 4, 6, 8, 7, 5, 2};
12 | sort(a);
13 | Print.print(a);
14 | }
15 |
16 | static void sort(int[] a) {
17 | for (int i = 0; i < a.length-1; i++) {
18 | for (int j = 0; j < a.length-i-1; j++) {
19 | if (a[j] > a[j + 1]) {
20 | Swap.swap(a, j, j + 1);
21 | }
22 | }
23 |
24 | }
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/Demo1/src/main/java/com/shf/sort/InsertionSort.java:
--------------------------------------------------------------------------------
1 | package com.shf.sort;
2 |
3 | import com.shf.sort.utils.Print;
4 | import com.shf.sort.utils.Swap;
5 |
6 | /**
7 | * 插入排序 样本小且基本有序的时候效率比较高
8 | *
9 | * 斗地主
10 | *
11 | * 从第二个数开始往前遍历,如果小就交换
12 | */
13 | public class InsertionSort {
14 | public static void main(String[] args) {
15 | int[] a = {9, 3, 1, 4, 6, 8, 7, 5, 2};
16 | sort(a);
17 | Print.print(a);
18 | }
19 |
20 | static void sort(int[] a) {
21 | for (int i = 1; i < a.length; i++) {
22 | for (int j = i; j > 0; j--) {
23 | if (a[j] < a[j - 1]) {
24 | Swap.swap(a, j, j - 1);
25 | }
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Demo1/src/main/java/com/shf/sort/utils/Print.java:
--------------------------------------------------------------------------------
1 | package com.shf.sort.utils;
2 |
3 | public class Print {
4 | public static void print(int[] arr) {
5 | for (int i = 0; i < arr.length; i++) {
6 | System.out.print(arr[i]+" ");
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Demo1/src/main/java/com/shf/sort/utils/Swap.java:
--------------------------------------------------------------------------------
1 | package com.shf.sort.utils;
2 |
3 | public class Swap {
4 | public static void swap(int[] arr, int i, int j) {
5 | int temp = arr[i];
6 | arr[i] = arr[j];
7 | arr[j] = temp;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/Demo1/target/classes/com/shf/Main.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/Demo1/target/classes/com/shf/Main.class
--------------------------------------------------------------------------------
/Demo1/target/classes/com/shf/Recursion/Test.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/Demo1/target/classes/com/shf/Recursion/Test.class
--------------------------------------------------------------------------------
/Demo1/target/classes/com/shf/sort/BubbleSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/Demo1/target/classes/com/shf/sort/BubbleSort.class
--------------------------------------------------------------------------------
/Demo1/target/classes/com/shf/sort/CountSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/Demo1/target/classes/com/shf/sort/CountSort.class
--------------------------------------------------------------------------------
/Demo1/target/classes/com/shf/sort/DataChecker.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/Demo1/target/classes/com/shf/sort/DataChecker.class
--------------------------------------------------------------------------------
/Demo1/target/classes/com/shf/sort/InsertionSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/Demo1/target/classes/com/shf/sort/InsertionSort.class
--------------------------------------------------------------------------------
/Demo1/target/classes/com/shf/sort/MergeSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/Demo1/target/classes/com/shf/sort/MergeSort.class
--------------------------------------------------------------------------------
/Demo1/target/classes/com/shf/sort/QuickSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/Demo1/target/classes/com/shf/sort/QuickSort.class
--------------------------------------------------------------------------------
/Demo1/target/classes/com/shf/sort/RadixSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/Demo1/target/classes/com/shf/sort/RadixSort.class
--------------------------------------------------------------------------------
/Demo1/target/classes/com/shf/sort/SelectionSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/Demo1/target/classes/com/shf/sort/SelectionSort.class
--------------------------------------------------------------------------------
/Demo1/target/classes/com/shf/sort/ShellSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/Demo1/target/classes/com/shf/sort/ShellSort.class
--------------------------------------------------------------------------------
/Demo1/target/classes/com/shf/sort/utils/Print.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/Demo1/target/classes/com/shf/sort/utils/Print.class
--------------------------------------------------------------------------------
/Demo1/target/classes/com/shf/sort/utils/Swap.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/Demo1/target/classes/com/shf/sort/utils/Swap.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class01/Code01_PrintBinary.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class01/Code01_PrintBinary.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class01/Code02_SumOfFactorial.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class01/Code02_SumOfFactorial.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class01/Code03_Sort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class01/Code03_Sort.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class01/Code04_SelectionSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class01/Code04_SelectionSort.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class01/Code05_BubbleSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class01/Code05_BubbleSort.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class01/Code06_InsertionSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class01/Code06_InsertionSort.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class02/Code01_PreSum$RangeSum1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class02/Code01_PreSum$RangeSum1.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class02/Code01_PreSum$RangeSum2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class02/Code01_PreSum$RangeSum2.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class02/Code01_PreSum.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class02/Code01_PreSum.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class02/Code02_RandToRand$RandomBox.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class02/Code02_RandToRand$RandomBox.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class02/Code02_RandToRand.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class02/Code02_RandToRand.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class02/Code03_Comp.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class02/Code03_Comp.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class02/Code03_EqualProbabilityRandom$RandomBox.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class02/Code03_EqualProbabilityRandom$RandomBox.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class02/Code03_EqualProbabilityRandom.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class02/Code03_EqualProbabilityRandom.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class03/Code01_BSExist.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class03/Code01_BSExist.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class03/Code02_BSNearLeft.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class03/Code02_BSNearLeft.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class03/Code03_BSNearRight.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class03/Code03_BSNearRight.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class03/Code04_BSAwesome.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class03/Code04_BSAwesome.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class03/Code05_HashMapTreeMap$Node.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class03/Code05_HashMapTreeMap$Node.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class03/Code05_HashMapTreeMap.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class03/Code05_HashMapTreeMap.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code01_ReverseList$DoubleNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code01_ReverseList$DoubleNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code01_ReverseList$Node.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code01_ReverseList$Node.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code01_ReverseList.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code01_ReverseList.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code02_LinkedListToQueueAndStack$MyQueue.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code02_LinkedListToQueueAndStack$MyQueue.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code02_LinkedListToQueueAndStack$MyStack.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code02_LinkedListToQueueAndStack$MyStack.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code02_LinkedListToQueueAndStack$Node.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code02_LinkedListToQueueAndStack$Node.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code02_LinkedListToQueueAndStack.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code02_LinkedListToQueueAndStack.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code03_DoubleLinkedListToDeque$MyDeque.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code03_DoubleLinkedListToDeque$MyDeque.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code03_DoubleLinkedListToDeque$Node.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code03_DoubleLinkedListToDeque$Node.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code03_DoubleLinkedListToDeque.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code03_DoubleLinkedListToDeque.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code04_ReverseNodesInKGroup$ListNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code04_ReverseNodesInKGroup$ListNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code04_ReverseNodesInKGroup.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code04_ReverseNodesInKGroup.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code05_AddTwoNumbers$ListNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code05_AddTwoNumbers$ListNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code05_AddTwoNumbers.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code05_AddTwoNumbers.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code06_MergeTwoSortedLinkedList$ListNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code06_MergeTwoSortedLinkedList$ListNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class04/Code06_MergeTwoSortedLinkedList.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class04/Code06_MergeTwoSortedLinkedList.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class05/Code01_BitMap1$BitMap.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class05/Code01_BitMap1$BitMap.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class05/Code01_BitMap1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class05/Code01_BitMap1.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class05/Code02_BitMap2$BitMap.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class05/Code02_BitMap2$BitMap.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class05/Code02_BitMap2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class05/Code02_BitMap2.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class05/Code03_BitAddMinusMultiDiv.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class05/Code03_BitAddMinusMultiDiv.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/Code01_MergeKSortedLists$ListNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/Code01_MergeKSortedLists$ListNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/Code01_MergeKSortedLists$ListNodeComparator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/Code01_MergeKSortedLists$ListNodeComparator.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/Code01_MergeKSortedLists.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/Code01_MergeKSortedLists.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/Code02_SameTree$TreeNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/Code02_SameTree$TreeNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/Code02_SameTree.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/Code02_SameTree.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/Code03_SymmetricTree$TreeNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/Code03_SymmetricTree$TreeNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/Code03_SymmetricTree.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/Code03_SymmetricTree.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/Code04_MaximumDepthOfBinaryTree$TreeNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/Code04_MaximumDepthOfBinaryTree$TreeNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/Code04_MaximumDepthOfBinaryTree.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/Code04_MaximumDepthOfBinaryTree.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/Code05_ConstructBinaryTreeFromPreorderAndInorderTraversal$TreeNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/Code05_ConstructBinaryTreeFromPreorderAndInorderTraversal$TreeNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/Code05_ConstructBinaryTreeFromPreorderAndInorderTraversal.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/Code05_ConstructBinaryTreeFromPreorderAndInorderTraversal.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/ShowComparator$AgeComparator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/ShowComparator$AgeComparator.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/ShowComparator$IdComparator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/ShowComparator$IdComparator.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/ShowComparator$Student.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/ShowComparator$Student.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/ShowComparator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/ShowComparator.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/ShowComparator2$IdComparator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/ShowComparator2$IdComparator.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/ShowComparator2$MyComparator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/ShowComparator2$MyComparator.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/ShowComparator2$Student.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/ShowComparator2$Student.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/ShowComparator2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/ShowComparator2.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/TraversalBinaryTree$Node.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/TraversalBinaryTree$Node.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class06/TraversalBinaryTree.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class06/TraversalBinaryTree.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class07/Code01_BinaryTreeLevelOrderTraversalII$TreeNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class07/Code01_BinaryTreeLevelOrderTraversalII$TreeNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class07/Code01_BinaryTreeLevelOrderTraversalII.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class07/Code01_BinaryTreeLevelOrderTraversalII.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class07/Code02_BalancedBinaryTree$Info.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class07/Code02_BalancedBinaryTree$Info.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class07/Code02_BalancedBinaryTree$TreeNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class07/Code02_BalancedBinaryTree$TreeNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class07/Code02_BalancedBinaryTree.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class07/Code02_BalancedBinaryTree.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class07/Code03_PathSum$TreeNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class07/Code03_PathSum$TreeNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class07/Code03_PathSum.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class07/Code03_PathSum.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class07/Code04_PathSumII$TreeNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class07/Code04_PathSumII$TreeNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class07/Code04_PathSumII.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class07/Code04_PathSumII.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class07/Code05_IsBinarySearchTree$Info.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class07/Code05_IsBinarySearchTree$Info.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class07/Code05_IsBinarySearchTree$TreeNode.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class07/Code05_IsBinarySearchTree$TreeNode.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class07/Code05_IsBinarySearchTree.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class07/Code05_IsBinarySearchTree.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class08/Code01_GetMax.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class08/Code01_GetMax.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class08/Code02_MergeSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class08/Code02_MergeSort.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class08/Code03_PartitionAndQuickSort$Job.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class08/Code03_PartitionAndQuickSort$Job.class
--------------------------------------------------------------------------------
/out/production/algorithm-primary-main/class08/Code03_PartitionAndQuickSort.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/out/production/algorithm-primary-main/class08/Code03_PartitionAndQuickSort.class
--------------------------------------------------------------------------------
/publicclass2020/src/class008/Code01_JumpGameII.java:
--------------------------------------------------------------------------------
1 | package class008;
2 |
3 | public class Code01_JumpGameII {
4 |
5 | /*
6 | * 评测代码可以直接去leetcode搜索:Jump Game II
7 | *
8 | */
9 |
10 | public static int jump(int[] arr) {
11 | if (arr == null || arr.length == 0) {
12 | return 0;
13 | }
14 | int jump = 0;
15 | int cur = 0;
16 | int next = 0;
17 | for (int i = 0; i < arr.length; i++) {
18 | if (cur < i) {
19 | jump++;
20 | cur = next;
21 | }
22 | next = Math.max(next, i + arr[i]);
23 | }
24 | return jump;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/publicclass2020/src/class008/Code02_LongestConsecutiveSequence.java:
--------------------------------------------------------------------------------
1 | package class008;
2 |
3 | import java.util.HashMap;
4 |
5 | public class Code02_LongestConsecutiveSequence {
6 |
7 | public static int longestConsecutive(int[] nums) {
8 | HashMap map = new HashMap<>();
9 | int len = 0;
10 | for (int num : nums) {
11 | if (!map.containsKey(num)) {
12 | map.put(num, 1);
13 | int preLen = map.containsKey(num - 1) ? map.get(num - 1) : 0;
14 | int posLen = map.containsKey(num + 1) ? map.get(num + 1) : 0;
15 | int all = preLen + posLen + 1;
16 | map.put(num - preLen, all);
17 | map.put(num + posLen, all);
18 | len = Math.max(len, all);
19 | }
20 | }
21 | return len;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/publicclass2020/src/class009/Code02_SearchA2DMatrixII.java:
--------------------------------------------------------------------------------
1 | package class009;
2 |
3 | public class Code02_SearchA2DMatrixII {
4 |
5 | /*
6 | * 评测代码可以直接去leetcode搜索:Search a 2D Matrix II
7 | *
8 | */
9 |
10 | public static boolean searchMatrix(int[][] m, int target) {
11 | if (m == null || m.length == 0 || m[0] == null || m[0].length == 0) {
12 | return false;
13 | }
14 | int N = m.length;
15 | int M = m[0].length;
16 | int row = 0;
17 | int col = M - 1;
18 | while (row < N && col >= 0) {
19 | if (m[row][col] > target) {
20 | col--;
21 | } else if (m[row][col] < target) {
22 | row++;
23 | } else {
24 | return true;
25 | }
26 | }
27 | return false;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/publicclass2020/src/class010/Code01_SwapWithoutTmp.java:
--------------------------------------------------------------------------------
1 | package class010;
2 |
3 | public class Code01_SwapWithoutTmp {
4 |
5 | public static void main(String[] args) {
6 | int a = 111;
7 | int b = 111;
8 | System.out.println(a);
9 | System.out.println(b);
10 | a = a ^ b;
11 | b = a ^ b;
12 | a = a ^ b;
13 | System.out.println(a);
14 | System.out.println(b);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/publicclass2020/src/class013/Code01_PalindromeNumber.java:
--------------------------------------------------------------------------------
1 | package class013;
2 |
3 | public class Code01_PalindromeNumber {
4 |
5 | public static boolean isPalindrome(int n) {
6 | if (n < 0) {
7 | return false;
8 | }
9 | n = Math.abs(n);
10 | int help = 1;
11 | while (n / help >= 10) {
12 | help *= 10;
13 | }
14 | while (n != 0) {
15 | if (n / help != n % 10) {
16 | return false;
17 | }
18 | n = (n % help) / 10;
19 | help /= 100;
20 | }
21 | return true;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/publicclass2020/src/class018/Code01_SqrtX.java:
--------------------------------------------------------------------------------
1 | package class018;
2 |
3 | public class Code01_SqrtX {
4 |
5 | // x一定非负,输入可以保证
6 | public static int mySqrt(int x) {
7 | if (x == 0) {
8 | return 0;
9 | }
10 | // x != 0 1 2
11 | if (x < 3) {
12 | return 1;
13 | }
14 | // x >= 3
15 | long ans = 1;
16 | long L = 1;
17 | long R = x;
18 | long M = 0;
19 | while (L <= R) {
20 | M = (L + R) / 2;
21 | if (M * M <= x) {
22 | ans = M;
23 | L = M + 1;
24 | } else {
25 | R = M - 1;
26 | }
27 | }
28 | return (int) ans;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/publicclass2020/src/class018/Code03_ContainerWithMostWater.java:
--------------------------------------------------------------------------------
1 | package class018;
2 |
3 | public class Code03_ContainerWithMostWater {
4 |
5 | public static int maxArea1(int[] h) {
6 | int max = 0;
7 | int N = h.length;
8 | for (int i = 0; i < N; i++) { // h[i]
9 | for (int j = i + 1; j < N; j++) { // h[j]
10 | max = Math.max(max, Math.min(h[i], h[j]) * (j - i));
11 | }
12 | }
13 | return max;
14 | }
15 |
16 | public static int maxArea2(int[] h) {
17 | int max = 0;
18 | int l = 0;
19 | int r = h.length - 1;
20 | while (l < r) {
21 | max = Math.max(max, Math.min(h[l], h[r]) * (r - l));
22 | if (h[l] > h[r]) {
23 | r--;
24 | } else {
25 | l++;
26 | }
27 | }
28 | return max;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/publicclass2020/src/class019/Code01_RotateImage.java:
--------------------------------------------------------------------------------
1 | package class019;
2 |
3 | public class Code01_RotateImage {
4 |
5 | public static void rotate(int[][] matrix) {
6 | // matrix.length == matrix[0].length
7 | int a = 0;
8 | int b = 0;
9 | int c = matrix.length - 1;
10 | int d = matrix[0].length - 1;
11 | while (a < c) {
12 | rotateEdge(matrix, a++, b++, c--, d--);
13 | }
14 | }
15 |
16 | public static void rotateEdge(int[][] m, int a, int b, int c, int d) {
17 | int tmp = 0;
18 | for (int i = 0; i < d - b; i++) {
19 | tmp = m[a][b + i];
20 | m[a][b + i] = m[c - i][b];
21 | m[c - i][b] = m[c][d - i];
22 | m[c][d - i] = m[a + i][d];
23 | m[a + i][d] = tmp;
24 | }
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/publicclass2020/src/class021/Code01_SwapWithoutTmp.java:
--------------------------------------------------------------------------------
1 | package class021;
2 |
3 | public class Code01_SwapWithoutTmp {
4 |
5 | public static void main(String[] args) {
6 | int a = 123;
7 | int b = -898121;
8 | System.out.println(a);
9 | System.out.println(b);
10 | a = a ^ b;
11 | b = a ^ b;
12 | a = a ^ b;
13 | System.out.println(a);
14 | System.out.println(b);
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/publicclass2020/src/class029/Code02_EatGrass.java:
--------------------------------------------------------------------------------
1 | package class029;
2 |
3 | public class Code02_EatGrass {
4 |
5 | // 当前有N份草,当前轮到先手先吃,然后后手再吃
6 | // 1,4,16,64,...
7 | // 返回 String "先手" "后手"
8 | public static String winner1(int n) {
9 | if (n < 5) {
10 | return (n == 0 || n == 2) ? "后手" : "先手";
11 | }
12 | // 先手吃的草数
13 | int eat = 1;
14 | while (eat <= n) {
15 | if (winner1(n - eat).equals("后手")) {
16 | return "先手";
17 | }
18 | if (eat > n / 4) { // 防止溢出
19 | break;
20 | }
21 | eat *= 4;
22 | }
23 | return "后手";
24 | }
25 |
26 | public static String winner2(int n) {
27 | if (n % 5 == 0 || n % 5 == 2) {
28 | return "后手";
29 | } else {
30 | return "先手";
31 | }
32 | }
33 |
34 | public static void main(String[] args) {
35 | for (int i = 0; i <= 50; i++) {
36 | System.out.println(i + " : " + winner1(i));
37 | }
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/publicclass2020/src/class030/Code01_IsPalindrome.java:
--------------------------------------------------------------------------------
1 | package class030;
2 |
3 | // 测试链接:https://leetcode.com/problems/palindrome-number
4 | public class Code01_IsPalindrome {
5 |
6 | // n<0 不是回文数
7 | public static boolean isPalindrome(int n) {
8 | if (n < 0) {
9 | return false;
10 | }
11 | int help = 1;
12 | while (n / help >= 10) {
13 | help *= 10;
14 | }
15 | while (n != 0) {
16 | if (n / help != n % 10) {
17 | return false;
18 | }
19 | n = (n % help) / 10;
20 | help /= 100;
21 | }
22 | return true;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/publicclass2020/src/class030/Code02_MySqrt.java:
--------------------------------------------------------------------------------
1 | package class030;
2 |
3 | // 测试链接:https://leetcode.com/problems/sqrtx
4 | public class Code02_MySqrt {
5 |
6 | public static int mySqrt(int x) {
7 | if (x == 0) {
8 | return 0;
9 | }
10 | if (x < 3) {
11 | return 1;
12 | }
13 | long ans = 1;
14 | long L = 1;
15 | long R = x;
16 | long M = 0;
17 | // L...R 1....x
18 | while (L <= R) {
19 | M = (L + R) / 2;
20 | if (M * M <= x) {
21 | ans = M;
22 | L = M + 1;
23 | } else {
24 | R = M - 1;
25 | }
26 | }
27 | return (int) ans;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/publicclass2020/src/class030/Code04_EnterLoopNode.java:
--------------------------------------------------------------------------------
1 | package class030;
2 |
3 | // 测试链接:https://leetcode.com/problems/linked-list-cycle-ii
4 | public class Code04_EnterLoopNode {
5 |
6 | // 这个类不用提交
7 | public static class ListNode {
8 | public int val;
9 | public ListNode next;
10 | }
11 |
12 | // 只提交以下的代码
13 | public static ListNode detectCycle(ListNode head) {
14 | if (head == null || head.next == null || head.next.next == null) {
15 | return null;
16 | }
17 | ListNode slow = head.next;
18 | ListNode fast = head.next.next;
19 | while (slow != fast) {
20 | if (fast.next == null || fast.next.next == null) {
21 | return null;
22 | }
23 | fast = fast.next.next;
24 | slow = slow.next;
25 | }
26 | fast = head;
27 | while (slow != fast) {
28 | slow = slow.next;
29 | fast = fast.next;
30 | }
31 | return slow;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/publicclass2020/src/class031/Code01_SwapWithoutTmp.java:
--------------------------------------------------------------------------------
1 | package class031;
2 |
3 | public class Code01_SwapWithoutTmp {
4 |
5 | public static void main(String[] args) {
6 |
7 | int test1 = 23;
8 | int test2 = 15;
9 | System.out.println(test1 ^ test2);
10 |
11 |
12 |
13 | int a = -111;
14 | int b = 343242111;
15 | System.out.println(a);
16 | System.out.println(b);
17 | a = a ^ b;
18 | b = a ^ b;
19 | a = a ^ b;
20 | System.out.println(a);
21 | System.out.println(b);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/publicclass2020/src/class031/Code02_AddMinus.java:
--------------------------------------------------------------------------------
1 | package class031;
2 |
3 | public class Code02_AddMinus {
4 |
5 | public static int add(int a, int b) {
6 | int t = 0;
7 | while (b != 0) {
8 | t = a;
9 | a = a ^ b; // a -> a' 无进位相加信息
10 | b = ((t & b) << 1); // b -> b' 进位信息
11 | }
12 | return a;
13 | }
14 |
15 | public static int minus(int a, int b) {
16 | return add(a, add(~b, 1));
17 | }
18 |
19 | public static void main(String[] args) {
20 | int a = 8739284;
21 | int b = 7348472;
22 | System.out.println(a + b);
23 | System.out.println(add(a, b));
24 |
25 | System.out.println(a - b);
26 | System.out.println(minus(a, b));
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/publicclass2020/src/class031/Code04_MissingNumber.java:
--------------------------------------------------------------------------------
1 | package class031;
2 |
3 | // 测试链接:https://leetcode.com/problems/first-missing-positive/
4 | public class Code04_MissingNumber {
5 |
6 | public static int firstMissingPositive(int[] arr) {
7 | int l = 0;
8 | int r = arr.length;
9 | while (l != r) {
10 | if (arr[l] == l + 1) {
11 | l++;
12 | } else if (arr[l] <= l + 1 || arr[l] > r || arr[arr[l] - 1] == arr[l]) {
13 | swap(arr, l, --r);
14 | } else {
15 | swap(arr, l, arr[l] - 1);
16 | }
17 | }
18 | return l + 1;
19 | }
20 |
21 | public static void swap(int[] arr, int i, int j) {
22 | int tmp = arr[i];
23 | arr[i] = arr[j];
24 | arr[j] = tmp;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/publicclass2020/src/class032/Code03_PaperFolding.java:
--------------------------------------------------------------------------------
1 | package class032;
2 |
3 | public class Code03_PaperFolding {
4 |
5 | public static void printAllFolds(int N) {
6 | process(1, N, true);
7 | System.out.println();
8 | }
9 |
10 | // 假想中的当前节点,在i层,一共N层,
11 | // 假想中的当前节点凹还是凸?down决定!down = true 凹 down = false 凸
12 | // 打印以假想节点为头的整棵树,中序打印
13 | public static void process(int i, int N, boolean down) {
14 | if (i > N) {
15 | return;
16 | }
17 | process(i + 1, N, true);
18 | System.out.print(down ? "凹 " : "凸 ");
19 | process(i + 1, N, false);
20 | }
21 |
22 | public static void main(String[] args) {
23 | int N = 4;
24 | printAllFolds(N);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/publicclass2020/src/class037/Code02_JumpGameII.java:
--------------------------------------------------------------------------------
1 | package class037;
2 |
3 | // 测试页面:https://leetcode.com/problems/jump-game-ii/
4 | public class Code02_JumpGameII {
5 |
6 | public static int jump(int[] arr) {
7 | if (arr == null || arr.length == 0) {
8 | return 0;
9 | }
10 | int step = 0;
11 | int cur = 0;
12 | int next = 0;
13 | for (int i = 0; i < arr.length; i++) {
14 | if (cur < i) {
15 | step++;
16 | cur = next;
17 | }
18 | next = Math.max(next, i + arr[i]);
19 | }
20 | return step;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/publicclass2020/src/class038/Code04_MissingNumber.java:
--------------------------------------------------------------------------------
1 | package class038;
2 |
3 | // 测试链接:https://leetcode.com/problems/first-missing-positive/
4 | public class Code04_MissingNumber {
5 |
6 | public static int firstMissingPositive(int[] arr) {
7 | int l = 0;
8 | int r = arr.length;
9 | while (l != r) {
10 | if (arr[l] == l + 1) {
11 | l++;
12 | } else if (arr[l] <= l || arr[l] > r || arr[arr[l] - 1] == arr[l]) {
13 | swap(arr, l, --r);
14 | } else {
15 | swap(arr, l, arr[l] - 1);
16 | }
17 | }
18 | return l + 1;
19 | }
20 |
21 | public static void swap(int[] arr, int i, int j) {
22 | int tmp = arr[i];
23 | arr[i] = arr[j];
24 | arr[j] = tmp;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/publicclass2020/src/class040/Code01_PalindromeNumber.java:
--------------------------------------------------------------------------------
1 | package class040;
2 |
3 | public class Code01_PalindromeNumber {
4 |
5 | public static boolean isPalindrome(int n) {
6 | if (n < 0) {
7 | return false;
8 | }
9 | int help = 1;
10 | while (n / help >= 10) {
11 | help *= 10;
12 | }
13 | while (n != 0) {
14 | if (n / help != n % 10) {
15 | return false;
16 | }
17 | n = (n % help) / 10;
18 | help /= 100;
19 | }
20 | return true;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/publicclass2020/src/class040/Code02_MaximumProductSubarray.java:
--------------------------------------------------------------------------------
1 | package class040;
2 |
3 | // 本次测试链接 : https://leetcode.com/problems/maximum-product-subarray/
4 | public class Code02_MaximumProductSubarray {
5 |
6 | public static int maxProduct(int[] nums) {
7 | // 答案,最终要返回的!
8 | int ans = nums[0];
9 | // min : 必须以0结尾时,最小累乘积
10 | int min = nums[0];
11 | // min : 必须以0结尾时,最大累乘积
12 | int max = nums[0];
13 | for (int i = 1; i < nums.length; i++) {
14 | // curmin : 必须以i结尾时,最小累乘积
15 | int curmin = Math.min(nums[i], Math.min(min * nums[i], max * nums[i]));
16 | int curmax = Math.max(nums[i], Math.max(min * nums[i], max * nums[i]));
17 | min = curmin;
18 | max = curmax;
19 | ans = Math.max(ans, max);
20 | }
21 | return ans;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/publicclass2020/src/class043/Code04_FindOddTimesNumber.java:
--------------------------------------------------------------------------------
1 | package class043;
2 |
3 | public class Code04_FindOddTimesNumber {
4 |
5 | public static int oddTimesNumber(int[] arr) {
6 | int xor = 0;
7 | for (int num : arr) {
8 | xor ^= num;
9 | }
10 | return xor;
11 | }
12 |
13 | public static void main(String[] args) {
14 | int[] arr = { 3, 4, 3, 4, 2, 1, 4, 3, 3, 2, 4, 2, 3, 6, 2, 3, 6, 1, 6 };
15 | System.out.println(oddTimesNumber(arr));
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/publicclass2020/src/class045/Code04_MissingNumber.java:
--------------------------------------------------------------------------------
1 | package class045;
2 |
3 | // 测试链接:https://leetcode.com/problems/first-missing-positive/
4 | public class Code04_MissingNumber {
5 |
6 | public static int firstMissingPositive(int[] arr) {
7 | // l是盯着的位置
8 | // 0~l-1
9 | int l = 0;
10 | int r = arr.length;
11 | while (l != r) {
12 | if (arr[l] == l + 1) {
13 | l++;
14 | } else if (arr[l] <= l || arr[l] > r || arr[arr[l] - 1] == arr[l]) {
15 | swap(arr, l, --r);
16 | } else {
17 | swap(arr, l, arr[l] - 1);
18 | }
19 | }
20 | return l + 1;
21 | }
22 |
23 | public static void swap(int[] arr, int i, int j) {
24 | int tmp = arr[i];
25 | arr[i] = arr[j];
26 | arr[j] = tmp;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/publicclass2020/src/class049/Code03_EatGrass.java:
--------------------------------------------------------------------------------
1 | package class049;
2 |
3 | public class Code03_EatGrass {
4 |
5 | public static String whoWin(int N) {
6 | return who(N, "先手");
7 | }
8 |
9 | // int rest : 剩下多少草
10 | // String cur : "先手"、"后手" 表示,当前轮到谁
11 | // 返回:"先手"、"后手",最终谁会赢
12 | public static String who(int rest, String cur) {
13 | if (rest == 0) {
14 | return cur.equals("先手") ? "后手" : "先手";
15 | }
16 | // 接下来,rest > 0, cur 将穷尽一切努力!
17 | int pick = 1;
18 | while (pick <= rest) {
19 | if (cur.equals(who(rest - pick, cur.equals("先手") ? "后手" : "先手"))) {
20 | return cur;
21 | }
22 | pick *= 4;
23 | }
24 | return cur.equals("先手") ? "后手" : "先手";
25 | }
26 |
27 | public static String winner2(int n) {
28 | if (n % 5 == 0 || n % 5 == 2) {
29 | return "后手";
30 | } else {
31 | return "先手";
32 | }
33 | }
34 |
35 | public static void main(String[] args) {
36 | for (int i = 0; i <= 50; i++) {
37 | System.out.println(i + " : " + whoWin(i));
38 | }
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/publicclass2020/src/class053/Code01_BestTimeToBuyAndSellStock.java:
--------------------------------------------------------------------------------
1 | package class053;
2 |
3 | public class Code01_BestTimeToBuyAndSellStock {
4 |
5 | public static int maxProfit(int[] prices) {
6 | if (prices == null || prices.length == 0) {
7 | return 0;
8 | }
9 | int ans = 0;
10 | int min = prices[0];
11 | for (int i = 1; i < prices.length; i++) {
12 | min = Math.min(min, prices[i]);
13 | ans = Math.max(ans, prices[i] - min);
14 | }
15 | return ans;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/publicclass2020/src/class053/Code02_BestTimeToBuyAndSellStockII.java:
--------------------------------------------------------------------------------
1 | package class053;
2 |
3 | //leetcode 122
4 | public class Code02_BestTimeToBuyAndSellStockII {
5 |
6 | public static int maxProfit(int[] prices) {
7 | if (prices == null || prices.length == 0) {
8 | return 0;
9 | }
10 | int ans = 0;
11 | for (int i = 1; i < prices.length; i++) {
12 | ans += Math.max(prices[i] - prices[i-1], 0);
13 | }
14 | return ans;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/publicclass2020/src/class053/Code03_BestTimeToBuyAndSellStockIII.java:
--------------------------------------------------------------------------------
1 | package class053;
2 |
3 | //leetcode 123
4 | public class Code03_BestTimeToBuyAndSellStockIII {
5 |
6 | public static int maxProfit(int[] prices) {
7 | if (prices == null || prices.length < 2) {
8 | return 0;
9 | }
10 | int ans = 0;
11 | int doneOnceMinusBuyMax = -prices[0];
12 | int doneOnceMax = 0;
13 | int min = prices[0];
14 | for (int i = 1; i < prices.length; i++) {
15 | min = Math.min(min, prices[i]);
16 | ans = Math.max(ans, doneOnceMinusBuyMax + prices[i]);
17 | doneOnceMax = Math.max(doneOnceMax, prices[i] - min);
18 | doneOnceMinusBuyMax = Math.max(doneOnceMinusBuyMax, doneOnceMax - prices[i]);
19 | }
20 | return ans;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/publicclass2020/src/class053/Code04_RabbitsInForest.java:
--------------------------------------------------------------------------------
1 | package class053;
2 |
3 | import java.util.Arrays;
4 |
5 | public class Code04_RabbitsInForest {
6 |
7 | public static int numRabbits(int[] arr) {
8 | if (arr == null || arr.length == 0) {
9 | return 0;
10 | }
11 | Arrays.sort(arr);
12 | int x = arr[0];
13 | int c = 1;
14 | int ans = 0;
15 | for (int i = 1; i < arr.length; i++) {
16 | if (x != arr[i]) {
17 | ans += ((c + x) / (x + 1)) * (x + 1);
18 | x = arr[i];
19 | c = 1;
20 | } else {
21 | c++;
22 | }
23 | }
24 | return ans + ((c + x) / (x + 1)) * (x + 1);
25 | }
26 |
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/publicclass2020/src/class054/Code02_PalindromeNumber.java:
--------------------------------------------------------------------------------
1 | package class054;
2 |
3 | public class Code02_PalindromeNumber {
4 |
5 | public static boolean isPalindrome(int n) {
6 | if (n < 0) {
7 | return false;
8 | }
9 | int tmp = 1;
10 | // num = 7654567
11 | // tmp = 1000000
12 | while (n / tmp >= 10) {
13 | tmp *= 10;
14 | }
15 | while (n != 0) {
16 | if (n / tmp != n % 10) {
17 | return false;
18 | }
19 | // num = 7654567
20 | // tmp = 1000000
21 | // n%t = 654567
22 | // /10 = 65456
23 | // = 10000
24 | n = (n % tmp) / 10;
25 | tmp /= 100;
26 | }
27 | return true;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/publicclass2020/src/class054/Code04_JumpGameII.java:
--------------------------------------------------------------------------------
1 | package class054;
2 |
3 | // 测试页面:https://leetcode.com/problems/jump-game-ii/
4 | public class Code04_JumpGameII {
5 |
6 | public static int jump(int[] arr) {
7 | if (arr == null || arr.length < 2) {
8 | return 0;
9 | }
10 | // 一开始,人在0位置,一步都没有跳过
11 | int jump = 0;
12 | int cur = 0;
13 | int next = arr[0];
14 | for (int i = 1; i < arr.length; i++) {
15 | if(cur < i) {
16 | jump++;
17 | cur = next;
18 | }
19 | next = Math.max(next, i + arr[i]);
20 | }
21 | return jump;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/publicclass2020/src/class055/Code01_LongestNoRepeatSubstring.java:
--------------------------------------------------------------------------------
1 | package class055;
2 |
3 | // 链接 : https://leetcode.com/problems/longest-substring-without-repeating-characters/
4 | public class Code01_LongestNoRepeatSubstring {
5 |
6 | public static int lengthOfLongestSubstring(String s) {
7 | if (s == null || s.length() == 0) {
8 | return 0;
9 | }
10 | char[] str = s.toCharArray();
11 | int[] map = new int[256];
12 | for (int i = 0; i < 256; i++) {
13 | map[i] = -1;
14 | }
15 | map[str[0]] = 0;
16 | int pre = 1;
17 | int ans = 1;
18 | for (int i = 1; i < str.length; i++) {
19 | pre = Math.min(i - map[str[i]], pre + 1);
20 | ans = Math.max(ans, pre);
21 | map[str[i]] = i;
22 | }
23 | return ans;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/publicclass2020/src/class055/Code02_SubArrayMaxSum.java:
--------------------------------------------------------------------------------
1 | package class055;
2 |
3 | // 本题测试链接 : https://leetcode.com/problems/maximum-subarray/
4 | public class Code02_SubArrayMaxSum {
5 |
6 | public static int maxSubArray(int[] arr) {
7 | if (arr == null || arr.length == 0) {
8 | return 0;
9 | }
10 | int N = arr.length;
11 | int pre = arr[0]; // 上一步的答案
12 | int ans = pre;
13 | for (int i = 1; i < N; i++) {
14 | // 子数组必须以i位置的数结尾的情况下,最大累加和是多少
15 | // arr[i] pre + arr[i]
16 | pre = Math.max(arr[i], pre + arr[i]);
17 | ans = Math.max(ans, pre);
18 | }
19 | return ans;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/publicclass2020/src/class055/Code04_PaperFolding.java:
--------------------------------------------------------------------------------
1 | package class055;
2 |
3 | public class Code04_PaperFolding {
4 |
5 | public static void printAllFolds(int N) {
6 | process(1, N, true);
7 | System.out.println();
8 | }
9 |
10 | // 想象中的节点,在第i层
11 | // N,最多有多少层,固定参数
12 | // 想象中的节点,是凸还是凹,down = true 凹 down = false 凸
13 | public static void process(int i, int N, boolean down) {
14 | if (i > N) {
15 | return;
16 | }
17 | process(i + 1, N, true);
18 | System.out.print(down ? "凹 " : "凸 ");
19 | process(i + 1, N, false);
20 | }
21 |
22 | public static void main(String[] args) {
23 | int N = 3;
24 | printAllFolds(N);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/publicclass2020/src/class056/Code01_MissingNumber.java:
--------------------------------------------------------------------------------
1 | package class056;
2 |
3 | // 测试链接:https://leetcode.com/problems/first-missing-positive/
4 | public class Code01_MissingNumber {
5 |
6 | public static int firstMissingPositive(int[] arr) {
7 | int l = 0; // l的左边,每一个位置i,上面都放着i+1这个数
8 | // 最好预期:1~r每个数字收集全,且只收集一次
9 | // 垃圾区:r....
10 | int r = arr.length;
11 | while (l != r) {
12 | if (arr[l] == l + 1) {
13 | l++;
14 | } else if (arr[l] <= l || arr[l] > r || arr[arr[l] - 1] == arr[l]) {
15 | // [l] = 83
16 | // 83应该放在82位置
17 | // arr [ arr[l] - 1 ] = arr[l]
18 | // arr[82] = 83
19 | // 此时的arr[l]是垃圾
20 | swap(arr, l, --r);
21 | } else { // l上面的数不是l+1 l上面的数也不是垃圾
22 | swap(arr, l, arr[l] - 1);
23 | }
24 | }
25 | return l + 1;
26 | }
27 |
28 | public static void swap(int[] arr, int i, int j) {
29 | int tmp = arr[i];
30 | arr[i] = arr[j];
31 | arr[j] = tmp;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/publicclass2020/src/class056/Code02_RabbitsInForest.java:
--------------------------------------------------------------------------------
1 | package class056;
2 |
3 | import java.util.Arrays;
4 |
5 | public class Code02_RabbitsInForest {
6 |
7 | public static int numRabbits(int[] arr) {
8 | if (arr == null || arr.length == 0) {
9 | return 0;
10 | }
11 | Arrays.sort(arr);
12 | int x = arr[0];
13 | int k = 1;
14 | int ans = 0;
15 | for (int i = 1; i < arr.length; i++) {
16 | if (x != arr[i]) {
17 | // (k / (x + 1)) 上 * (x+1)
18 | // (k + x + 1 - 1) / (x + 1)
19 | // (k + x) / (x + 1) (x + 1)
20 | ans += ((k + x) / (x + 1)) * (x + 1);
21 | x = arr[i];
22 | k = 1;
23 | } else {
24 | k++;
25 | }
26 | }
27 | return ans + ((k + x) / (x + 1)) * (x + 1);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/publicclass2020/src/class059/Code05_SubarraySumEqualsK.java:
--------------------------------------------------------------------------------
1 | package class059;
2 |
3 | import java.util.HashMap;
4 |
5 | public class Code05_SubarraySumEqualsK {
6 |
7 | public static int subarraySum(int[] nums, int sum) {
8 | if (nums == null || nums.length == 0) {
9 | return 0;
10 | }
11 | // key : 某一个前缀和!
12 | // value : 这个前缀和,出现了几次!
13 | HashMap preSumTimesMap = new HashMap<>();
14 | preSumTimesMap.put(0, 1);
15 | // 每一步的整体和, 当你遍历到i位置,0~i整体的累加和!
16 | int all = 0;
17 | int ans = 0;
18 | for (int i = 0; i < nums.length; i++) {
19 | // 0...i的整体累加和了!1000 200 1000 - 200 = 800
20 | all += nums[i];
21 | if (preSumTimesMap.containsKey(all - sum)) {
22 | ans += preSumTimesMap.get(all - sum);
23 | }
24 | // 0....i 这个前缀和,一定要去!更新map!
25 | if (!preSumTimesMap.containsKey(all)) {
26 | preSumTimesMap.put(all, 1);
27 | } else {
28 | preSumTimesMap.put(all, preSumTimesMap.get(all) + 1);
29 | }
30 | }
31 | return ans;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/publicclass2020/src/class066/Code01_BestTimeToBuyAndSellStock.java:
--------------------------------------------------------------------------------
1 | package class066;
2 |
3 | // leetcode题目 : https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
4 | public class Code01_BestTimeToBuyAndSellStock {
5 |
6 | public static int maxProfit(int[] prices) {
7 | if (prices == null || prices.length == 0) {
8 | return 0;
9 | }
10 | // 最好的一笔收入,是多少
11 | int ans = 0;
12 | // 0..0 范围上的最小值
13 | int min = prices[0];
14 | // 假设每一个i,都是卖出时机!
15 | for (int i = 1; i < prices.length; i++) {
16 | // 更新min,min 0...i-1的最小值
17 | // min 0...i整体的最小值!
18 | min = Math.min(min, prices[i]);
19 | // prices[i] - min 挣得最多的钱
20 | ans = Math.max(ans, prices[i] - min);
21 | }
22 | return ans;
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/publicclass2020/src/class066/Code02_BestTimeToBuyAndSellStockII.java:
--------------------------------------------------------------------------------
1 | package class066;
2 |
3 | //leetcode题目 : https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/
4 | public class Code02_BestTimeToBuyAndSellStockII {
5 |
6 | public static int maxProfit(int[] prices) {
7 | if (prices == null || prices.length == 0) {
8 | return 0;
9 | }
10 | int ans = 0;
11 | for (int i = 1; i < prices.length; i++) {
12 | ans += Math.max(prices[i] - prices[i-1], 0);
13 | }
14 | return ans;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/publicclass2020/src/class067/Code02_KokoEatingBananas.java:
--------------------------------------------------------------------------------
1 | package class067;
2 |
3 | // 测试链接 : https://leetcode.com/problems/koko-eating-bananas/
4 | public class Code02_KokoEatingBananas {
5 |
6 | public static int minEatingSpeed(int[] piles, int h) {
7 | int L = 1;
8 | int R = 0;
9 | for (int pile : piles) {
10 | R = Math.max(R, pile);
11 | }
12 | // 只需要在L ~ R范围上,最小的达标速度
13 | // 1 ~ max
14 | int ans = 0;
15 | int M = 0;
16 | while (L <= R) {
17 | M = L + ((R - L) >> 1);
18 | if (hours(piles, M) <= h) {
19 | ans = M;
20 | R = M - 1;
21 | } else {
22 | L = M + 1;
23 | }
24 | }
25 | return ans;
26 | }
27 |
28 | // 一堆香蕉都在piles数组里
29 | // 猩猩以speed的速度吃!
30 | // 但是,这一小时吃完,就躺!
31 | // 返回一共要几小时?
32 | public static int hours(int[] piles, int speed) {
33 | int ans = 0;
34 | for (int pile : piles) {
35 | ans += (pile + speed - 1) / speed;
36 | }
37 | return ans;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/publicclass2020/src/class070/Code01_FindTheCelebrity.java:
--------------------------------------------------------------------------------
1 | package class070;
2 |
3 | // 测试链接 : https://leetcode.com/problems/find-the-celebrity/
4 | public class Code01_FindTheCelebrity {
5 |
6 | // 提交时不要提交这个函数,因为默认系统会给你这个函数
7 | // knows方法默认自己认识自己
8 | public static boolean knows(int x, int i) {
9 | return true;
10 | }
11 |
12 | // 只提交下面的方法
13 | public int findCelebrity(int n) {
14 | // 谁可能成为明星,谁就是cand
15 | int cand = 0;
16 | for (int i = 1; i < n; i++) {
17 | if (knows(cand, i)) {
18 | cand = i;
19 | }
20 | }
21 | // cand....右边,cand都不认识!
22 | // cand是什么?唯一可能是明星的人!
23 | // 下一步就是验证,它到底是不是明星
24 | // 1) cand是不是不认识所有的人 cand...(右侧cand都不认识)
25 | // 所以,只用验证 ....cand的左侧即可
26 | for (int i = 0; i < cand; i++) {
27 | if (knows(cand, i)) {
28 | return -1;
29 | }
30 | }
31 | // 2) 是不是所有的人都认识cand
32 | for (int i = 0; i < n; i++) {
33 | if (!knows(i, cand)) {
34 | return -1;
35 | }
36 | }
37 | return cand;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/publicclass2020/src/class075/Code01_BattleshipsInABoard.java:
--------------------------------------------------------------------------------
1 | package class075;
2 |
3 | // 来自米哈游
4 | // 测试链接 : https://leetcode.com/problems/battleships-in-a-board/
5 | public class Code01_BattleshipsInABoard {
6 |
7 | public static int countBattleships(char[][] m) {
8 | int ans = 0;
9 | for (int i = 0; i < m.length; i++) {
10 | for (int j = 0; j < m[0].length; j++) {
11 | if ((m[i][j] == 'X')
12 | && (i == 0 || m[i - 1][j] != 'X')
13 | && (j == 0 || m[i][j - 1] != 'X')) {
14 | ans++;
15 | }
16 | }
17 | }
18 | return ans;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/publicclass2020/src/class076/Code02_4KeysKeyboard.java:
--------------------------------------------------------------------------------
1 | package class076;
2 |
3 | // 测试链接 : https://leetcode.com/problems/4-keys-keyboard/
4 | public class Code02_4KeysKeyboard {
5 |
6 | public static int maxA(int n) {
7 | int[] dp = new int[n + 1];
8 | // dp[1] : 1
9 | // dp[2] : 2
10 | // dp[5] : 5
11 | for (int i = 1; i <= 5 && i <= n; i++) {
12 | dp[i] = i;
13 | }
14 | // i
15 | //-1 -1 -1 粘贴
16 | for (int i = 6; i <= n; i++) {
17 | dp[i] = Math.max(
18 | Math.max(dp[i - 3] * 2, dp[i - 4] * 3),
19 | Math.max(dp[i - 5] * 4, dp[i - 6] * 5));
20 | }
21 | return dp[n];
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/publicclass2020/src/class076/Code06_SplitStrings.java:
--------------------------------------------------------------------------------
1 | package class076;
2 |
3 | public class Code06_SplitStrings {
4 | // 题目6
5 | // 给定一个非常大的List list
6 | // 每一个字符串类似 : "hello,world,have,hello,world"
7 | // 这一个字符串中,有2个hello,2个world,1个have
8 | // 请设计一种多线程处理方案,统计list中每一个字符串,
9 | // 切分出来的单词数量,并且汇总
10 | // 最终返回一个HashMap表示每个字符串出现几次
11 | }
12 |
--------------------------------------------------------------------------------
/publicclass2020/src/class078/Code01_SplitSameNumberWays.java:
--------------------------------------------------------------------------------
1 | package class078;
2 |
3 | // 来自微软
4 | // 比如,str = "ayxbx"
5 | // 有以下4种切法 : a | yxbx、ay | xbx、ayx | bx、ayxb | x
6 | // 其中第1、3、4种切法符合:x和y的个数,至少在左右两块中的一块里有相同的数量
7 | // 所以返回3
8 | // 给定一个字符串str,长度为N
9 | // 你有N-1种划分方法,把str切成左右两半,返回有几种切法满足:
10 | // x和y的个数,至少在左右两块中的一块里有相同的数量
11 | public class Code01_SplitSameNumberWays {
12 |
13 | public static int splitSameNumberWays(char[] str) {
14 | if (str == null || str.length == 0) {
15 | return 0;
16 | }
17 | int xAll = 0;
18 | int yAll = 0;
19 | for (char c : str) {
20 | xAll += c == 'x' ? 1 : 0;
21 | yAll += c == 'y' ? 1 : 0;
22 | }
23 | int leftX = str[0] == 'x' ? 1 : 0;
24 | int leftY = str[0] == 'y' ? 1 : 0;
25 | int ans = 0;
26 | for (int i = 1; i < str.length; i++) {
27 | if (leftX == leftY || (xAll - leftX) == (yAll - leftY)) {
28 | ans++;
29 | }
30 | leftX += str[i] == 'x' ? 1 : 0;
31 | leftY += str[i] == 'y' ? 1 : 0;
32 | }
33 | return ans;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/publicclass2020/src/class079/Code04_LongestUncontinuousSet.java:
--------------------------------------------------------------------------------
1 | package class079;
2 |
3 | import java.util.Arrays;
4 |
5 | // 来自美团
6 | // 给定一个数组arr,你可以随意挑选其中的数字
7 | // 但是你挑选的数中,任何两个数a和b,不能让Math.abs(a - b) <= 1
8 | // 返回你最多能挑选几个数
9 | public class Code04_LongestUncontinuousSet {
10 |
11 | public static int longestUncontinuous(int[] arr) {
12 | if (arr == null || arr.length == 0) {
13 | return 0;
14 | }
15 | Arrays.sort(arr);
16 | int n = arr.length;
17 | int size = 1;
18 | for (int i = 1; i < n; i++) {
19 | if (arr[i] != arr[size - 1]) {
20 | arr[size++] = arr[i];
21 | }
22 | }
23 | int[] dp = new int[size];
24 | dp[0] = 1;
25 | int ans = 1;
26 | for (int i = 1; i < size; i++) {
27 | dp[i] = 1;
28 | if (arr[i] - arr[i - 1] > 1) {
29 | dp[i] = 1 + dp[i - 1];
30 | }
31 | if (i - 2 >= 0 && arr[i] - arr[i - 2] > 1) {
32 | dp[i] = Math.max(dp[i], 1 + dp[i - 2]);
33 | }
34 | ans = Math.max(ans, dp[i]);
35 | }
36 | return ans;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/publicclass2020/src/class086/Code03_BattleshipsInABoard.java:
--------------------------------------------------------------------------------
1 | package class086;
2 |
3 | // 来自米哈游
4 | // 测试链接 : https://leetcode.com/problems/battleships-in-a-board/
5 | public class Code03_BattleshipsInABoard {
6 |
7 | public static int countBattleships(char[][] m) {
8 | int ans = 0;
9 | for (int i = 0; i < m.length; i++) {
10 | for (int j = 0; j < m[0].length; j++) {
11 | if ((m[i][j] == 'X')
12 | && (i == 0 || m[i - 1][j] != 'X')
13 | && (j == 0 || m[i][j - 1] != 'X')) {
14 | ans++;
15 | }
16 | }
17 | }
18 | return ans;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/publicclass2020/src/class099/Code03_CorporateFlightBookings.java:
--------------------------------------------------------------------------------
1 | package class099;
2 |
3 | // 这里有 n 个航班,它们分别从 1 到 n 进行编号。
4 | // 有一份航班预订表 bookings ,
5 | // 表中第 i 条预订记录 bookings[i] = [firsti, lasti, seatsi]
6 | // 意味着在从 firsti 到 lasti
7 | //(包含 firsti 和 lasti )的 每个航班 上预订了 seatsi 个座位。
8 | // 请你返回一个长度为 n 的数组 answer,里面的元素是每个航班预定的座位总数。
9 | // 测试链接 : https://leetcode.cn/problems/corporate-flight-bookings/
10 | public class Code03_CorporateFlightBookings {
11 |
12 | public static int[] corpFlightBookings(int[][] bookings, int n) {
13 | // 1 2 3 4 n
14 | // 0 1 2 3 .. n n+1
15 | int[] cnt = new int[n + 2];
16 | for (int[] book : bookings) {
17 | // start book[0]
18 | // end book[1]
19 | // 票 book[2]
20 | cnt[book[0]] += book[2];
21 | cnt[book[1] + 1] -= book[2];
22 | }
23 | for (int i = 1; i < cnt.length; i++) {
24 | cnt[i] += cnt[i - 1];
25 | }
26 | int[] ans = new int[n];
27 | for (int i = 0; i < n; i++) {
28 | ans[i] = cnt[i + 1];
29 | }
30 | return ans;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/publicclass2020/src/class114/Code01_KthMissingPositiveNumber.java:
--------------------------------------------------------------------------------
1 | package class114;
2 |
3 | // 给你一个 严格升序排列 的正整数数组 arr 和一个整数 k 。
4 | // 请你找到这个数组里第 k 个缺失的正整数。
5 | // 测试链接 : https://leetcode.cn/problems/kth-missing-positive-number/
6 | public class Code01_KthMissingPositiveNumber {
7 |
8 | public int findKthPositive(int[] arr, int k) {
9 | int l = 0;
10 | int r = arr.length - 1;
11 | int m = 0;
12 | int find = arr.length;
13 | while (l <= r) {
14 | m = (l + r) / 2;
15 | if (arr[m] - (m + 1) >= k) {
16 | find = m;
17 | r = m - 1;
18 | } else {
19 | l = m + 1;
20 | }
21 | }
22 | int preValue = find == 0 ? 0 : arr[find - 1];
23 | int under = preValue - find;
24 | return preValue + (k - under);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/publicclass2020/src/class115/Code02_SumOfSubSequenceWidths.java:
--------------------------------------------------------------------------------
1 | package class115;
2 |
3 | import java.util.Arrays;
4 |
5 | // 一个序列的 宽度 定义为该序列中最大元素和最小元素的差值。
6 | // 给你一个整数数组 nums ,返回 nums 的所有非空 子序列 的 宽度之和
7 | // 由于答案可能非常大,请返回对 109 + 7 取余 后的结果。
8 | // 子序列 定义为从一个数组里删除一些(或者不删除)元素,
9 | // 但不改变剩下元素的顺序得到的数组
10 | // 例如,[3,6,2,7] 就是数组 [0,3,1,6,2,2,7] 的一个子序列。
11 | // 测试链接 : https://leetcode.cn/problems/sum-of-subsequence-widths/
12 | public class Code02_SumOfSubSequenceWidths {
13 |
14 | public static int sumSubseqWidths(int[] nums) {
15 | Arrays.sort(nums);
16 | int mod = 1000000007;
17 | long ans = 0;
18 | long A = 0;
19 | long B = 0;
20 | long C = 1;
21 | long D = C;
22 | for (int i = 1; i < nums.length; i++) {
23 | A = (D * nums[i]) % mod;
24 | B = (B * 2 + nums[i - 1]) % mod;
25 | ans = (ans + A - B + mod) % mod;
26 | C = (C * 2) % mod;
27 | D = (D + C) % mod;
28 | }
29 | return (int) (ans);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/publicclass2020/src/class117/Code08_MaximumProductSubarray.java:
--------------------------------------------------------------------------------
1 | package class117;
2 |
3 | // 测试链接:https://leetcode.cn/problems/maximum-product-subarray/
4 | public class Code08_MaximumProductSubarray {
5 |
6 | public static int maxProduct(int[] nums) {
7 | int ans = nums[0];
8 | int min = nums[0];
9 | int max = nums[0];
10 | for (int i = 1; i < nums.length; i++) {
11 | int curmin = Math.min(nums[i], Math.min(min * nums[i], max * nums[i]));
12 | int curmax = Math.max(nums[i], Math.max(min * nums[i], max * nums[i]));
13 | min = curmin;
14 | max = curmax;
15 | ans = Math.max(ans, max);
16 | }
17 | return ans;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/publicclass2020/src/class117/Code09_RotateImage.java:
--------------------------------------------------------------------------------
1 | package class117;
2 |
3 | // 测试链接 : https://leetcode.cn/problems/rotate-image/
4 | public class Code09_RotateImage {
5 |
6 | public static void rotate(int[][] matrix) {
7 | // matrix.length == matrix[0].length
8 | int a = 0;
9 | int b = 0;
10 | int c = matrix.length - 1;
11 | int d = matrix[0].length - 1;
12 | while (a < c) {
13 | rotateEdge(matrix, a++, b++, c--, d--);
14 | }
15 | }
16 |
17 | public static void rotateEdge(int[][] m, int a, int b, int c, int d) {
18 | int tmp = 0;
19 | for (int i = 0; i < d - b; i++) {
20 | tmp = m[a][b + i];
21 | m[a][b + i] = m[c - i][b];
22 | m[c - i][b] = m[c][d - i];
23 | m[c][d - i] = m[a + i][d];
24 | m[a + i][d] = tmp;
25 | }
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp001-master.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/trainingcamp源码/trainingcamp001-master.zip
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp001-master/trainingcamp001-master.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp002-master.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/trainingcamp源码/trainingcamp002-master.zip
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp002-master/src/class01/Code03_MSumToN.java:
--------------------------------------------------------------------------------
1 | package class01;
2 |
3 | public class Code03_MSumToN {
4 |
5 | public static boolean isMSum1(int num) {
6 | for (int i = 1; i <= num; i++) {
7 | int sum = i;
8 | for (int j = i + 1; j <= num; j++) {
9 | if (sum + j > num) {
10 | break;
11 | }
12 | if (sum + j == num) {
13 | return true;
14 | }
15 | sum += j;
16 | }
17 | }
18 | return false;
19 | }
20 |
21 | public static boolean isMSum2(int num) {
22 | if (num < 3) {
23 | return false;
24 | }
25 | return (num & (num - 1)) != 0;
26 | }
27 |
28 | public static void main(String[] args) {
29 | for (int num = 1; num < 200; num++) {
30 | System.out.println(num + " : " + isMSum1(num));
31 | }
32 | System.out.println("test begin");
33 | for (int num = 1; num < 5000; num++) {
34 | if (isMSum1(num) != isMSum2(num)) {
35 | System.out.println("Oops!");
36 | }
37 | }
38 | System.out.println("test end");
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp002-master/trainingcamp002-master.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp003-master.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/trainingcamp源码/trainingcamp003-master.zip
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp003-master/src/class01/Code02_NeedParentheses.java:
--------------------------------------------------------------------------------
1 | package class01;
2 |
3 | public class Code02_NeedParentheses {
4 |
5 | public static boolean valid(String s) {
6 | char[] str = s.toCharArray();
7 | int count = 0;
8 | for (int i = 0; i < str.length; i++) {
9 | count += str[i] == '(' ? 1 : -1;
10 | if (count < 0) {
11 | return false;
12 | }
13 | }
14 | return count == 0;
15 | }
16 |
17 | public static int needParentheses(String s) {
18 | char[] str = s.toCharArray();
19 | int count = 0;
20 | int need = 0;
21 | for (int i = 0; i < str.length; i++) {
22 | if (str[i] == '(') {
23 | count++;
24 | } else { // 遇到的是')'
25 | if (count == 0) {
26 | need++;
27 | } else {
28 | count--;
29 | }
30 | }
31 | }
32 | return count + need;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp003-master/src/class01/Code04_ColorLeftRight.java:
--------------------------------------------------------------------------------
1 | package class01;
2 |
3 | public class Code04_ColorLeftRight {
4 |
5 | // RGRGR -> RRRGG
6 | public static int minPaint(String s) {
7 | if (s == null || s.length() < 2) {
8 | return 0;
9 | }
10 | char[] str = s.toCharArray();
11 | int N = str.length;
12 | int rAll = 0;
13 | for (int i = 0; i < N; i++) {
14 | rAll += str[i] == 'R' ? 1 : 0;
15 | }
16 | int ans = rAll; // 如果数组所有的范围,都是右侧范围,都变成G
17 | int left = 0;
18 | for (int i = 0; i < N - 1; i++) { // 0..i 左侧 n-1..N-1
19 | left += str[i] == 'G' ? 1 : 0;
20 | rAll -= str[i] == 'R' ? 1 : 0;
21 | ans = Math.min(ans, left + rAll);
22 | }
23 | // 0...N-1 左全部 右无
24 | ans = Math.min(ans, left + (str[N - 1] == 'G' ? 1 : 0));
25 | return ans;
26 | }
27 |
28 | public static void main(String[] args) {
29 | String test = "GGGGGR";
30 | System.out.println(minPaint(test));
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp003-master/src/class04/Code06_SubArrayMaxSum.java:
--------------------------------------------------------------------------------
1 | package class04;
2 |
3 | public class Code06_SubArrayMaxSum {
4 |
5 | public static int maxSum(int[] arr) {
6 | if (arr == null || arr.length == 0) {
7 | return 0;
8 | }
9 | int max = Integer.MIN_VALUE;
10 | int cur = 0;
11 | for (int i = 0; i < arr.length; i++) {
12 | cur += arr[i];
13 | max = Math.max(max, cur);
14 | cur = cur < 0 ? 0 : cur;
15 | }
16 | return max;
17 | }
18 |
19 | public static void printArray(int[] arr) {
20 | for (int i = 0; i != arr.length; i++) {
21 | System.out.print(arr[i] + " ");
22 | }
23 | System.out.println();
24 | }
25 |
26 | public static void main(String[] args) {
27 | int[] arr1 = { -2, -3, -5, 40, -10, -10, 100, 1 };
28 | System.out.println(maxSum(arr1));
29 |
30 | int[] arr2 = { -2, -3, -5, 0, 1, 2, -1 };
31 | System.out.println(maxSum(arr2));
32 |
33 | int[] arr3 = { -2, -3, -5, -1 };
34 | System.out.println(maxSum(arr3));
35 |
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp003-master/src/class04/Code07_SubMatrixMaxSum.java:
--------------------------------------------------------------------------------
1 | package class04;
2 |
3 | public class Code07_SubMatrixMaxSum {
4 |
5 | public static int maxSum(int[][] m) {
6 | if (m == null || m.length == 0 || m[0].length == 0) {
7 | return 0;
8 | }
9 | int max = Integer.MIN_VALUE;
10 | int cur = 0;
11 | int[] s = null;
12 | for (int i = 0; i != m.length; i++) { // 开始的行号i
13 | s = new int[m[0].length]; //
14 | for (int j = i; j != m.length; j++) { // 结束的行号j,i~j行是我讨论的范围
15 | cur = 0;
16 | for (int k = 0; k != s.length; k++) {
17 | s[k] += m[j][k];
18 | cur += s[k];
19 | max = Math.max(max, cur);
20 | cur = cur < 0 ? 0 : cur;
21 | }
22 | }
23 | }
24 | return max;
25 | }
26 |
27 | public static void main(String[] args) {
28 | int[][] matrix = { { -90, 48, 78 }, { 64, -40, 64 }, { -81, -7, 66 } };
29 | System.out.println(maxSum(matrix));
30 |
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp003-master/src/class06/Code03_JumpGame.java:
--------------------------------------------------------------------------------
1 | package class06;
2 |
3 | public class Code03_JumpGame {
4 |
5 | public static int jump(int[] arr) {
6 | if (arr == null || arr.length == 0) {
7 | return 0;
8 | }
9 | int step = 0; // 跳了多少步
10 | int cur = 0; // step步内,右边界
11 | int next = 0;// step+1步内,右边界
12 | for (int i = 0; i < arr.length; i++) {
13 | if (cur < i) {
14 | step++;
15 | cur = next;
16 | }
17 | next = Math.max(next, i + arr[i]);
18 | }
19 | return step;
20 | }
21 |
22 | public static void main(String[] args) {
23 | int[] arr = { 3, 2, 3, 1, 1, 4 };
24 | System.out.println(jump(arr));
25 |
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp003-master/src/class07/Code01_MinLengthForSort.java:
--------------------------------------------------------------------------------
1 | package class07;
2 |
3 | public class Code01_MinLengthForSort {
4 |
5 | public static int getMinLength(int[] arr) {
6 | if (arr == null || arr.length < 2) {
7 | return 0;
8 | }
9 | int min = arr[arr.length - 1];
10 | int noMinIndex = -1;
11 | for (int i = arr.length - 2; i != -1; i--) {
12 | if (arr[i] > min) {
13 | noMinIndex = i;
14 | } else {
15 | min = Math.min(min, arr[i]);
16 | }
17 | }
18 | if (noMinIndex == -1) {
19 | return 0;
20 | }
21 | int max = arr[0];
22 | int noMaxIndex = -1;
23 | for (int i = 1; i != arr.length; i++) {
24 | if (arr[i] < max) {
25 | noMaxIndex = i;
26 | } else {
27 | max = Math.max(max, arr[i]);
28 | }
29 | }
30 | return noMaxIndex - noMinIndex + 1;
31 | }
32 |
33 | public static void main(String[] args) {
34 | int[] arr = { 1, 2, 4, 7, 10, 11, 7, 12, 6, 7, 16, 18, 19 };
35 | System.out.println(getMinLength(arr));
36 |
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp003-master/trainingcamp003-master.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp004-master.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/trainingcamp源码/trainingcamp004-master.zip
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp004-master/src/class01/Code02_MaxSubArraySumLessOrEqualK.java:
--------------------------------------------------------------------------------
1 | package class01;
2 |
3 | import java.util.TreeSet;
4 |
5 | public class Code02_MaxSubArraySumLessOrEqualK {
6 |
7 | // 请返回arr中,求个子数组的累加和,是<=K的,并且是最大的。
8 | // 返回这个最大的累加和
9 | public static int getMaxLessOrEqualK(int[] arr, int K) {
10 | // 记录i之前的,前缀和,按照有序表组织
11 | TreeSet set = new TreeSet();
12 | // 一个数也没有的时候,就已经有一个前缀和是0了
13 | set.add(0);
14 |
15 | int max = Integer.MIN_VALUE;
16 | int sum = 0;
17 | // 每一步的i,都求子数组必须以i结尾的情况下,求个子数组的累加和,是<=K的,并且是最大的
18 | for (int i = 0; i < arr.length; i++) {
19 | sum += arr[i]; // sum -> arr[0..i];
20 | if (set.ceiling(sum - K) != null) {
21 | max = Math.max(max, sum - set.ceiling(sum - K));
22 | }
23 | set.add(sum); // 当前的前缀和加入到set中去
24 | }
25 | return max;
26 |
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp004-master/src/class02/Code01_BestTimetoBuyandSellStock1.java:
--------------------------------------------------------------------------------
1 | package class02;
2 |
3 | public class Code01_BestTimetoBuyandSellStock1 {
4 |
5 | public int maxProfit(int[] prices) {
6 | if (prices == null || prices.length == 0) {
7 | return 0;
8 | }
9 | int min = prices[0];
10 | int ans = 0;
11 | for (int i = 0; i < prices.length; i++) {
12 | min = Math.min(min, prices[i]);
13 | ans = Math.max(ans, prices[i] - min);
14 | }
15 | return ans;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp004-master/src/class02/Code02_BestTimetoBuyandSellStock2.java:
--------------------------------------------------------------------------------
1 | package class02;
2 |
3 | public class Code02_BestTimetoBuyandSellStock2 {
4 |
5 | public static int maxProfit(int[] prices) {
6 | if (prices == null || prices.length == 0) {
7 | return 0;
8 | }
9 | int ans = 0;
10 | for (int i = 1; i < prices.length; i++) {
11 | ans += Math.max(prices[i] - prices[i-1], 0);
12 | }
13 | return ans;
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp004-master/src/class04/Code03_Nim.java:
--------------------------------------------------------------------------------
1 | package class04;
2 |
3 | public class Code03_Nim {
4 |
5 | // 保证arr是正数数组
6 | public static void printWinner(int[] arr) {
7 | int eor = 0;
8 | for (int num : arr) {
9 | eor ^= num;
10 | }
11 | if (eor == 0) {
12 | System.out.println("后手赢");
13 | } else {
14 | System.out.println("先手赢");
15 | }
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp004-master/trainingcamp004-master.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp005-master.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/trainingcamp源码/trainingcamp005-master.zip
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp005-master/src/class06/Code02_StrangePrinter.java:
--------------------------------------------------------------------------------
1 | package class06;
2 |
3 | public class Code02_StrangePrinter {
4 |
5 | public static int strangePrinter(String s) {
6 | if (s == null || s.length() == 0) {
7 | return 0;
8 | }
9 | char[] str = s.toCharArray();
10 | int N = str.length;
11 | int[][] dp = new int[N][N];
12 | dp[N - 1][N - 1] = 1;
13 | for (int i = 0; i < N - 1; i++) {
14 | dp[i][i] = 1;
15 | dp[i][i + 1] = str[i] == str[i + 1] ? 1 : 2;
16 | }
17 | for (int L = N - 3; L >= 0; L--) {
18 | for (int R = L + 2; R < N; R++) {
19 |
20 | // L....R
21 |
22 | dp[L][R] = R - L + 1;
23 |
24 | // L...k-1 k...R
25 | for (int k = L + 1; k <= R; k++) {
26 | dp[L][R] = Math.min(dp[L][R], dp[L][k - 1] + dp[k][R] - (str[L] == str[k] ? 1 : 0));
27 | }
28 | }
29 | }
30 | return dp[0][N - 1];
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp005-master/src/class08/DC3_Algorithm.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/trainingcamp源码/trainingcamp005-master/src/class08/DC3_Algorithm.pdf
--------------------------------------------------------------------------------
/trainingcamp源码/trainingcamp005-master/trainingcamp005-master.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/全部算法课讲解知识点提纲、题目汇总、PPT合集、学前必读、学习规划/class-notes/算法和数据结构知识梳理.xmind:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/全部算法课讲解知识点提纲、题目汇总、PPT合集、学前必读、学习规划/class-notes/算法和数据结构知识梳理.xmind
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class01/Code02_CountFiles.java:
--------------------------------------------------------------------------------
1 | package class01;
2 |
3 | import java.io.File;
4 | import java.util.Stack;
5 |
6 | public class Code02_CountFiles {
7 |
8 | // 注意这个函数也会统计隐藏文件
9 | public static int getFileNumber(String folderPath) {
10 | File root = new File(folderPath);
11 | if (!root.isDirectory() && !root.isFile()) {
12 | return 0;
13 | }
14 | if (root.isFile()) {
15 | return 1;
16 | }
17 | Stack stack = new Stack<>();
18 | stack.add(root);
19 | int files = 0;
20 | while (!stack.isEmpty()) {
21 | File folder = stack.pop();
22 | for (File next : folder.listFiles()) {
23 | if (next.isFile()) {
24 | files++;
25 | }
26 | if (next.isDirectory()) {
27 | stack.push(next);
28 | }
29 | }
30 | }
31 | return files;
32 | }
33 |
34 | public static void main(String[] args) {
35 | // 你可以自己更改目录
36 | String path = "/Users/zuochengyun/Desktop/";
37 | System.out.println(getFileNumber(path));
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class01/Code03_Near2Power.java:
--------------------------------------------------------------------------------
1 | package class01;
2 |
3 | public class Code03_Near2Power {
4 |
5 | // 已知n是正数
6 | // 返回大于等于,且最接近n的,2的某次方的值
7 | public static final int tableSizeFor(int n) {
8 | n--;
9 | n |= n >>> 1;
10 | n |= n >>> 2;
11 | n |= n >>> 4;
12 | n |= n >>> 8;
13 | n |= n >>> 16;
14 | return (n < 0) ? 1 : n + 1;
15 | }
16 |
17 | public static void main(String[] args) {
18 | int cap = 120;
19 | System.out.println(tableSizeFor(cap));
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class02/Code06_MinLengthForSort.java:
--------------------------------------------------------------------------------
1 | package class02;
2 |
3 | // 本题测试链接 : https://leetcode.com/problems/shortest-unsorted-continuous-subarray/
4 | public class Code06_MinLengthForSort {
5 |
6 | public static int findUnsortedSubarray(int[] nums) {
7 | if (nums == null || nums.length < 2) {
8 | return 0;
9 | }
10 | int N = nums.length;
11 | int right = -1;
12 | int max = Integer.MIN_VALUE;
13 | for (int i = 0; i < N; i++) {
14 | if (max > nums[i]) {
15 | right = i;
16 | }
17 | max = Math.max(max, nums[i]);
18 | }
19 | int min = Integer.MAX_VALUE;
20 | int left = N;
21 | for (int i = N - 1; i >= 0; i--) {
22 | if (min < nums[i]) {
23 | left = i;
24 | }
25 | min = Math.min(min, nums[i]);
26 | }
27 | return Math.max(0, right - left + 1);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class03/Code01_LongestSubstringWithoutRepeatingCharacters.java:
--------------------------------------------------------------------------------
1 | package class03;
2 |
3 | // 本题测试链接 : https://leetcode.com/problems/longest-substring-without-repeating-characters/
4 | public class Code01_LongestSubstringWithoutRepeatingCharacters {
5 |
6 | public static int lengthOfLongestSubstring(String s) {
7 | if (s == null || s.equals("")) {
8 | return 0;
9 | }
10 | char[] str = s.toCharArray();
11 | int[] map = new int[256];
12 | for (int i = 0; i < 256; i++) {
13 | map[i] = -1;
14 | }
15 | map[str[0]] = 0;
16 | int N = str.length;
17 | int ans = 1;
18 | int pre = 1;
19 | for (int i = 1; i < N; i++) {
20 | pre = Math.min(i - map[str[i]], pre + 1);
21 | ans = Math.max(ans, pre);
22 | map[str[i]] = i;
23 | }
24 | return ans;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class04/Code02_SubArrayMaxSum.java:
--------------------------------------------------------------------------------
1 | package class04;
2 |
3 | // 本题测试链接 : https://leetcode.com/problems/maximum-subarray/
4 | public class Code02_SubArrayMaxSum {
5 |
6 | public static int maxSubArray(int[] arr) {
7 | if (arr == null || arr.length == 0) {
8 | return 0;
9 | }
10 | int max = Integer.MIN_VALUE;
11 | int cur = 0;
12 | for (int i = 0; i < arr.length; i++) {
13 | cur += arr[i];
14 | max = Math.max(max, cur);
15 | cur = cur < 0 ? 0 : cur;
16 | }
17 | return max;
18 | }
19 |
20 | public static int maxSubArray2(int[] arr) {
21 | if (arr == null || arr.length == 0) {
22 | return 0;
23 | }
24 | // 上一步,dp的值
25 | // dp[0]
26 | int pre = arr[0];
27 | int max = arr[0];
28 | for (int i = 1; i < arr.length; i++) {
29 | pre = Math.max(arr[i], arr[i] + pre);
30 | max = Math.max(max, pre);
31 | }
32 | return max;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class06/Code05_Nim.java:
--------------------------------------------------------------------------------
1 | package class06;
2 |
3 | public class Code05_Nim {
4 |
5 | // 保证arr是正数数组
6 | public static void printWinner(int[] arr) {
7 | int eor = 0;
8 | for (int num : arr) {
9 | eor ^= num;
10 | }
11 | if (eor == 0) {
12 | System.out.println("后手赢");
13 | } else {
14 | System.out.println("先手赢");
15 | }
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class08/Code02_ContainerWithMostWater.java:
--------------------------------------------------------------------------------
1 | package class08;
2 |
3 | // 本题测试链接 : https://leetcode.com/problems/container-with-most-water/
4 | public class Code02_ContainerWithMostWater {
5 |
6 | public static int maxArea1(int[] h) {
7 | int max = 0;
8 | int N = h.length;
9 | for (int i = 0; i < N; i++) { // h[i]
10 | for (int j = i + 1; j < N; j++) { // h[j]
11 | max = Math.max(max, Math.min(h[i], h[j]) * (j - i));
12 | }
13 | }
14 | return max;
15 | }
16 |
17 | public static int maxArea2(int[] h) {
18 | int max = 0;
19 | int l = 0;
20 | int r = h.length - 1;
21 | while (l < r) {
22 | max = Math.max(max, Math.min(h[l], h[r]) * (r - l));
23 | if (h[l] > h[r]) {
24 | r--;
25 | } else {
26 | l++;
27 | }
28 | }
29 | return max;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class10/Code01_JumpGame.java:
--------------------------------------------------------------------------------
1 | package class10;
2 |
3 | // 本题测试链接 : https://leetcode.com/problems/jump-game-ii/
4 | public class Code01_JumpGame {
5 |
6 | public static int jump(int[] arr) {
7 | if (arr == null || arr.length == 0) {
8 | return 0;
9 | }
10 | int step = 0;
11 | int cur = 0;
12 | int next = 0;
13 | for (int i = 0; i < arr.length; i++) {
14 | if (cur < i) {
15 | step++;
16 | cur = next;
17 | }
18 | next = Math.max(next, i + arr[i]);
19 | }
20 | return step;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class14/Code02_MaxSubArraySumLessOrEqualK.java:
--------------------------------------------------------------------------------
1 | package class14;
2 |
3 | import java.util.TreeSet;
4 |
5 | public class Code02_MaxSubArraySumLessOrEqualK {
6 |
7 | // 请返回arr中,求个子数组的累加和,是<=K的,并且是最大的。
8 | // 返回这个最大的累加和
9 | public static int getMaxLessOrEqualK(int[] arr, int K) {
10 | // 记录i之前的,前缀和,按照有序表组织
11 | TreeSet set = new TreeSet();
12 | // 一个数也没有的时候,就已经有一个前缀和是0了
13 | set.add(0);
14 | int max = Integer.MIN_VALUE;
15 | int sum = 0;
16 | // 每一步的i,都求子数组必须以i结尾的情况下,求个子数组的累加和,是<=K的,并且是最大的
17 | for (int i = 0; i < arr.length; i++) {
18 | sum += arr[i]; // sum -> arr[0..i];
19 | if (set.ceiling(sum - K) != null) {
20 | max = Math.max(max, sum - set.ceiling(sum - K));
21 | }
22 | set.add(sum); // 当前的前缀和加入到set中去
23 | }
24 | return max;
25 |
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class14/Code06_MissingNumber.java:
--------------------------------------------------------------------------------
1 | package class14;
2 |
3 | // 测试链接:https://leetcode.com/problems/first-missing-positive/
4 | public class Code06_MissingNumber {
5 |
6 | public static int firstMissingPositive(int[] arr) {
7 | // l是盯着的位置
8 | // 0 ~ L-1有效区
9 | int L = 0;
10 | int R = arr.length;
11 | while (L != R) {
12 | if (arr[L] == L + 1) {
13 | L++;
14 | } else if (arr[L] <= L || arr[L] > R || arr[arr[L] - 1] == arr[L]) { // 垃圾的情况
15 | swap(arr, L, --R);
16 | } else {
17 | swap(arr, L, arr[L] - 1);
18 | }
19 | }
20 | return L + 1;
21 | }
22 |
23 | public static void swap(int[] arr, int i, int j) {
24 | int tmp = arr[i];
25 | arr[i] = arr[j];
26 | arr[j] = tmp;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class15/Code01_BestTimeToBuyAndSellStock.java:
--------------------------------------------------------------------------------
1 | package class15;
2 |
3 | // leetcode 121
4 | public class Code01_BestTimeToBuyAndSellStock {
5 |
6 | public static int maxProfit(int[] prices) {
7 | if (prices == null || prices.length == 0) {
8 | return 0;
9 | }
10 | // 必须在0时刻卖掉,[0] - [0]
11 | int ans = 0;
12 | // arr[0...0]
13 | int min = prices[0];
14 | for (int i = 1; i < prices.length; i++) {
15 | min = Math.min(min, prices[i]);
16 | ans = Math.max(ans, prices[i] - min);
17 | }
18 | return ans;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class15/Code02_BestTimeToBuyAndSellStockII.java:
--------------------------------------------------------------------------------
1 | package class15;
2 |
3 | //leetcode 122
4 | public class Code02_BestTimeToBuyAndSellStockII {
5 |
6 | public static int maxProfit(int[] prices) {
7 | if (prices == null || prices.length == 0) {
8 | return 0;
9 | }
10 | int ans = 0;
11 | for (int i = 1; i < prices.length; i++) {
12 | ans += Math.max(prices[i] - prices[i-1], 0);
13 | }
14 | return ans;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class15/Code03_BestTimeToBuyAndSellStockIII.java:
--------------------------------------------------------------------------------
1 | package class15;
2 |
3 | //leetcode 123
4 | public class Code03_BestTimeToBuyAndSellStockIII {
5 |
6 | public static int maxProfit(int[] prices) {
7 | if (prices == null || prices.length < 2) {
8 | return 0;
9 | }
10 | int ans = 0;
11 | int doneOnceMinusBuyMax = -prices[0];
12 | int doneOnceMax = 0;
13 | int min = prices[0];
14 | for (int i = 1; i < prices.length; i++) {
15 | min = Math.min(min, prices[i]);
16 | ans = Math.max(ans, doneOnceMinusBuyMax + prices[i]);
17 | doneOnceMax = Math.max(doneOnceMax, prices[i] - min);
18 | doneOnceMinusBuyMax = Math.max(doneOnceMinusBuyMax, doneOnceMax - prices[i]);
19 | }
20 | return ans;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class15/Code06_BestTimeToBuyAndSellStockWithTransactionFee.java:
--------------------------------------------------------------------------------
1 | package class15;
2 |
3 | //leetcode 714
4 | public class Code06_BestTimeToBuyAndSellStockWithTransactionFee {
5 |
6 | public static int maxProfit(int[] arr, int fee) {
7 | if (arr == null || arr.length < 2) {
8 | return 0;
9 | }
10 | int N = arr.length;
11 | // 0..0 0 -[0] - fee
12 | int bestbuy = -arr[0] - fee;
13 | // 0..0 卖 0
14 | int bestsell = 0;
15 | for (int i = 1; i < N; i++) {
16 | // 来到i位置了!
17 | // 如果在i必须买 收入 - 批发价 - fee
18 | int curbuy = bestsell - arr[i] - fee;
19 | // 如果在i必须卖 整体最优(收入 - 良好批发价 - fee)
20 | int cursell = bestbuy + arr[i];
21 | bestbuy = Math.max(bestbuy, curbuy);
22 | bestsell = Math.max(bestsell, cursell);
23 | }
24 | return bestsell;
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class22/Code02_TrappingRainWater.java:
--------------------------------------------------------------------------------
1 | package class22;
2 |
3 | // 本题测试链接 : https://leetcode.com/problems/trapping-rain-water/
4 | public class Code02_TrappingRainWater {
5 |
6 | public static int trap(int[] arr) {
7 | if (arr == null || arr.length < 2) {
8 | return 0;
9 | }
10 | int N = arr.length;
11 | int L = 1;
12 | int leftMax = arr[0];
13 | int R = N - 2;
14 | int rightMax = arr[N - 1];
15 | int water = 0;
16 | while (L <= R) {
17 | if (leftMax <= rightMax) {
18 | water += Math.max(0, leftMax - arr[L]);
19 | leftMax = Math.max(leftMax, arr[L++]);
20 | } else {
21 | water += Math.max(0, rightMax - arr[R]);
22 | rightMax = Math.max(rightMax, arr[R--]);
23 | }
24 | }
25 | return water;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class27/Problem_0001_TwoSum.java:
--------------------------------------------------------------------------------
1 | package class27;
2 |
3 | import java.util.HashMap;
4 |
5 | public class Problem_0001_TwoSum {
6 |
7 | public static int[] twoSum(int[] nums, int target) {
8 | // key 某个之前的数 value 这个数出现的位置
9 | HashMap map = new HashMap<>();
10 | for (int i = 0; i < nums.length; i++) {
11 | if (map.containsKey(target - nums[i])) {
12 | return new int[] { map.get(target - nums[i]), i };
13 | }
14 | map.put(nums[i], i);
15 | }
16 | return new int[] { -1, -1 };
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class27/Problem_0007_ReverseInteger.java:
--------------------------------------------------------------------------------
1 | package class27;
2 |
3 | public class Problem_0007_ReverseInteger {
4 |
5 | public static int reverse(int x) {
6 | boolean neg = ((x >>> 31) & 1) == 1;
7 | x = neg ? x : -x;
8 | int m = Integer.MIN_VALUE / 10;
9 | int o = Integer.MIN_VALUE % 10;
10 | int res = 0;
11 | while (x != 0) {
12 | if (res < m || (res == m && x % 10 < o)) {
13 | return 0;
14 | }
15 | res = res * 10 + x % 10;
16 | x /= 10;
17 | }
18 | return neg ? res : Math.abs(res);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class27/说明:
--------------------------------------------------------------------------------
1 | leetcode高频题
2 | leetcode全题目列表 : https://leetcode.com/problemset/all/
3 | 在全题目列表的右侧栏,点击Top Interview Questions
4 | 或者直接进入右侧链接 : https://leetcode.com/problemset/all/?listId=wpwgkgt
5 | 即可看到leetcode高频题全列表
6 | 本节课解决leetcode高频题列表中的如下题目 :
7 | 0001 : 大厂刷题班, 第27节, 本节
8 | 0002 : 算法新手班, 第4节第5题
9 | 0003 : 大厂刷题班, 第3节第1题
10 | 0004 : 大厂刷题班, 第12节第3题
11 | 0005 : 体系学习班, Manacher算法
12 | 0007 : 大厂刷题班, 第27节, 本节
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class28/Problem_0012_IntegerToRoman.java:
--------------------------------------------------------------------------------
1 | package class28;
2 |
3 | public class Problem_0012_IntegerToRoman {
4 |
5 | public static String intToRoman(int num) {
6 | String[][] c = {
7 | { "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" },
8 | { "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" },
9 | { "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" },
10 | { "", "M", "MM", "MMM" } };
11 | StringBuilder roman = new StringBuilder();
12 | roman
13 | .append(c[3][num / 1000 % 10])
14 | .append(c[2][num / 100 % 10])
15 | .append(c[1][num / 10 % 10])
16 | .append(c[0][num % 10]);
17 | return roman.toString();
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class28/Problem_0014_LongestCommonPrefix.java:
--------------------------------------------------------------------------------
1 | package class28;
2 |
3 | public class Problem_0014_LongestCommonPrefix {
4 |
5 | public static String longestCommonPrefix(String[] strs) {
6 | if (strs == null || strs.length == 0) {
7 | return "";
8 | }
9 | char[] chs = strs[0].toCharArray();
10 | int min = Integer.MAX_VALUE;
11 | for (String str : strs) {
12 | char[] tmp = str.toCharArray();
13 | int index = 0;
14 | while (index < tmp.length && index < chs.length) {
15 | if (chs[index] != tmp[index]) {
16 | break;
17 | }
18 | index++;
19 | }
20 | min = Math.min(index, min);
21 | if (min == 0) {
22 | return "";
23 | }
24 | }
25 | return strs[0].substring(0, min);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class28/Problem_0019_RemoveNthNodeFromEndofList.java:
--------------------------------------------------------------------------------
1 | package class28;
2 |
3 | public class Problem_0019_RemoveNthNodeFromEndofList {
4 |
5 | public static class ListNode {
6 | public int val;
7 | public ListNode next;
8 | }
9 |
10 | public static ListNode removeNthFromEnd(ListNode head, int n) {
11 | ListNode cur = head;
12 | ListNode pre = null;
13 | while (cur != null) {
14 | n--;
15 | if (n == -1) {
16 | pre = head;
17 | }
18 | if (n < -1) {
19 | pre = pre.next;
20 | }
21 | cur = cur.next;
22 | }
23 | if (n > 0) {
24 | return head;
25 | }
26 | if (pre == null) {
27 | return head.next;
28 | }
29 | pre.next = pre.next.next;
30 | return head;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class28/Problem_0020_ValidParentheses.java:
--------------------------------------------------------------------------------
1 | package class28;
2 |
3 | public class Problem_0020_ValidParentheses {
4 |
5 | public static boolean isValid(String s) {
6 | if (s == null || s.length() == 0) {
7 | return true;
8 | }
9 | char[] str = s.toCharArray();
10 | int N = str.length;
11 | char[] stack = new char[N];
12 | int size = 0;
13 | for (int i = 0; i < N; i++) {
14 | char cha = str[i];
15 | if (cha == '(' || cha == '[' || cha == '{') {
16 | stack[size++] = cha == '(' ? ')' : (cha == '[' ? ']' : '}');
17 | } else {
18 | if (size == 0) {
19 | return false;
20 | }
21 | char last = stack[--size];
22 | if (cha != last) {
23 | return false;
24 | }
25 | }
26 | }
27 | return size == 0;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class28/Problem_0026_RemoveDuplicatesFromSortedArray.java:
--------------------------------------------------------------------------------
1 | package class28;
2 |
3 | public class Problem_0026_RemoveDuplicatesFromSortedArray {
4 |
5 | public static int removeDuplicates(int[] nums) {
6 | if (nums == null) {
7 | return 0;
8 | }
9 | if (nums.length < 2) {
10 | return nums.length;
11 | }
12 | int done = 0;
13 | for (int i = 1; i < nums.length; i++) {
14 | if (nums[i] != nums[done]) {
15 | nums[++done] = nums[i];
16 | }
17 | }
18 | return done + 1;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class28/Problem_0034_FindFirstAndLastPositionOfElementInSortedArray.java:
--------------------------------------------------------------------------------
1 | package class28;
2 |
3 | public class Problem_0034_FindFirstAndLastPositionOfElementInSortedArray {
4 |
5 | public static int[] searchRange(int[] nums, int target) {
6 | if (nums == null || nums.length == 0) {
7 | return new int[] { -1, -1 };
8 | }
9 | int L = lessMostRight(nums, target) + 1;
10 | if (L == nums.length || nums[L] != target) {
11 | return new int[] { -1, -1 };
12 | }
13 | return new int[] { L, lessMostRight(nums, target + 1) };
14 | }
15 |
16 | public static int lessMostRight(int[] arr, int num) {
17 | int L = 0;
18 | int R = arr.length - 1;
19 | int M = 0;
20 | int ans = -1;
21 | while (L <= R) {
22 | M = L + ((R - L) >> 1);
23 | if (arr[M] < num) {
24 | ans = M;
25 | L = M + 1;
26 | } else {
27 | R = M - 1;
28 | }
29 | }
30 | return ans;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class28/Problem_0036_ValidSudoku.java:
--------------------------------------------------------------------------------
1 | package class28;
2 |
3 | public class Problem_0036_ValidSudoku {
4 |
5 | public static boolean isValidSudoku(char[][] board) {
6 | boolean[][] row = new boolean[9][10];
7 | boolean[][] col = new boolean[9][10];
8 | boolean[][] bucket = new boolean[9][10];
9 | for (int i = 0; i < 9; i++) {
10 | for (int j = 0; j < 9; j++) {
11 | int bid = 3 * (i / 3) + (j / 3);
12 | if (board[i][j] != '.') {
13 | int num = board[i][j] - '0';
14 | if (row[i][num] || col[j][num] || bucket[bid][num]) {
15 | return false;
16 | }
17 | row[i][num] = true;
18 | col[j][num] = true;
19 | bucket[bid][num] = true;
20 | }
21 | }
22 | }
23 | return true;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class28/Problem_0038_CountAndSay.java:
--------------------------------------------------------------------------------
1 | package class28;
2 |
3 | public class Problem_0038_CountAndSay {
4 |
5 | public static String countAndSay(int n) {
6 | if (n < 1) {
7 | return "";
8 | }
9 | if (n == 1) {
10 | return "1";
11 | }
12 | char[] last = countAndSay(n - 1).toCharArray();
13 | StringBuilder ans = new StringBuilder();
14 | int times = 1;
15 | for (int i = 1; i < last.length; i++) {
16 | if (last[i - 1] == last[i]) {
17 | times++;
18 | } else {
19 | ans.append(String.valueOf(times));
20 | ans.append(String.valueOf(last[i - 1]));
21 | times = 1;
22 | }
23 | }
24 | ans.append(String.valueOf(times));
25 | ans.append(String.valueOf(last[last.length - 1]));
26 | return ans.toString();
27 | }
28 |
29 | public static void main(String[] args) {
30 | System.out.println(countAndSay(20));
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class28/说明:
--------------------------------------------------------------------------------
1 | leetcode高频题
2 | leetcode全题目列表 : https://leetcode.com/problemset/all/
3 | 在全题目列表的右侧栏,点击Top Interview Questions
4 | 或者直接进入右侧链接 : https://leetcode.com/problemset/all/?listId=wpwgkgt
5 | 即可看到leetcode高频题全列表
6 | 本节课解决leetcode高频题列表中的如下题目 :
7 | 0008 : 大厂刷题班, 第28节, 本节
8 | 0010 : 大厂刷题班, 第12节第4题
9 | 0011 : 大厂刷题班, 第8节第2题
10 | 0012 : 大厂刷题班, 第28节, 本节
11 | 0013 : 大厂刷题班, 第28节, 本节
12 | 0014 : 大厂刷题班, 第28节, 本节
13 | 0015 : 大厂刷题班, 第25节第2题
14 | 0017 : 大厂刷题班, 第28节, 本节
15 | 0019 : 大厂刷题班, 第28节, 本节
16 | 0020 : 大厂刷题班, 第28节, 本节
17 | 0021 : 算法新手班, 第4节第6题
18 | 0022 : 大厂刷题班, 第28节, 本节
19 | 0023 : 算法新手班, 第6节第1题
20 | 0026 : 大厂刷题班, 第28节, 本节
21 | 0028 : 体系学习班, KMP算法
22 | 0029 : 算法新手班, 第5节第3题
23 | 0034 : 大厂刷题班, 第28节, 本节
24 | 0036 : 大厂刷题班, 第28节, 本节
25 | 0037 : 大厂刷题班, 第28节, 本节
26 | 0038 : 大厂刷题班, 第28节, 本节
27 | 0041 : 大厂刷题班, 第14节第6题
28 | 0042 : 大厂刷题班, 第22节第2题
29 | 0044 : 大厂刷题班, 第12节第4题
30 | 0045 : 大厂刷题班, 第10节第1题
31 | 0046 : 体系学习班, 第17节第4题
32 | 0048 : 体系学习班, 第40节第6题
33 | 0049 : 大厂刷题班, 第28节, 本节
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class29/Problem_0050_PowXN.java:
--------------------------------------------------------------------------------
1 | package class29;
2 |
3 | public class Problem_0050_PowXN {
4 |
5 | public static int pow(int a, int n) {
6 | int ans = 1;
7 | int t = a;
8 | while (n != 0) {
9 | if ((n & 1) != 0) {
10 | ans *= t;
11 | }
12 | t *= t;
13 | n >>= 1;
14 | }
15 | return ans;
16 | }
17 |
18 | // x的n次方,n可能是负数
19 | public static double myPow(double x, int n) {
20 | if (n == 0) {
21 | return 1D;
22 | }
23 | int pow = Math.abs(n == Integer.MIN_VALUE ? n + 1 : n);
24 | double t = x;
25 | double ans = 1D;
26 | while (pow != 0) {
27 | if ((pow & 1) != 0) {
28 | ans *= t;
29 | }
30 | pow >>= 1;
31 | t = t * t;
32 | }
33 | if (n == Integer.MIN_VALUE) {
34 | ans *= x;
35 | }
36 | return n < 0 ? (1D / ans) : ans;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class29/Problem_0056_MergeIntervals.java:
--------------------------------------------------------------------------------
1 | package class29;
2 |
3 | import java.util.Arrays;
4 |
5 | public class Problem_0056_MergeIntervals {
6 |
7 | public static int[][] merge(int[][] intervals) {
8 | if (intervals.length == 0) {
9 | return new int[0][0];
10 | }
11 | Arrays.sort(intervals, (a, b) -> a[0] - b[0]);
12 | int s = intervals[0][0];
13 | int e = intervals[0][1];
14 | int size = 0;
15 | for (int i = 1; i < intervals.length; i++) {
16 | if (intervals[i][0] > e) {
17 | intervals[size][0] = s;
18 | intervals[size++][1] = e;
19 | s = intervals[i][0];
20 | e = intervals[i][1];
21 | } else {
22 | e = Math.max(e, intervals[i][1]);
23 | }
24 | }
25 | intervals[size][0] = s;
26 | intervals[size++][1] = e;
27 | return Arrays.copyOf(intervals, size);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class29/Problem_0062_UniquePaths.java:
--------------------------------------------------------------------------------
1 | package class29;
2 |
3 | public class Problem_0062_UniquePaths {
4 |
5 | // m 行
6 | // n 列
7 | // 下:m-1
8 | // 右:n-1
9 | public static int uniquePaths(int m, int n) {
10 | int right = n - 1;
11 | int all = m + n - 2;
12 | long o1 = 1;
13 | long o2 = 1;
14 | // o1乘进去的个数 一定等于 o2乘进去的个数
15 | for (int i = right + 1, j = 1; i <= all; i++, j++) {
16 | o1 *= i;
17 | o2 *= j;
18 | long gcd = gcd(o1, o2);
19 | o1 /= gcd;
20 | o2 /= gcd;
21 | }
22 | return (int) o1;
23 | }
24 |
25 | // 调用的时候,请保证初次调用时,m和n都不为0
26 | public static long gcd(long m, long n) {
27 | return n == 0 ? m : gcd(n, m % n);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class29/Problem_0066_PlusOne.java:
--------------------------------------------------------------------------------
1 | package class29;
2 |
3 | public class Problem_0066_PlusOne {
4 |
5 | public static int[] plusOne(int[] digits) {
6 | int n = digits.length;
7 | for (int i = n - 1; i >= 0; i--) {
8 | if (digits[i] < 9) {
9 | digits[i]++;
10 | return digits;
11 | }
12 | digits[i] = 0;
13 | }
14 | int[] ans = new int[n + 1];
15 | ans[0] = 1;
16 | return ans;
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class29/Problem_0069_SqrtX.java:
--------------------------------------------------------------------------------
1 | package class29;
2 |
3 | public class Problem_0069_SqrtX {
4 |
5 | // x一定非负,输入可以保证
6 | public static int mySqrt(int x) {
7 | if (x == 0) {
8 | return 0;
9 | }
10 | if (x < 3) {
11 | return 1;
12 | }
13 | // x >= 3
14 | long ans = 1;
15 | long L = 1;
16 | long R = x;
17 | long M = 0;
18 | while (L <= R) {
19 | M = (L + R) / 2;
20 | if (M * M <= x) {
21 | ans = M;
22 | L = M + 1;
23 | } else {
24 | R = M - 1;
25 | }
26 | }
27 | return (int) ans;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class29/说明:
--------------------------------------------------------------------------------
1 | leetcode高频题
2 | leetcode全题目列表 : https://leetcode.com/problemset/all/
3 | 在全题目列表的右侧栏,点击Top Interview Questions
4 | 或者直接进入右侧链接 : https://leetcode.com/problemset/all/?listId=wpwgkgt
5 | 即可看到leetcode高频题全列表
6 | 本节课解决leetcode高频题列表中的如下题目 :
7 | 0033 : 大厂刷题班, 第29节, 本节
8 | 0050 : 大厂刷题班, 第29节, 本节
9 | 0053 : 体系学习班, 第40节第2题
10 | 0054 : 体系学习班, 第40节第5题
11 | 0055 : 大厂刷题班, 第10节第1题
12 | 0056 : 大厂刷题班, 第29节, 本节
13 | 0062 : 大厂刷题班, 第29节, 本节
14 | 0066 : 大厂刷题班, 第29节, 本节
15 | 0069 : 大厂刷题班, 第29节, 本节
16 | 0070 : 体系学习班, 第26节第2题
17 | 0073 : 大厂刷题班, 第29节, 本节
18 | 0075 : 体系学习班, 第5节第2题, 快排中的荷兰国旗问题
19 | 0076 : 大厂刷题班, 第24节第5题
20 | 0078 : 体系学习班, 第17节题目3, 生成子序列问题和本题一样的
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class30/Problem_0088_MergeSortedArray.java:
--------------------------------------------------------------------------------
1 | package class30;
2 |
3 | public class Problem_0088_MergeSortedArray {
4 |
5 | public static void merge(int[] nums1, int m, int[] nums2, int n) {
6 | int index = nums1.length;
7 | while (m > 0 && n > 0) {
8 | if (nums1[m - 1] >= nums2[n - 1]) {
9 | nums1[--index] = nums1[--m];
10 | } else {
11 | nums1[--index] = nums2[--n];
12 | }
13 | }
14 | while (m > 0) {
15 | nums1[--index] = nums1[--m];
16 | }
17 | while (n > 0) {
18 | nums1[--index] = nums2[--n];
19 | }
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class30/Problem_0101_SymmetricTree.java:
--------------------------------------------------------------------------------
1 | package class30;
2 |
3 | public class Problem_0101_SymmetricTree {
4 |
5 | public static class TreeNode {
6 | int val;
7 | TreeNode left;
8 | TreeNode right;
9 | }
10 |
11 | public boolean isSymmetric(TreeNode root) {
12 | return isMirror(root, root);
13 | }
14 |
15 | // 一棵树是原始树 head1
16 | // 另一棵是翻面树 head2
17 | public static boolean isMirror(TreeNode head1, TreeNode head2) {
18 | if (head1 == null && head2 == null) {
19 | return true;
20 | }
21 | if (head1 != null && head2 != null) {
22 | return head1.val == head2.val
23 | && isMirror(head1.left, head2.right)
24 | && isMirror(head1.right, head2.left);
25 | }
26 | // 一个为空,一个不为空 false
27 | return false;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class30/Problem_0108_ConvertSortedArrayToBinarySearchTree.java:
--------------------------------------------------------------------------------
1 | package class30;
2 |
3 | public class Problem_0108_ConvertSortedArrayToBinarySearchTree {
4 |
5 | public static class TreeNode {
6 | int val;
7 | TreeNode left;
8 | TreeNode right;
9 |
10 | TreeNode(int val) {
11 | this.val = val;
12 | }
13 | }
14 |
15 | public TreeNode sortedArrayToBST(int[] nums) {
16 | return process(nums, 0, nums.length - 1);
17 | }
18 |
19 | public static TreeNode process(int[] nums, int L, int R) {
20 | if (L > R) {
21 | return null;
22 | }
23 | if (L == R) {
24 | return new TreeNode(nums[L]);
25 | }
26 | int M = (L + R) / 2;
27 | TreeNode head = new TreeNode(nums[M]);
28 | head.left = process(nums, L, M - 1);
29 | head.right = process(nums, M + 1, R);
30 | return head;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class30/Problem_0118_PascalTriangle.java:
--------------------------------------------------------------------------------
1 | package class30;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class Problem_0118_PascalTriangle {
7 |
8 | public static List> generate(int numRows) {
9 | List> ans = new ArrayList<>();
10 | for (int i = 0; i < numRows; i++) {
11 | ans.add(new ArrayList<>());
12 | ans.get(i).add(1);
13 | }
14 | for (int i = 1; i < numRows; i++) {
15 | for (int j = 1; j < i; j++) {
16 | ans.get(i).add(ans.get(i - 1).get(j - 1) + ans.get(i - 1).get(j));
17 | }
18 | ans.get(i).add(1);
19 | }
20 | return ans;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class30/Problem_0119_PascalTriangleII.java:
--------------------------------------------------------------------------------
1 | package class30;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class Problem_0119_PascalTriangleII {
7 |
8 | public List getRow(int rowIndex) {
9 | List ans = new ArrayList<>();
10 | for (int i = 0; i <= rowIndex; i++) {
11 | for (int j = i - 1; j > 0; j--) {
12 | ans.set(j, ans.get(j - 1) + ans.get(j));
13 | }
14 | ans.add(1);
15 | }
16 | return ans;
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class30/说明:
--------------------------------------------------------------------------------
1 | leetcode高频题
2 | leetcode全题目列表 : https://leetcode.com/problemset/all/
3 | 在全题目列表的右侧栏,点击Top Interview Questions
4 | 或者直接进入右侧链接 : https://leetcode.com/problemset/all/?listId=wpwgkgt
5 | 即可看到leetcode高频题全列表
6 | 本节课解决leetcode高频题列表中的如下题目 :
7 | 0079 : 大厂刷题班, 第30节, 本节
8 | 0084 : 体系学习班, 第25节第3题
9 | 0088 : 大厂刷题班, 第30节, 本节
10 | 0091 : 体系学习班, 第19节第2题
11 | 0639 : 本题不再高频题列表中, 但本题是0091的难度加强题, 相似度很强, 大厂刷题班, 第30节, 本节
12 | 0094 : 体系学习班, 第30节第1题, Morris遍历
13 | 0098 : 大厂刷题班, 第30节, 本节
14 | 0101 : 大厂刷题班, 第30节, 本节
15 | 0102 : 新手班, 第7节第1题
16 | 0103 : 大厂刷题班, 第30节, 本节
17 | 0104 : 太简单了, 体系学习班, 二叉树的递归套路、Morris遍历都可以做, 跳过
18 | 0105 : 新手班, 第6节第5题
19 | 0108 : 大厂刷题班, 第30节, 本节
20 | 0116 : 大厂刷题班, 第30节, 本节
21 | 0118 : 大厂刷题班, 第30节, 本节
22 | 0119 : 本题不在高频题列表中,但和0118类似, 大厂刷题班, 第30节, 本节
23 | 0121 : 大厂刷题班, 第15节第1题
24 | 0122 : 大厂刷题班, 第15节第2题
25 | 0123 : 大厂刷题班, 第15节第3题
26 | 0124 : 大厂刷题班, 第30节, 本节
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class31/说明:
--------------------------------------------------------------------------------
1 | leetcode高频题
2 | leetcode全题目列表 : https://leetcode.com/problemset/all/
3 | 在全题目列表的右侧栏,点击Top Interview Questions
4 | 或者直接进入右侧链接 : https://leetcode.com/problemset/all/?listId=wpwgkgt
5 | 即可看到leetcode高频题全列表
6 | 本节课解决leetcode高频题列表中的如下题目 :
7 | 0125 : 大厂刷题班, 第31节, 本节
8 | 0127 : 大厂刷题班, 第31节, 本节
9 | 0128 : 大厂刷题班, 第12节第3题
10 | 0130 : 大厂刷题班, 第31节, 本节
11 | 0131 : 大厂刷题班, 第11节第2题
12 | 0134 : 体系学习班, 第24节第3题 & 大厂刷题班, 第25节第4题
13 | 0136 : 体系学习班, 第2节第2题
14 | 0138 : 体系学习班, 第9节第4题
15 | 0139 : 大厂刷题班, 第31节, 本节
16 | 0140 : 大厂刷题班, 第31节, 本节
17 | 0141 : 体系学习班, 第10节第1题
18 | 0146 : 大厂刷题班, 第19节第1题
19 | 0148 : 大厂刷题班, 第31节, 本节
20 | 0149 : 大厂刷题班, 第25节第3题
21 | 0150 : 大厂刷题班, 第31节, 本节
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class32/Problem_0163_MissingRanges.java:
--------------------------------------------------------------------------------
1 | package class32;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class Problem_0163_MissingRanges {
7 |
8 | public static List findMissingRanges(int[] nums, int lower, int upper) {
9 | List ans = new ArrayList<>();
10 | for (int num : nums) {
11 | if (num > lower) {
12 | ans.add(miss(lower, num - 1));
13 | }
14 | if (num == upper) {
15 | return ans;
16 | }
17 | lower = num + 1;
18 | }
19 | if (lower <= upper) {
20 | ans.add(miss(lower, upper));
21 | }
22 | return ans;
23 | }
24 |
25 | // 生成"lower->upper"的字符串,如果lower==upper,只用生成"lower"
26 | public static String miss(int lower, int upper) {
27 | String left = String.valueOf(lower);
28 | String right = "";
29 | if (upper > lower) {
30 | right = "->" + String.valueOf(upper);
31 | }
32 | return left + right;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class32/Problem_0171_ExcelSheetColumnNumber.java:
--------------------------------------------------------------------------------
1 | package class32;
2 |
3 | public class Problem_0171_ExcelSheetColumnNumber {
4 |
5 | // 这道题反过来也要会写
6 | public static int titleToNumber(String s) {
7 | char[] str = s.toCharArray();
8 | int ans = 0;
9 | for (int i = 0; i < str.length; i++) {
10 | ans = ans * 26 + (str[i] - 'A') + 1;
11 | }
12 | return ans;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class32/Problem_0172_FactorialTrailingZeroes.java:
--------------------------------------------------------------------------------
1 | package class32;
2 |
3 | public class Problem_0172_FactorialTrailingZeroes {
4 |
5 | public static int trailingZeroes(int n) {
6 | int ans = 0;
7 | while (n != 0) {
8 | n /= 5;
9 | ans += n;
10 | }
11 | return ans;
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class32/Problem_0191_NumberOf1Bits.java:
--------------------------------------------------------------------------------
1 | package class32;
2 |
3 | public class Problem_0191_NumberOf1Bits {
4 |
5 | // n的二进制形式,有几个1?
6 | public static int hammingWeight1(int n) {
7 | int bits = 0;
8 | int rightOne = 0;
9 | while(n != 0) {
10 | bits++;
11 | rightOne = n & (-n);
12 | n ^= rightOne;
13 | }
14 | return bits;
15 | }
16 |
17 | public static int hammingWeight2(int n) {
18 | n = (n & 0x55555555) + ((n >>> 1) & 0x55555555);
19 | n = (n & 0x33333333) + ((n >>> 2) & 0x33333333);
20 | n = (n & 0x0f0f0f0f) + ((n >>> 4) & 0x0f0f0f0f);
21 | n = (n & 0x00ff00ff) + ((n >>> 8) & 0x00ff00ff);
22 | n = (n & 0x0000ffff) + ((n >>> 16) & 0x0000ffff);
23 | return n;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class32/Problem_0204_CountPrimes.java:
--------------------------------------------------------------------------------
1 | package class32;
2 |
3 | public class Problem_0204_CountPrimes {
4 |
5 | public static int countPrimes(int n) {
6 | if (n < 3) {
7 | return 0;
8 | }
9 | // j已经不是素数了,f[j] = true;
10 | boolean[] f = new boolean[n];
11 | int count = n / 2; // 所有偶数都不要,还剩几个数
12 | // 跳过了1、2 3、5、7、
13 | for (int i = 3; i * i < n; i += 2) {
14 | if (f[i]) {
15 | continue;
16 | }
17 | // 3 -> 3 * 3 = 9 3 * 5 = 15 3 * 7 = 21
18 | // 7 -> 7 * 7 = 49 7 * 9 = 63
19 | // 13 -> 13 * 13 13 * 15
20 | for (int j = i * i; j < n; j += 2 * i) {
21 | if (!f[j]) {
22 | --count;
23 | f[j] = true;
24 | }
25 | }
26 | }
27 | return count;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class32/说明:
--------------------------------------------------------------------------------
1 | leetcode高频题
2 | leetcode全题目列表 : https://leetcode.com/problemset/all/
3 | 在全题目列表的右侧栏,点击Top Interview Questions
4 | 或者直接进入右侧链接 : https://leetcode.com/problemset/all/?listId=wpwgkgt
5 | 即可看到leetcode高频题全列表
6 | 本节课解决leetcode高频题列表中的如下题目 :
7 | 0152 : 大厂刷题班, 第32节, 本节
8 | 0155 : 体系学习班, 第3节第5题
9 | 0160 : 体系学习班, 第10节第1题
10 | 0162 : 体系学习班, 第1节第6题
11 | 0163 : 大厂刷题班, 第32节, 本节
12 | 0166 : 大厂刷题班, 第32节, 本节
13 | 0169 : 大厂刷题班, 第23节第4题
14 | 0171 : 大厂刷题班, 第32节, 本节
15 | 0172 : 大厂刷题班, 第32节, 本节
16 | 0179 : 体系学习班, 第13节第5题
17 | 0188 : 大厂刷题班, 第15节第4题
18 | 0189 : 大厂刷题班, 第32节, 本节
19 | 0190 : 大厂刷题班, 第32节, 本节
20 | 0191 : 大厂刷题班, 第32节, 本节
21 | 0198 : 大厂刷题班, 第4节第4题
22 | 0200 : 体系学习班, 第15节第2题、第3题
23 | 0202 : 大厂刷题班, 第32节, 本节
24 | 0204 : 大厂刷题班, 第32节, 本节
25 | 补充题 ExaminationPaperWays : 拼多多, 卷子合法数量问题
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class33/Problem_0237_DeleteNodeInLinkedList.java:
--------------------------------------------------------------------------------
1 | package class33;
2 |
3 | public class Problem_0237_DeleteNodeInLinkedList {
4 |
5 | public static class ListNode {
6 | int val;
7 | ListNode next;
8 | }
9 |
10 | public void deleteNode(ListNode node) {
11 | node.val = node.next.val;
12 | node.next = node.next.next;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class33/Problem_0238_ProductOfArrayExceptSelf.java:
--------------------------------------------------------------------------------
1 | package class33;
2 |
3 | public class Problem_0238_ProductOfArrayExceptSelf {
4 |
5 | public int[] productExceptSelf(int[] nums) {
6 | int n = nums.length;
7 | int[] ans = new int[n];
8 | ans[0] = nums[0];
9 | for (int i = 1; i < n; i++) {
10 | ans[i] = ans[i - 1] * nums[i];
11 | }
12 | int right = 1;
13 | for (int i = n - 1; i > 0; i--) {
14 | ans[i] = ans[i - 1] * right;
15 | right *= nums[i];
16 | }
17 | ans[0] = right;
18 | return ans;
19 | }
20 |
21 | // 扩展 : 如果仅仅是不能用除号,把结果直接填在nums里呢?
22 | // 解法:数一共几个0;每一个位得到结果就是,a / b,位运算替代 /,之前的课讲过(新手班)
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class33/Problem_0242_ValidAnagram.java:
--------------------------------------------------------------------------------
1 | package class33;
2 |
3 | public class Problem_0242_ValidAnagram {
4 |
5 | public static boolean isAnagram(String s, String t) {
6 | if (s.length() != t.length()) {
7 | return false;
8 | }
9 | char[] str1 = s.toCharArray();
10 | char[] str2 = t.toCharArray();
11 | int[] count = new int[256];
12 | for (char cha : str1) {
13 | count[cha]++;
14 | }
15 | for (char cha : str2) {
16 | if (--count[cha] < 0) {
17 | return false;
18 | }
19 | }
20 | return true;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class33/Problem_0277_FindTheCelebrity.java:
--------------------------------------------------------------------------------
1 | package class33;
2 |
3 | public class Problem_0277_FindTheCelebrity {
4 |
5 | // 提交时不要提交这个函数,因为默认系统会给你这个函数
6 | // knows方法,自己不认识自己
7 | public static boolean knows(int x, int i) {
8 | return true;
9 | }
10 |
11 | // 只提交下面的方法 0 ~ n-1
12 | public int findCelebrity(int n) {
13 | // 谁可能成为明星,谁就是cand
14 | int cand = 0;
15 | for (int i = 0; i < n; ++i) {
16 | if (knows(cand, i)) {
17 | cand = i;
18 | }
19 | }
20 | // cand是什么?唯一可能是明星的人!
21 | // 下一步就是验证,它到底是不是明星
22 | // 1) cand是不是不认识所有的人 cand...(右侧cand都不认识)
23 | // 所以,只用验证 ....cand的左侧即可
24 | for (int i = 0; i < cand; ++i) {
25 | if (knows(cand, i)) {
26 | return -1;
27 | }
28 | }
29 | // 2) 是不是所有的人都认识cand
30 | for (int i = 0; i < n; ++i) {
31 | if (!knows(i, cand)) {
32 | return -1;
33 | }
34 | }
35 | return cand;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class33/Problem_0283_MoveZeroes.java:
--------------------------------------------------------------------------------
1 | package class33;
2 |
3 | public class Problem_0283_MoveZeroes {
4 |
5 | public static void moveZeroes(int[] nums) {
6 | int to = 0;
7 | for (int i = 0; i < nums.length; i++) {
8 | if (nums[i] != 0) {
9 | swap(nums, to++, i);
10 | }
11 | }
12 | }
13 |
14 | public static void swap(int[] arr, int i, int j) {
15 | int tmp = arr[i];
16 | arr[i] = arr[j];
17 | arr[j] = tmp;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class33/说明:
--------------------------------------------------------------------------------
1 | leetcode高频题
2 | leetcode全题目列表 : https://leetcode.com/problemset/all/
3 | 在全题目列表的右侧栏,点击Top Interview Questions
4 | 或者直接进入右侧链接 : https://leetcode.com/problemset/all/?listId=wpwgkgt
5 | 即可看到leetcode高频题全列表
6 | 本节课解决leetcode高频题列表中的如下题目 :
7 | 0206 : 太简单,跳过
8 | 0207 : 大厂刷题班, 第33节, 本节
9 | 0208 : 体系学习班, 第8节第1题
10 | 0210 : 大厂刷题班, 第33节, 本节
11 | 0212 : 大厂刷题班, 第26节第1题
12 | 0213 : 大厂刷题班, 第33节, 本节
13 | 0215 : 体系学习班, 第29节第1题
14 | 0217 : 太简单,跳过
15 | 0218 : 大厂刷题班, 第4节第8题
16 | 0227 : 大厂刷题班, 第8节第1题
17 | 0230 : 太简单了,跳过。二叉树基本遍历、Morris遍历都可以解决
18 | 0234 : 体系学习班, 第9节第2题
19 | 0236 : 体系学习班, 第13节第3题 扩展在 大厂刷题班, 第23节第1题
20 | 0237 : 大厂刷题班, 第33节, 本节
21 | 0238 : 大厂刷题班, 第33节, 本节
22 | 0239 : 体系学习班, 第24节第1题
23 | 0240 : 大厂刷题班, 第17节第1题
24 | 0242 : 大厂刷题班, 第33节, 本节
25 | 0251 : 大厂刷题班, 第33节, 本节
26 | 0253 : 体系学习班, 第14节第3题
27 | 0268 : 大厂刷题班, 第14节第6题
28 | 0269 : 大厂刷题班, 第33节, 本节
29 | 0277 : 大厂刷题班, 第33节, 本节
30 | 0279 : 大厂刷题班, 第33节, 本节
31 | 0283 : 大厂刷题班, 第33节, 本节
32 | 0285 : 太简单了,跳过。用二叉树普通遍历或者Morris遍历都可以解决
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class34/Problem_0287_FindTheDuplicateNumber.java:
--------------------------------------------------------------------------------
1 | package class34;
2 |
3 | public class Problem_0287_FindTheDuplicateNumber {
4 |
5 | public static int findDuplicate(int[] nums) {
6 | if (nums == null || nums.length < 2) {
7 | return -1;
8 | }
9 | int slow = nums[0];
10 | int fast = nums[nums[0]];
11 | while (slow != fast) {
12 | slow = nums[slow];
13 | fast = nums[nums[fast]];
14 | }
15 | fast = 0;
16 | while (slow != fast) {
17 | fast = nums[fast];
18 | slow = nums[slow];
19 | }
20 | return slow;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class34/Problem_0326_PowerOfThree.java:
--------------------------------------------------------------------------------
1 | package class34;
2 |
3 | public class Problem_0326_PowerOfThree {
4 |
5 | // 如果一个数字是3的某次幂,那么这个数一定只含有3这个质数因子
6 | // 1162261467是int型范围内,最大的3的幂,它是3的19次方
7 | // 这个1162261467只含有3这个质数因子,如果n也是只含有3这个质数因子,那么
8 | // 1162261467 % n == 0
9 | // 反之如果1162261467 % n != 0 说明n一定含有其他因子
10 | public static boolean isPowerOfThree(int n) {
11 | return (n > 0 && 1162261467 % n == 0);
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class34/Problem_0340_LongestSubstringWithAtMostKDistinctCharacters.java:
--------------------------------------------------------------------------------
1 | package class34;
2 |
3 | public class Problem_0340_LongestSubstringWithAtMostKDistinctCharacters {
4 |
5 | public static int lengthOfLongestSubstringKDistinct(String s, int k) {
6 | if (s == null || s.length() == 0 || k < 1) {
7 | return 0;
8 | }
9 | char[] str = s.toCharArray();
10 | int N = str.length;
11 | int[] count = new int[256];
12 | int diff = 0;
13 | int R = 0;
14 | int ans = 0;
15 | for (int i = 0; i < N; i++) {
16 | // R 窗口的右边界
17 | while (R < N && (diff < k || (diff == k && count[str[R]] > 0))) {
18 | diff += count[str[R]] == 0 ? 1 : 0;
19 | count[str[R++]]++;
20 | }
21 | // R 来到违规的第一个位置
22 | ans = Math.max(ans, R - i);
23 | diff -= count[str[i]] == 1 ? 1 : 0;
24 | count[str[i]]--;
25 | }
26 | return ans;
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class34/Problem_0384_ShuffleAnArray.java:
--------------------------------------------------------------------------------
1 | package class34;
2 |
3 | public class Problem_0384_ShuffleAnArray {
4 |
5 | class Solution {
6 | private int[] origin;
7 | private int[] shuffle;
8 | private int N;
9 |
10 | public Solution(int[] nums) {
11 | origin = nums;
12 | N = nums.length;
13 | shuffle = new int[N];
14 | for (int i = 0; i < N; i++) {
15 | shuffle[i] = origin[i];
16 | }
17 | }
18 |
19 | public int[] reset() {
20 | return origin;
21 | }
22 |
23 | public int[] shuffle() {
24 | for (int i = N - 1; i >= 0; i--) {
25 | int r = (int) (Math.random() * (i + 1));
26 | int tmp = shuffle[r];
27 | shuffle[r] = shuffle[i];
28 | shuffle[i] = tmp;
29 | }
30 | return shuffle;
31 | }
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class34/说明:
--------------------------------------------------------------------------------
1 | leetcode高频题
2 | leetcode全题目列表 : https://leetcode.com/problemset/all/
3 | 在全题目列表的右侧栏,点击Top Interview Questions
4 | 或者直接进入右侧链接 : https://leetcode.com/problemset/all/?listId=wpwgkgt
5 | 即可看到leetcode高频题全列表
6 | 本节课解决leetcode高频题列表中的如下题目 :
7 | 0287 : 大厂刷题班, 第34节, 本节
8 | 0289 : 大厂刷题班, 第34节, 本节
9 | 0295 : 大厂刷题班, 第34节, 本节
10 | 0297 : 体系学习班, 第11节第2题
11 | 0300 : 大厂刷题班, 第9节第3题
12 | 0308 : 体系学习班, 第32节第2题
13 | 0309 : 大厂刷题班, 第15节第5题
14 | 0315 : 大厂刷题班, 第34节, 本节
15 | 0322 : 体系学习班, 硬币找零专题 : 第21节第2、3、4题, 第22节第2题, 第24节第4题
16 | 0324 : 大厂刷题班, 第34节, 本节
17 | 0326 : 大厂刷题班, 第34节, 本节
18 | 0328 : 大厂刷题班, 第34节, 本节
19 | 0329 : 大厂刷题班, 第1节第5题
20 | 0334 : 大厂刷题班, 第9节第3题的变形, 问 : 最长递增子序列长度能否超过2而已, 跳过
21 | 0340 : 大厂刷题班, 第34节, 本节
22 | 0341 : 大厂刷题班, 第34节, 本节
23 | 0344 : 太简单了, 跳过
24 | 0348 : 大厂刷题班, 第34节, 本节
25 | 0350 : 太简单了, 跳过
26 | 0371 : 新手班, 第5节第3题
27 | 0378 : 大厂刷题班, 第17节第2题
28 | 0380 : 大厂刷题班, 第34节, 本节
29 | 0384 : 大厂刷题班, 第34节, 本节
30 | 0387 : 太简单了, 跳过
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class35/Problem_0412_FizzBuzz.java:
--------------------------------------------------------------------------------
1 | package class35;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class Problem_0412_FizzBuzz {
7 |
8 | public static List fizzBuzz(int n) {
9 | ArrayList ans = new ArrayList<>();
10 | for (int i = 1; i <= n; i++) {
11 | if (i % 15 == 0) {
12 | ans.add("FizzBuzz");
13 | } else if (i % 5 == 0) {
14 | ans.add("Buzz");
15 | } else if (i % 3 == 0) {
16 | ans.add("Fizz");
17 | } else {
18 | ans.add(String.valueOf(i));
19 | }
20 | }
21 | return ans;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class35/Problem_0454_4SumII.java:
--------------------------------------------------------------------------------
1 | package class35;
2 |
3 | import java.util.HashMap;
4 |
5 | public class Problem_0454_4SumII {
6 |
7 | public static int fourSumCount(int[] A, int[] B, int[] C, int[] D) {
8 | HashMap map = new HashMap<>();
9 | int sum = 0;
10 | for (int i = 0; i < A.length; i++) {
11 | for (int j = 0; j < B.length; j++) {
12 | sum = A[i] + B[j];
13 | if (!map.containsKey(sum)) {
14 | map.put(sum, 1);
15 | } else {
16 | map.put(sum, map.get(sum) + 1);
17 | }
18 | }
19 | }
20 | int ans = 0;
21 | for (int i = 0; i < C.length; i++) {
22 | for (int j = 0; j < D.length; j++) {
23 | sum = C[i] + D[j];
24 | if (map.containsKey(-sum)) {
25 | ans += map.get(-sum);
26 | }
27 | }
28 | }
29 | return ans;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class35/说明:
--------------------------------------------------------------------------------
1 | leetcode高频题
2 | leetcode全题目列表 : https://leetcode.com/problemset/all/
3 | 在全题目列表的右侧栏,点击Top Interview Questions
4 | 或者直接进入右侧链接 : https://leetcode.com/problemset/all/?listId=wpwgkgt
5 | 即可看到leetcode高频题全列表
6 | 本节课解决leetcode高频题列表中的如下题目 :
7 | 0347 : 大厂刷题班, 第35节, 本节
8 | 0395 : 大厂刷题班, 第35节, 本节
9 | 0412 : 大厂刷题班, 第35节, 本节
10 | 0454 : 大厂刷题班, 第35节, 本节
11 | 0673 : 大厂刷题班, 第35节, 本节
12 | 0687 : 大厂刷题班, 第35节, 本节
13 | 0772 : 大厂刷题班, 第8节第1题
14 | 至此,Leetcode高频题系列完结
15 |
16 | 本节附加题
17 | Code01 : 2021年8月大厂真实笔试题
18 | Code02 : 2021年8月大厂真实笔试题
19 | Code03 : 2021年8月大厂真实笔试题
20 | Code04 : 2021年8月大厂真实笔试题
21 | Code05 : 2021年8月大厂真实笔试题
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class36/说明:
--------------------------------------------------------------------------------
1 | Code01 : 2021年8月大厂真实笔试题
2 | Code02 : 2021年8月大厂真实笔试题
3 | Code03 : 2021年8月大厂真实笔试题
4 | Code04 : 2021年8月大厂真实笔试题
5 | Code05 : 2021年8月大厂真实笔试题
6 | Code06 : 2021年8月大厂真实笔试题
7 | Code07 : 2021年8月大厂真实笔试题
8 | Code08 : 2021年8月大厂真实笔试题
9 | Code09 : 2021年8月大厂真实笔试题
10 | Code10 : 2021年8月大厂真实笔试题
11 | Code11 : 2021年8月大厂真实笔试题
12 | Code12 : 2021年8月大厂真实笔试题
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class37/Problem_0221_MaximalSquare.java:
--------------------------------------------------------------------------------
1 | package class37;
2 |
3 | public class Problem_0221_MaximalSquare {
4 |
5 | public static int maximalSquare(char[][] m) {
6 | if (m == null || m.length == 0 || m[0].length == 0) {
7 | return 0;
8 | }
9 | int N = m.length;
10 | int M = m[0].length;
11 | int[][] dp = new int[N + 1][M + 1];
12 | int max = 0;
13 | for (int i = 0; i < N; i++) {
14 | if (m[i][0] == '1') {
15 | dp[i][0] = 1;
16 | max = 1;
17 | }
18 | }
19 | for (int j = 1; j < M; j++) {
20 | if (m[0][j] == '1') {
21 | dp[0][j] = 1;
22 | max = 1;
23 | }
24 | }
25 | for (int i = 1; i < N; i++) {
26 | for (int j = 1; j < M; j++) {
27 | if (m[i][j] == '1') {
28 | dp[i][j] = Math.min(
29 | Math.min(dp[i - 1][j],
30 | dp[i][j - 1]),
31 | dp[i - 1][j - 1])
32 | + 1;
33 | max = Math.max(max, dp[i][j]);
34 | }
35 | }
36 | }
37 | return max * max;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class37/Problem_0226_InvertBinaryTree.java:
--------------------------------------------------------------------------------
1 | package class37;
2 |
3 | public class Problem_0226_InvertBinaryTree {
4 |
5 | public class TreeNode {
6 | public int val;
7 | public TreeNode left;
8 | public TreeNode right;
9 | }
10 |
11 | public static TreeNode invertTree(TreeNode root) {
12 | if (root == null) {
13 | return null;
14 | }
15 | TreeNode left = root.left;
16 | root.left = invertTree(root.right);
17 | root.right = invertTree(left);
18 | return root;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class37/Problem_0337_HouseRobberIII.java:
--------------------------------------------------------------------------------
1 | package class37;
2 |
3 | public class Problem_0337_HouseRobberIII {
4 |
5 | public static class TreeNode {
6 | public int val;
7 | public TreeNode left;
8 | public TreeNode right;
9 | }
10 |
11 | public static int rob(TreeNode root) {
12 | Info info = process(root);
13 | return Math.max(info.no, info.yes);
14 | }
15 |
16 | public static class Info {
17 | public int no;
18 | public int yes;
19 |
20 | public Info(int n, int y) {
21 | no = n;
22 | yes = y;
23 | }
24 | }
25 |
26 | public static Info process(TreeNode x) {
27 | if (x == null) {
28 | return new Info(0, 0);
29 | }
30 | Info leftInfo = process(x.left);
31 | Info rightInfo = process(x.right);
32 | int no = Math.max(leftInfo.no, leftInfo.yes) + Math.max(rightInfo.no, rightInfo.yes);
33 | int yes = x.val + leftInfo.no + rightInfo.no;
34 | return new Info(no, yes);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class37/说明:
--------------------------------------------------------------------------------
1 | leetcode最受欢迎100题
2 | leetcode全题目列表 : https://leetcode.com/problemset/all/
3 | 在全题目列表的右侧栏,点击Top 100 Liked Questions
4 | 或者直接进入右侧链接 : https://leetcode.com/problemset/all/?listId=79h8rn6
5 | 即可看到leetcode最受欢迎100题全列表
6 |
7 | 大厂刷题班27节~35节已经讲完leetcode高频题系列
8 | leetcode高频题系列和leetcode最受欢迎100题系列题目有重合
9 | 以下为leetcode最受欢迎100题不和leetcode高频题重合的题号,其他的都重复了,不再讲述
10 | 0032 : 大厂刷题班, 第14节第1题
11 | 0039 : 体系学习班, 硬币找零专题 : 第21节第2、3、4题, 第22节第2题, 第24节第4题。本题就是无限张找零问题,不再重复讲述
12 | 0064 : 体系学习班, 第21节第1题
13 | 0072 : 大厂刷题班, 第5节第3题
14 | 0085 : 体系学习班, 第25节第4题
15 | 0096 : 体系学习班, 第39节第4题, 卡特兰数
16 | 0114 : 大厂刷题班, 第37节, 本节
17 | 0142 : 体系学习班, 第10节第1题
18 | 0221 : 大厂刷题班, 第37节, 本节
19 | 0226 : 大厂刷题班, 第37节, 本节
20 | 0337 : 体系学习班, 第13节, 第4题, 还是这道题的加强版(多叉树)
21 | 0338 : 和leetcode第191题重复, 大厂刷题班第30节讲过了
22 | 0394 : 大厂刷题班, 第37节, 本节
23 | 0406 : 大厂刷题班, 第37节, 本节
24 | 0416 : 体系学习班, 第23节第1题, 还是这道题的加强版
25 | 0437 : 大厂刷题班, 第37节, 本节
26 | 剩余题目在下一节
27 |
28 | 本节附加题
29 | code01 : 2021年8月大厂真实笔试题
30 | code02 : 2021年8月大厂真实笔试题
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class38/Problem_0617_MergeTwoBinaryTrees.java:
--------------------------------------------------------------------------------
1 | package class38;
2 |
3 | public class Problem_0617_MergeTwoBinaryTrees {
4 |
5 | public static class TreeNode {
6 | public int val;
7 | public TreeNode left;
8 | public TreeNode right;
9 |
10 | public TreeNode(int val) {
11 | this.val = val;
12 | }
13 | }
14 |
15 | // 当前,一棵树的头是t1,另一颗树的头是t2
16 | // 请返回,整体merge之后的头
17 | public static TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
18 | if (t1 == null) {
19 | return t2;
20 | }
21 | if (t2 == null) {
22 | return t1;
23 | }
24 | // t1和t2都不是空
25 | TreeNode merge = new TreeNode(t1.val + t2.val);
26 | merge.left = mergeTrees(t1.left, t2.left);
27 | merge.right = mergeTrees(t1.right, t2.right);
28 | return merge;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class38/Problem_0739_DailyTemperatures.java:
--------------------------------------------------------------------------------
1 | package class38;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Stack;
6 |
7 | public class Problem_0739_DailyTemperatures {
8 |
9 | public static int[] dailyTemperatures(int[] arr) {
10 | if (arr == null || arr.length == 0) {
11 | return new int[0];
12 | }
13 | int N = arr.length;
14 | int[] ans = new int[N];
15 | Stack> stack = new Stack<>();
16 | for (int i = 0; i < N; i++) {
17 | while (!stack.isEmpty() && arr[stack.peek().get(0)] < arr[i]) {
18 | List popIs = stack.pop();
19 | for (Integer popi : popIs) {
20 | ans[popi] = i - popi;
21 | }
22 | }
23 | if (!stack.isEmpty() && arr[stack.peek().get(0)] == arr[i]) {
24 | stack.peek().add(Integer.valueOf(i));
25 | } else {
26 | ArrayList list = new ArrayList<>();
27 | list.add(i);
28 | stack.push(list);
29 | }
30 | }
31 | return ans;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class38/Problem_0763_PartitionLabels.java:
--------------------------------------------------------------------------------
1 | package class38;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class Problem_0763_PartitionLabels {
7 |
8 | public static List partitionLabels(String S) {
9 | char[] str = S.toCharArray();
10 | int[] far = new int[26];
11 | for (int i = 0; i < str.length; i++) {
12 | far[str[i] - 'a'] = i;
13 | }
14 | List ans = new ArrayList<>();
15 | int left = 0;
16 | int right = far[str[0] - 'a'];
17 | for (int i = 1; i < str.length; i++) {
18 | if (i > right) {
19 | ans.add(right - left + 1);
20 | left = i;
21 | }
22 | right = Math.max(right, far[str[i] - 'a']);
23 | }
24 | ans.add(right - left + 1);
25 | return ans;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class38/说明:
--------------------------------------------------------------------------------
1 | leetcode最受欢迎100题
2 | leetcode全题目列表 : https://leetcode.com/problemset/all/
3 | 在全题目列表的右侧栏,点击Top 100 Liked Questions
4 | 或者直接进入右侧链接 : https://leetcode.com/problemset/all/?listId=79h8rn6
5 | 即可看到leetcode最受欢迎100题全列表
6 |
7 | 大厂刷题班27节~35节已经讲完leetcode高频题系列
8 | leetcode高频题系列和leetcode最受欢迎100题系列题目有重合
9 | 以下为leetcode最受欢迎100题不和leetcode高频题重合的题号,其他的都重复了,不再讲述
10 | 0438 : 大厂刷题班, 第38节, 本节
11 | 0448 : 大厂刷题班, 第38节, 本节
12 | 0494 : 大厂刷题班, 第1节第7题
13 | 0543 : 体系学习班, 第12节第6题
14 | 0560 : 大厂刷题班, 第37节, Leetcode题目437与本题思路相同, 课上也讲了该题做法
15 | 0581 : 大厂刷题班, 第1节第6题
16 | 0617 : 大厂刷题班, 第38节, 本节
17 | 0621 : 大厂刷题班, 第38节, 本节
18 | 0647 : 大厂刷题班, 第38节, 本节
19 | 0739 : 大厂刷题班, 第38节, 本节
20 | 0763 : 大厂刷题班, 第38节, 本节
21 | 至此,leetcode最受欢迎100题系列完结
22 |
23 | 本节附加题
24 | code01 : 2021年8月大厂真实笔试题
25 | code02 : 2021年8月大厂真实笔试题
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class42/Problem_0335_SelfCrossing.java:
--------------------------------------------------------------------------------
1 | package class42;
2 |
3 | public class Problem_0335_SelfCrossing {
4 |
5 | public static boolean isSelfCrossing(int[] x) {
6 | if (x == null || x.length < 4) {
7 | return false;
8 | }
9 | if ((x.length > 3 && x[2] <= x[0] && x[3] >= x[1])
10 | || (x.length > 4
11 | && ((x[3] <= x[1] && x[4] >= x[2]) || (x[3] == x[1] && x[0] + x[4] >= x[2])))) {
12 | return true;
13 | }
14 | for (int i = 5; i < x.length; i++) {
15 | if (x[i - 1] <= x[i - 3] && ((x[i] >= x[i - 2])
16 | || (x[i - 2] >= x[i - 4] && x[i - 5] + x[i - 1] >= x[i - 3] && x[i - 4] + x[i] >= x[i - 2]))) {
17 | return true;
18 | }
19 | }
20 | return false;
21 | }
22 |
23 | public static void main(String[] args) {
24 | int[] arr = { 2, 2, 3, 2, 2 };
25 | System.out.println(isSelfCrossing(arr));
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class48/Problem_0483_SmallestGoodBase.java:
--------------------------------------------------------------------------------
1 | package class48;
2 |
3 | public class Problem_0483_SmallestGoodBase {
4 |
5 | // ""4651" -> 4651
6 | public static String smallestGoodBase(String n) {
7 | long num = Long.valueOf(n);
8 | // n这个数,需要从m位开始试,固定位数,一定要有m位!
9 | for (int m = (int) (Math.log(num + 1) / Math.log(2)); m > 2; m--) {
10 | // num开m次方
11 | long l = (long) (Math.pow(num, 1.0 / m));
12 | long r = (long) (Math.pow(num, 1.0 / (m - 1))) + 1L;
13 | while (l <= r) {
14 | long k = l + ((r - l) >> 1);
15 | long sum = 0L;
16 | long base = 1L;
17 | for (int i = 0; i < m && sum <= num; i++) {
18 | sum += base;
19 | base *= k;
20 | }
21 | if (sum < num) {
22 | l = k + 1;
23 | } else if (sum > num) {
24 | r = k - 1;
25 | } else {
26 | return String.valueOf(k);
27 | }
28 | }
29 | }
30 | return String.valueOf(num - 1);
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class49/Problem_0446_ArithmeticSlicesIISubsequence.java:
--------------------------------------------------------------------------------
1 | package class49;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 |
6 | public class Problem_0446_ArithmeticSlicesIISubsequence {
7 |
8 | // 时间复杂度是O(N^2),最优解的时间复杂度
9 | public static int numberOfArithmeticSlices(int[] arr) {
10 | int N = arr.length;
11 | int ans = 0;
12 | ArrayList> maps = new ArrayList<>();
13 | for (int i = 0; i < N; i++) {
14 | maps.add(new HashMap<>());
15 | // ....j...i(结尾)
16 | for (int j = i - 1; j >= 0; j--) {
17 | long diff = (long) arr[i] - (long) arr[j];
18 | if (diff <= Integer.MIN_VALUE || diff > Integer.MAX_VALUE) {
19 | continue;
20 | }
21 | int dif = (int) diff;
22 | int count = maps.get(j).getOrDefault(dif, 0);
23 | ans += count;
24 | maps.get(i).put(dif, maps.get(i).getOrDefault(dif, 0) + count + 1);
25 | }
26 | }
27 | return ans;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class51/Problem_0630_CourseScheduleIII.java:
--------------------------------------------------------------------------------
1 | package class51;
2 |
3 | import java.util.Arrays;
4 | import java.util.PriorityQueue;
5 |
6 | public class Problem_0630_CourseScheduleIII {
7 |
8 | public static int scheduleCourse(int[][] courses) {
9 | // courses[i] = {花费,截止}
10 | Arrays.sort(courses, (a, b) -> a[1] - b[1]);
11 | // 花费时间的大根堆
12 | PriorityQueue heap = new PriorityQueue<>((a, b) -> b - a);
13 | // 时间点
14 | int time = 0;
15 | for (int[] c : courses) {
16 | //
17 | if (time + c[0] <= c[1]) { // 当前时间 + 花费 <= 截止时间的
18 | heap.add(c[0]);
19 | time += c[0];
20 | } else { // 当前时间 + 花费 > 截止时间的, 只有淘汰掉某课,当前的课才能进来!
21 | if (!heap.isEmpty() && heap.peek() > c[0]) {
22 | // time -= heap.poll();
23 | // heap.add(c[0]);
24 | // time += c[0];
25 | heap.add(c[0]);
26 | time += c[0] - heap.poll();
27 | }
28 | }
29 | }
30 | return heap.size();
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/大厂算法和数据结构刷题班/coding-for-great-offer/src/class51/Problem_0875_KokoEatingBananas.java:
--------------------------------------------------------------------------------
1 | package class51;
2 |
3 | public class Problem_0875_KokoEatingBananas {
4 |
5 | public static int minEatingSpeed(int[] piles, int h) {
6 | int L = 1;
7 | int R = 0;
8 | for (int pile : piles) {
9 | R = Math.max(R, pile);
10 | }
11 | int ans = 0;
12 | int M = 0;
13 | while (L <= R) {
14 | M = L + ((R - L) >> 1);
15 | if (hours(piles, M) <= h) {
16 | ans = M;
17 | R = M - 1;
18 | } else {
19 | L = M + 1;
20 | }
21 | }
22 | return ans;
23 | }
24 |
25 | public static long hours(int[] piles, int speed) {
26 | long ans = 0;
27 | int offset = speed - 1;
28 | for (int pile : piles) {
29 | ans += (pile + offset) / speed;
30 | }
31 | return ans;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/左程云算法 源码/Algorithm-master.zip
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Algorithm
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=10
4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5 | org.eclipse.jdt.core.compiler.compliance=10
6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11 | org.eclipse.jdt.core.compiler.source=10
12 |
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master/Algorithm-master.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master/src/Test/CountSortTest.java:
--------------------------------------------------------------------------------
1 | package Test;
2 |
3 | import static org.junit.jupiter.api.Assertions.*;
4 |
5 | import java.util.Arrays;
6 | import java.util.Random;
7 |
8 | import org.junit.jupiter.api.Test;
9 |
10 | import com.mashibing.CountSort;
11 |
12 | class CountSortTest {
13 |
14 | int[] generateRandomArray() {
15 | Random r = new Random();
16 |
17 | int[] arr = new int[10000];
18 |
19 | for (int i = 0; i < arr.length; i++)
20 | arr[i] = r.nextInt(10);
21 |
22 | return arr;
23 | }
24 |
25 |
26 | @Test
27 | void testSort() {
28 | int[] a = generateRandomArray();
29 | int[] result = CountSort.sort(a);
30 | Arrays.sort(a);
31 | boolean same = true;
32 |
33 | for (int i = 0; i < a.length; i++) {
34 | if(result[i] != a[i]) same = false;
35 | }
36 |
37 | assertEquals(true, same);
38 |
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master/src/Test/RadixSortTest.java:
--------------------------------------------------------------------------------
1 | package Test;
2 |
3 | import static org.junit.jupiter.api.Assertions.*;
4 |
5 | import java.util.Arrays;
6 | import java.util.Random;
7 |
8 | import org.junit.jupiter.api.Test;
9 |
10 | import com.mashibing.RadixSort;
11 |
12 | class RadixSortTest {
13 |
14 | int[] generateRandomArray() {
15 | Random r = new Random();
16 |
17 | int[] arr = new int[10000];
18 |
19 | for (int i = 0; i < arr.length; i++)
20 | arr[i] = r.nextInt(1000);
21 |
22 | return arr;
23 | }
24 |
25 |
26 | @Test
27 | void testSort() {
28 | int[] a = generateRandomArray();
29 | int[] result = RadixSort.sort(a);
30 | Arrays.sort(a);
31 | boolean same = true;
32 |
33 | for (int i = 0; i < a.length; i++) {
34 | if(result[i] != a[i]) same = false;
35 | }
36 |
37 | assertEquals(true, same);
38 |
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master/src/com/mashibing/BinarySearch.java:
--------------------------------------------------------------------------------
1 | package com.mashibing;
2 |
3 | public class BinarySearch {
4 | public static void main(String[] args) {
5 | int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
6 |
7 | int num = 100;
8 | int pos = -1;
9 |
10 | for (int start = 0, end = a.length - 1; start <= end;) {
11 | int middle = (start + end) / 2;
12 | if (a[middle] == num) {
13 | pos = middle;
14 | break;
15 | } else if (a[middle] < num) {
16 | start = middle+1;
17 | } else {
18 | end = middle-1;
19 | }
20 | }
21 |
22 | System.out.println(pos);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master/src/com/mashibing/BubbleSort.java:
--------------------------------------------------------------------------------
1 | package com.mashibing;
2 |
3 | public class BubbleSort {
4 | public static void main(String[] args) {
5 | int[] a = { 9, 3, 1, 4, 6, 8, 7, 5, 2};
6 | sort(a);
7 | print(a);
8 | }
9 |
10 | static void sort(int[] a) {
11 | for(int i=a.length-1; i>0; i--)
12 | findMax(a, i);
13 | }
14 |
15 | static void findMax(int[] a, int n) {
16 | for(int j=0; j a[j+1]) swap(a, j, j+1);
18 | }
19 | }
20 |
21 | static void swap(int[] a, int i, int j) {
22 | int temp = a[i];
23 | a[i] = a[j];
24 | a[j] = temp;
25 | }
26 |
27 | static void print(int[] arr) {
28 | for(int i=0; i0 && a[j] < a[j-1]; j--) {
13 | //if(a[j] < a[j-1]) {
14 | swap(a, j, j-1);
15 | //}
16 | }
17 | }
18 | }
19 |
20 | static void swap(int[] a, int i, int j) {
21 | int temp = a[i];
22 | a[i] = a[j];
23 | a[j] = temp;
24 | }
25 |
26 | static void print(int[] arr) {
27 | for (int i = 0; i < arr.length; i++) {
28 | System.out.print(arr[i] + " ");
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master/src/com/mashibing/MergeSort.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/左程云算法 源码/Algorithm-master/src/com/mashibing/MergeSort.java
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master/src/com/mashibing/RadixSort.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/左程云算法 源码/Algorithm-master/src/com/mashibing/RadixSort.java
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master/src/com/mashibing/SelectionSort.java:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/左程云算法 源码/Algorithm-master/src/com/mashibing/SelectionSort.java
--------------------------------------------------------------------------------
/左程云算法 源码/Algorithm-master/src/com/mashibing/ShellSort.java:
--------------------------------------------------------------------------------
1 | package com.mashibing;
2 |
3 |
4 | public class ShellSort {
5 |
6 | public static void main(String[] args) {
7 | int[] arr = { 9, 6, 11, 3, 5, 12, 8, 7, 10, 15, 14, 4, 1, 13, 2 };
8 |
9 | sort(arr);
10 |
11 | print(arr);
12 | }
13 |
14 | public static void sort(int[] arr) {
15 |
16 | int h = 1;
17 | while(h <= arr.length /3 ) {
18 | h = h*3 + 1;
19 | }
20 |
21 | for(int gap = h; gap > 0; gap = (gap-1)/3) {
22 |
23 | for(int i=gap; igap-1; j-=gap) {
25 | if(arr[j] < arr[j-gap]) {
26 | swap(arr, j, j-gap);
27 | }
28 | }
29 | }
30 | }
31 |
32 | }
33 |
34 | static void swap(int[] arr, int i, int j) {
35 | int temp = arr[i];
36 | arr[i] = arr[j];
37 | arr[j] = temp;
38 | }
39 |
40 | static void print(int[] arr) {
41 | for(int i=0; i
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class01/Code04_BSExist.java:
--------------------------------------------------------------------------------
1 | package class01;
2 |
3 | public class Code04_BSExist {
4 |
5 | public static boolean exist(int[] sortedArr, int num) {
6 | if (sortedArr == null || sortedArr.length == 0) {
7 | return false;
8 | }
9 | int L = 0;
10 | int R = sortedArr.length - 1;
11 | int mid = 0;
12 | // L..R
13 | while (L < R) {
14 | // mid = (L+R) / 2;
15 | // L 10亿 R 18亿
16 | // mid = L + (R - L) / 2
17 | // N / 2 N >> 1
18 | mid = L + ((R - L) >> 1); // mid = (L + R) / 2
19 | if (sortedArr[mid] == num) {
20 | return true;
21 | } else if (sortedArr[mid] > num) {
22 | R = mid - 1;
23 | } else {
24 | L = mid + 1;
25 | }
26 | }
27 | return sortedArr[L] == num;
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class01/Code06_BSAwesome.java:
--------------------------------------------------------------------------------
1 | package class01;
2 |
3 | public class Code06_BSAwesome {
4 |
5 | public static int getLessIndex(int[] arr) {
6 | if (arr == null || arr.length == 0) {
7 | return -1; // no exist
8 | }
9 | if (arr.length == 1 || arr[0] < arr[1]) {
10 | return 0;
11 | }
12 | if (arr[arr.length - 1] < arr[arr.length - 2]) {
13 | return arr.length - 1;
14 | }
15 | int left = 1;
16 | int right = arr.length - 2;
17 | int mid = 0;
18 | while (left < right) {
19 | mid = (left + right) / 2;
20 | if (arr[mid] > arr[mid - 1]) {
21 | right = mid - 1;
22 | } else if (arr[mid] > arr[mid + 1]) {
23 | left = mid + 1;
24 | } else {
25 | return mid;
26 | }
27 | }
28 | return left;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class01/Test.java:
--------------------------------------------------------------------------------
1 | package class01;
2 |
3 | public class Test {
4 |
5 | public static void main(String[] args) {
6 | int a = 6;
7 | int b = 6;
8 |
9 |
10 | a = a ^ b;
11 | b = a ^ b;
12 | a = a ^ b;
13 |
14 |
15 | System.out.println(a);
16 | System.out.println(b);
17 |
18 |
19 |
20 |
21 | int[] arr = {3,1,100};
22 |
23 | System.out.println(arr[0]);
24 | System.out.println(arr[2]);
25 |
26 | swap(arr, 0, 0);
27 |
28 | System.out.println(arr[0]);
29 | System.out.println(arr[2]);
30 |
31 |
32 |
33 | }
34 |
35 |
36 | public static void swap (int[] arr, int i, int j) {
37 | // arr[0] = arr[0] ^ arr[0];
38 | arr[i] = arr[i] ^ arr[j];
39 | arr[j] = arr[i] ^ arr[j];
40 | arr[i] = arr[i] ^ arr[j];
41 | }
42 |
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class02/Code02_DeleteGivenValue.java:
--------------------------------------------------------------------------------
1 | package class02;
2 |
3 | public class Code02_DeleteGivenValue {
4 |
5 | public static class Node {
6 | public int value;
7 | public Node next;
8 |
9 | public Node(int data) {
10 | this.value = data;
11 | }
12 | }
13 |
14 | public static Node removeValue(Node head, int num) {
15 | while (head != null) {
16 | if (head.value != num) {
17 | break;
18 | }
19 | head = head.next;
20 | }
21 | // head来到 第一个不需要删的位置
22 | Node pre = head;
23 | Node cur = head;
24 | //
25 | while (cur != null) {
26 | if (cur.value == num) {
27 | pre.next = cur.next;
28 | } else {
29 | pre = cur;
30 | }
31 | cur = cur.next;
32 | }
33 | return head;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class02/Code08_GetMax.java:
--------------------------------------------------------------------------------
1 | package class02;
2 |
3 | public class Code08_GetMax {
4 |
5 | // 求arr中的最大值
6 | public static int getMax(int[] arr) {
7 | return process(arr, 0, arr.length - 1);
8 | }
9 |
10 | // arr[L..R]范围上求最大值 L ... R N
11 | public static int process(int[] arr, int L, int R) {
12 | if (L == R) { // arr[L..R]范围上只有一个数,直接返回,base case
13 | return arr[L];
14 | }
15 | int mid = L + ((R - L) >> 1); // 中点 1
16 | int leftMax = process(arr, L, mid);
17 | int rightMax = process(arr, mid + 1, R);
18 | return Math.max(leftMax, rightMax);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class04/Test.java:
--------------------------------------------------------------------------------
1 | package class04;
2 |
3 | import java.util.Comparator;
4 | import java.util.PriorityQueue;
5 |
6 |
7 | public class Test {
8 |
9 | // 负数,o1 放在上面的情况
10 | public static class MyComp implements Comparator{
11 |
12 | @Override
13 | public int compare(Integer o1, Integer o2) {
14 | return o2 - o1;
15 | }
16 |
17 | }
18 |
19 |
20 |
21 | public static void main(String[] args) {
22 | System.out.println("hello");
23 | // 大根堆
24 | PriorityQueue heap = new PriorityQueue<>(new MyComp());
25 |
26 | heap.add(5);
27 | heap.add(7);
28 | heap.add(3);
29 | heap.add(0);
30 | heap.add(2);
31 | heap.add(5);
32 |
33 | while(!heap.isEmpty()) {
34 | System.out.println(heap.poll());
35 | }
36 |
37 |
38 |
39 |
40 |
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class06/Test.java:
--------------------------------------------------------------------------------
1 | package class06;
2 |
3 | public class Test {
4 |
5 | public static class Node{
6 | public int value;
7 | public Node next;
8 | public Node(int v) {
9 | value = v;
10 | }
11 | }
12 |
13 | public static void main(String[] args) {
14 | Node a = new Node(1);
15 | Node b = new Node(2);
16 | Node c = new Node(3);
17 |
18 | a.next = b;
19 | b.next = c;
20 |
21 | c = null;
22 |
23 | }
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class07/Code08_PaperFolding.java:
--------------------------------------------------------------------------------
1 | package class07;
2 |
3 | public class Code08_PaperFolding {
4 |
5 | public static void printAllFolds(int N) {
6 | printProcess(1, N, true);
7 | }
8 |
9 | // 递归过程,来到了某一个节点,
10 | // i是节点的层数,N一共的层数,down == true 凹 down == false 凸
11 | public static void printProcess(int i, int N, boolean down) {
12 | if (i > N) {
13 | return;
14 | }
15 | printProcess(i + 1, N, true);
16 | System.out.println(down ? "凹 " : "凸 ");
17 | printProcess(i + 1, N, false);
18 | }
19 |
20 | public static void main(String[] args) {
21 | int N = 3;
22 | printAllFolds(N);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class10/Code02_BFS.java:
--------------------------------------------------------------------------------
1 | package class10;
2 |
3 | import java.util.HashSet;
4 | import java.util.LinkedList;
5 | import java.util.Queue;
6 |
7 | public class Code02_BFS {
8 |
9 | // 从node出发,进行宽度优先遍历
10 | public static void bfs(Node node) {
11 | if (node == null) {
12 | return;
13 | }
14 | Queue queue = new LinkedList<>();
15 | HashSet set = new HashSet<>();
16 | queue.add(node);
17 | set.add(node);
18 | while (!queue.isEmpty()) {
19 | Node cur = queue.poll();
20 | System.out.println(cur.value);
21 | for (Node next : cur.nexts) {
22 | if (!set.contains(next)) {
23 | set.add(next);
24 | queue.add(next);
25 | }
26 | }
27 | }
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class10/Code02_DFS.java:
--------------------------------------------------------------------------------
1 | package class10;
2 |
3 | import java.util.HashSet;
4 | import java.util.Stack;
5 |
6 | public class Code02_DFS {
7 |
8 | public static void dfs(Node node) {
9 | if (node == null) {
10 | return;
11 | }
12 | Stack stack = new Stack<>();
13 | HashSet set = new HashSet<>();
14 | stack.add(node);
15 | set.add(node);
16 | System.out.println(node.value);
17 | while (!stack.isEmpty()) {
18 | Node cur = stack.pop();
19 | for (Node next : cur.nexts) {
20 | if (!set.contains(next)) {
21 | stack.push(cur);
22 | stack.push(next);
23 | set.add(next);
24 | System.out.println(next.value);
25 | break;
26 | }
27 | }
28 | }
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class10/Edge.java:
--------------------------------------------------------------------------------
1 | package class10;
2 |
3 | public class Edge {
4 | public int weight;
5 | public Node from;
6 | public Node to;
7 |
8 | public Edge(int weight, Node from, Node to) {
9 | this.weight = weight;
10 | this.from = from;
11 | this.to = to;
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class10/Graph.java:
--------------------------------------------------------------------------------
1 | package class10;
2 |
3 | import java.util.HashMap;
4 | import java.util.HashSet;
5 |
6 | public class Graph {
7 | public HashMap nodes;
8 | public HashSet edges;
9 |
10 | public Graph() {
11 | nodes = new HashMap<>();
12 | edges = new HashSet<>();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class10/Node.java:
--------------------------------------------------------------------------------
1 | package class10;
2 |
3 | import java.util.ArrayList;
4 |
5 | // 点结构的描述 A 0
6 | public class Node {
7 | public int value;
8 | public int in;
9 | public int out;
10 | public ArrayList nexts;
11 | public ArrayList edges;
12 |
13 | public Node(int value) {
14 | this.value = value;
15 | in = 0;
16 | out = 0;
17 | nexts = new ArrayList<>();
18 | edges = new ArrayList<>();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/左程云算法 源码/algorithmbasic2020-master/src/class11/Code04_ReverseStackUsingRecursive.java:
--------------------------------------------------------------------------------
1 | package class11;
2 |
3 | import java.util.Stack;
4 |
5 | public class Code04_ReverseStackUsingRecursive {
6 |
7 | public static void reverse(Stack stack) {
8 | if (stack.isEmpty()) {
9 | return;
10 | }
11 | int i = f(stack);
12 | reverse(stack);
13 | stack.push(i);
14 | }
15 |
16 | public static int f(Stack stack) {
17 | int result = stack.pop();
18 | if (stack.isEmpty()) {
19 | return result;
20 | } else {
21 | int last = f(stack);
22 | stack.push(result);
23 | return last;
24 | }
25 | }
26 |
27 | public static void main(String[] args) {
28 | Stack test = new Stack();
29 | test.push(1);
30 | test.push(2);
31 | test.push(3);
32 | test.push(4);
33 | test.push(5);
34 | reverse(test);
35 | while (!test.isEmpty()) {
36 | System.out.println(test.pop());
37 | }
38 |
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2021_12_3_week/Code02_BinaryNegate.java:
--------------------------------------------------------------------------------
1 | package class_2021_12_3_week;
2 |
3 | //测试链接 : https://www.nowcoder.com/test/33701596/summary
4 | //本题目为第2题
5 | public class Code02_BinaryNegate {
6 |
7 | public static String maxLexicographical(String num) {
8 | char[] arr = num.toCharArray();
9 | int i = 0;
10 | while (i < arr.length) {
11 | if (arr[i] == '0') {
12 | break;
13 | }
14 | i++;
15 | }
16 | while(i < arr.length) {
17 | if(arr[i] == '1') {
18 | break;
19 | }
20 | arr[i++] = '1';
21 | }
22 | return String.valueOf(arr);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2022_01_2_week/Code01_StringCounts.java:
--------------------------------------------------------------------------------
1 | package class_2022_01_2_week;
2 |
3 | // 给定一个非常大的List list
4 | // 每一个字符串类似 : "hello,world,have,hello,world"
5 | // 这一个字符串中,有2个hello,2个world,1个have
6 | // 请设计一种多线程处理方案,统计list中每一个字符串,切分出来的单词数量,并且汇总
7 | // 最终返回一个HashMap表示每个字符串在list中一共出现几次
8 | public class Code01_StringCounts {
9 |
10 | // 多线程设计 + 算法
11 | // 本题没有代码实现,会在课上讲述思路
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2022_01_4_week/Code04_BattleshipsInABoard.java:
--------------------------------------------------------------------------------
1 | package class_2022_01_4_week;
2 |
3 | // 来自米哈游
4 | // 测试链接 : https://leetcode.com/problems/battleships-in-a-board/
5 | public class Code04_BattleshipsInABoard {
6 |
7 | public static int countBattleships(char[][] m) {
8 | int ans = 0;
9 | for (int i = 0; i < m.length; i++) {
10 | for (int j = 0; j < m[0].length; j++) {
11 | if ((m[i][j] == 'X')
12 | && (i == 0 || m[i - 1][j] != 'X')
13 | && (j == 0 || m[i][j - 1] != 'X')) {
14 | ans++;
15 | }
16 | }
17 | }
18 | return ans;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2022_02_2_week/Code04_ReachingPoints.java:
--------------------------------------------------------------------------------
1 | package class_2022_02_2_week;
2 |
3 | // 测试链接 : https://leetcode.com/problems/reaching-points/
4 | public class Code04_ReachingPoints {
5 |
6 | // 会超时,但是揭示了大思路
7 | public static boolean reachingPoints1(int sx, int sy, int tx, int ty) {
8 | while (tx != ty) {
9 | if (tx < ty) {
10 | ty -= tx;
11 | } else {
12 | tx -= ty;
13 | }
14 | if (sx == tx && sy == ty) {
15 | return true;
16 | }
17 | }
18 | return false;
19 | }
20 |
21 | // 对大体思路的优化
22 | // s ( 5, 10)
23 | // t (100, 65)
24 | public static boolean reachingPoints2(int sx, int sy, int tx, int ty) {
25 | while (sx < tx && sy < ty) {
26 | if (tx < ty) {
27 | ty %= tx;
28 | } else {
29 | tx %= ty;
30 | }
31 | }
32 | // 1) startx >= tx
33 | // 2) starty >= ty
34 | return (sx == tx && sy <= ty && (ty - sy) % sx == 0)
35 | || (sy == ty && sx <= tx && (tx - sx) % sy == 0);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2022_02_3_week/Code05_StoneGameIX.java:
--------------------------------------------------------------------------------
1 | package class_2022_02_3_week;
2 |
3 | // 测试链接 : https://leetcode.com/problems/stone-game-ix/
4 | public class Code05_StoneGameIX {
5 |
6 | public static boolean stoneGameIX(int[] stones) {
7 | int[] counts = new int[3];
8 | for (int num : stones) {
9 | counts[num % 3]++;
10 | }
11 | return counts[0] % 2 == 0
12 | ? counts[1] != 0 && counts[2] != 0
13 | : Math.abs(counts[1] - counts[2]) > 2;
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2022_03_4_week/Code06_LongestContinuousTrees.java:
--------------------------------------------------------------------------------
1 | package class_2022_03_4_week;
2 |
3 | // 来自学员问题
4 | // 给定一个数字n,表示一开始有编号1~n的树木,列成一条直线
5 | // 给定一个有序数组arr,表示现在哪些树已经没了,arr[i]一定在[1,n]范围
6 | // 给定一个数字m,表示你可以补种多少棵树
7 | // 返回补种之后,最长的连续树木,有多少棵
8 | public class Code06_LongestContinuousTrees {
9 |
10 | public static int longestTrees(int n, int m, int[] arr) {
11 | int ans = 0;
12 | int start = 1;
13 | for (int i = 0, j = m; j < arr.length; i++, j++) {
14 | ans = Math.max(ans, arr[j] - start);
15 | start = arr[i] + 1;
16 | }
17 | ans = Math.max(ans, n - start + 1);
18 | return ans;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2022_03_5_week/Code04_KillAllSameTime.java:
--------------------------------------------------------------------------------
1 | package class_2022_03_5_week;
2 |
3 | // 来自网易
4 | // 我军一起干掉敌人的最少移动数
5 | // km算法的又一个题
6 | // 给定一个矩阵int[][] matrix
7 | // matrix[i][j] == -2,代表此处(i,j)有山脉,无法通行
8 | // matrix[i][j] == -1,代表此处(i,j)是一个敌军
9 | // matrix[i][j] == 0,代表此处(i,j)是空地,可以自由行动
10 | // matrix[i][j] > 0,代表此处(i,j)是一个我军,行动能力就是matrix[i][j]
11 | // 我军只能上、下、左、右移动,只可以穿过同样是我军的地点和空地的地点,但是最多移动matrix[i][j]步
12 | // 任何一个我军都不能穿过山脉,任何一个我军可以来到敌军的位置,表示消灭了敌军,但是如果这么做了,这个我军就不能再移动了
13 | // 你可以任意决定所有我军的行动策略,每一步你都可以随意选择一个友军移动随意方向的,但是必须合法。
14 | // 如果你可以让所有我军在消耗完自身的行动能力之前,消灭所有的敌军,请返回总距离的最小值
15 | // 如果你就是无法消灭所有敌军,返回-1
16 | public class Code04_KillAllSameTime {
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2022_06_2_week/Code02_Solution.HEIC:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2022_06_2_week/Code02_Solution.HEIC
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2022_08_1_week/Code02_WaterKing.java:
--------------------------------------------------------------------------------
1 | package class_2022_08_1_week;
2 |
3 | // 找到数组中的水王数
4 | // 本题来自,大厂刷题班,23节
5 | // 为了讲述下一个题,才重新讲述这个题
6 | // 比较简单
7 | public class Code02_WaterKing {
8 |
9 | public static int waterKing(int[] arr) {
10 | int cand = 0;
11 | int hp = 0;
12 | for (int i = 0; i < arr.length; i++) {
13 | if (hp == 0) {
14 | cand = arr[i];
15 | hp = 1;
16 | } else if (arr[i] == cand) {
17 | hp++;
18 | } else {
19 | hp--;
20 | }
21 | }
22 | if (hp == 0) {
23 | return -1;
24 | }
25 | hp = 0;
26 | for (int i = 0; i < arr.length; i++) {
27 | if (arr[i] == cand) {
28 | hp++;
29 | }
30 | }
31 | return hp > arr.length / 2 ? cand : -1;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2022_08_4_week/Code01_MaxXFromStock.java:
--------------------------------------------------------------------------------
1 | package class_2022_08_4_week;
2 |
3 | // 来自神策
4 | // 给定一个数组arr,表示连续n天的股价,数组下标表示第几天
5 | // 指标X:任意两天的股价之和 - 此两天间隔的天数
6 | // 比如
7 | // 第3天,价格是10
8 | // 第9天,价格是30
9 | // 那么第3天和第9天的指标X = 10 + 30 - (9 - 3) = 34
10 | // 返回arr中最大的指标X
11 | // 时间复杂度O(N)
12 | public class Code01_MaxXFromStock {
13 |
14 | public static int maxX(int[] arr) {
15 | if (arr == null || arr.length < 2) {
16 | return -1;
17 | }
18 | // 0 + arr[0]
19 | int preBest = arr[0];
20 | int ans = 0;
21 | for (int i = 1; i < arr.length; i++) {
22 | ans = Math.max(ans, arr[i] - i + preBest);
23 | preBest = Math.max(preBest, arr[i] + i);
24 | }
25 | return ans;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2022_11_5_week/Code03_SumOfSubSequenceWidths.java:
--------------------------------------------------------------------------------
1 | package class_2022_11_5_week;
2 |
3 | import java.util.Arrays;
4 |
5 | // 一个序列的 宽度 定义为该序列中最大元素和最小元素的差值。
6 | // 给你一个整数数组 nums ,返回 nums 的所有非空 子序列 的 宽度之和
7 | // 由于答案可能非常大,请返回对 109 + 7 取余 后的结果。
8 | // 子序列 定义为从一个数组里删除一些(或者不删除)元素,
9 | // 但不改变剩下元素的顺序得到的数组
10 | // 例如,[3,6,2,7] 就是数组 [0,3,1,6,2,2,7] 的一个子序列。
11 | // 测试链接 : https://leetcode.cn/problems/sum-of-subsequence-widths/
12 | public class Code03_SumOfSubSequenceWidths {
13 |
14 | public static int sumSubseqWidths(int[] nums) {
15 | Arrays.sort(nums);
16 | int mod = 1000000007;
17 | long ans = 0;
18 | long A = 0;
19 | long B = 0;
20 | long C = 1;
21 | long D = C;
22 | for (int i = 1; i < nums.length; i++) {
23 | A = (D * nums[i]) % mod;
24 | B = (B * 2 + nums[i - 1]) % mod;
25 | ans = (ans + A - B + mod) % mod;
26 | C = (C * 2) % mod;
27 | D = (D + C) % mod;
28 | }
29 | return (int) (ans);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2023_01_1_week/Code01_KthMissingPositiveNumber.java:
--------------------------------------------------------------------------------
1 | package class_2023_01_1_week;
2 |
3 | // 给你一个 严格升序排列 的正整数数组 arr 和一个整数 k 。
4 | // 请你找到这个数组里第 k 个缺失的正整数。
5 | // 测试链接 : https://leetcode.cn/problems/kth-missing-positive-number/
6 | public class Code01_KthMissingPositiveNumber {
7 |
8 | public int findKthPositive(int[] arr, int k) {
9 | int l = 0;
10 | int r = arr.length - 1;
11 | int m = 0;
12 | int find = arr.length;
13 | while (l <= r) {
14 | m = (l + r) / 2;
15 | if (arr[m] - (m + 1) >= k) {
16 | find = m;
17 | r = m - 1;
18 | } else {
19 | l = m + 1;
20 | }
21 | }
22 | int preValue = find == 0 ? 0 : arr[find - 1];
23 | int under = preValue - find;
24 | return preValue + (k - under);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2023_01_1_week/Code02_NthMagicalNumber.java:
--------------------------------------------------------------------------------
1 | package class_2023_01_1_week;
2 |
3 | // 一个正整数如果能被 a 或 b 整除,那么它是神奇的。
4 | // 给定三个整数 n , a , b ,返回第 n 个神奇的数字。
5 | // 因为答案可能很大,所以返回答案 对 10^9 + 7 取模 后的值。
6 | // 测试链接 : https://leetcode.cn/problems/nth-magical-number/
7 | public class Code02_NthMagicalNumber {
8 |
9 | public static int nthMagicalNumber(int n, int a, int b) {
10 | // 求a和b的最小公倍数
11 | long lcm = (long) a / gcd(a, b) * b;
12 | long ans = 0;
13 | // l = 0
14 | // r = (long) n * Math.min(a, b)
15 | for (long l = 0, r = (long) n * Math.min(a, b), m = 0; l <= r;) {
16 | m = (l + r) / 2;
17 | if (m / a + m / b - m / lcm >= n) {
18 | ans = m;
19 | r = m - 1;
20 | } else {
21 | l = m + 1;
22 | }
23 | }
24 | return (int) (ans % 1000000007);
25 | }
26 |
27 | public static int gcd(int a, int b) {
28 | return b == 0 ? a : gcd(b, a % b);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/每周有营养的大厂算法面试题(直播进行中,每周三晚上8点)/weekly-problems/src/class_2023_02_1_week/Code01_MinimizeDeviationInArray.java:
--------------------------------------------------------------------------------
1 | package class_2023_02_1_week;
2 |
3 | import java.util.TreeSet;
4 |
5 | // 测试链接 : https://leetcode.cn/problems/minimize-deviation-in-array/
6 | public class Code01_MinimizeDeviationInArray {
7 |
8 | public int minimumDeviation(int[] nums) {
9 | TreeSet set = new TreeSet<>();
10 | for (int num : nums) {
11 | set.add(num % 2 == 0 ? num : num * 2);
12 | }
13 | int ans = set.last() - set.first();
14 | while (ans > 0 && set.last() % 2 == 0) {
15 | int max = set.last();
16 | set.remove(max);
17 | set.add(max / 2);
18 | ans = Math.min(ans, set.last() - set.first());
19 | }
20 | return ans;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class03/Code02_DeleteGivenValue.java:
--------------------------------------------------------------------------------
1 | package class03;
2 |
3 | public class Code02_DeleteGivenValue {
4 |
5 | public static class Node {
6 | public int value;
7 | public Node next;
8 |
9 | public Node(int data) {
10 | this.value = data;
11 | }
12 | }
13 |
14 | // head = removeValue(head, 2);
15 | public static Node removeValue(Node head, int num) {
16 | // head来到第一个不需要删的位置
17 | while (head != null) {
18 | if (head.value != num) {
19 | break;
20 | }
21 | head = head.next;
22 | }
23 | // 1 ) head == null
24 | // 2 ) head != null
25 | Node pre = head;
26 | Node cur = head;
27 | while (cur != null) {
28 | if (cur.value == num) {
29 | pre.next = cur.next;
30 | } else {
31 | pre = cur;
32 | }
33 | cur = cur.next;
34 | }
35 | return head;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class03/Code08_GetMax.java:
--------------------------------------------------------------------------------
1 | package class03;
2 |
3 | public class Code08_GetMax {
4 |
5 | // 求arr中的最大值
6 | public static int getMax(int[] arr) {
7 | return process(arr, 0, arr.length - 1);
8 | }
9 |
10 | // arr[L..R]范围上求最大值 L ... R N
11 | public static int process(int[] arr, int L, int R) {
12 | // arr[L..R]范围上只有一个数,直接返回,base case
13 | if (L == R) {
14 | return arr[L];
15 | }
16 | // L...R 不只一个数
17 | // mid = (L + R) / 2
18 | int mid = L + ((R - L) >> 1); // 中点 1
19 | int leftMax = process(arr, L, mid);
20 | int rightMax = process(arr, mid + 1, R);
21 | return Math.max(leftMax, rightMax);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class07/Inner.java:
--------------------------------------------------------------------------------
1 | package class07;
2 |
3 | public class Inner {
4 | public T value;
5 |
6 | public Inner(T v) {
7 | value = v;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class11/Code07_PaperFolding.java:
--------------------------------------------------------------------------------
1 | package class11;
2 |
3 | public class Code07_PaperFolding {
4 |
5 | public static void printAllFolds(int N) {
6 | process(1, N, true);
7 | System.out.println();
8 | }
9 |
10 | // 当前你来了一个节点,脑海中想象的!
11 | // 这个节点在第i层,一共有N层,N固定不变的
12 | // 这个节点如果是凹的话,down = T
13 | // 这个节点如果是凸的话,down = F
14 | // 函数的功能:中序打印以你想象的节点为头的整棵树!
15 | public static void process(int i, int N, boolean down) {
16 | if (i > N) {
17 | return;
18 | }
19 | process(i + 1, N, true);
20 | System.out.print(down ? "凹 " : "凸 ");
21 | process(i + 1, N, false);
22 | }
23 |
24 | public static void main(String[] args) {
25 | int N = 4;
26 | printAllFolds(N);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class16/Code01_BFS.java:
--------------------------------------------------------------------------------
1 | package class16;
2 |
3 | import java.util.HashSet;
4 | import java.util.LinkedList;
5 | import java.util.Queue;
6 |
7 | public class Code01_BFS {
8 |
9 | // 从node出发,进行宽度优先遍历
10 | public static void bfs(Node start) {
11 | if (start == null) {
12 | return;
13 | }
14 | Queue queue = new LinkedList<>();
15 | HashSet set = new HashSet<>();
16 | queue.add(start);
17 | set.add(start);
18 | while (!queue.isEmpty()) {
19 | Node cur = queue.poll();
20 | System.out.println(cur.value);
21 | for (Node next : cur.nexts) {
22 | if (!set.contains(next)) {
23 | set.add(next);
24 | queue.add(next);
25 | }
26 | }
27 | }
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class16/Code02_DFS.java:
--------------------------------------------------------------------------------
1 | package class16;
2 |
3 | import java.util.HashSet;
4 | import java.util.Stack;
5 |
6 | public class Code02_DFS {
7 |
8 | public static void dfs(Node node) {
9 | if (node == null) {
10 | return;
11 | }
12 | Stack stack = new Stack<>();
13 | HashSet set = new HashSet<>();
14 | stack.add(node);
15 | set.add(node);
16 | System.out.println(node.value);
17 | while (!stack.isEmpty()) {
18 | Node cur = stack.pop();
19 | for (Node next : cur.nexts) {
20 | if (!set.contains(next)) {
21 | stack.push(cur);
22 | stack.push(next);
23 | set.add(next);
24 | System.out.println(next.value);
25 | break;
26 | }
27 | }
28 | }
29 | }
30 |
31 |
32 |
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class16/Edge.java:
--------------------------------------------------------------------------------
1 | package class16;
2 |
3 | public class Edge {
4 | public int weight;
5 | public Node from;
6 | public Node to;
7 |
8 | public Edge(int weight, Node from, Node to) {
9 | this.weight = weight;
10 | this.from = from;
11 | this.to = to;
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class16/Graph.java:
--------------------------------------------------------------------------------
1 | package class16;
2 |
3 | import java.util.HashMap;
4 | import java.util.HashSet;
5 |
6 | public class Graph {
7 | public HashMap nodes;
8 | public HashSet edges;
9 |
10 | public Graph() {
11 | nodes = new HashMap<>();
12 | edges = new HashSet<>();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class16/Node.java:
--------------------------------------------------------------------------------
1 | package class16;
2 |
3 | import java.util.ArrayList;
4 |
5 | // 点结构的描述
6 | public class Node {
7 | public int value;
8 | public int in;
9 | public int out;
10 | public ArrayList nexts;
11 | public ArrayList edges;
12 |
13 | public Node(int value) {
14 | this.value = value;
15 | in = 0;
16 | out = 0;
17 | nexts = new ArrayList<>();
18 | edges = new ArrayList<>();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class17/Code05_ReverseStackUsingRecursive.java:
--------------------------------------------------------------------------------
1 | package class17;
2 |
3 | import java.util.Stack;
4 |
5 | public class Code05_ReverseStackUsingRecursive {
6 |
7 | public static void reverse(Stack stack) {
8 | if (stack.isEmpty()) {
9 | return;
10 | }
11 | int i = f(stack);
12 | reverse(stack);
13 | stack.push(i);
14 | }
15 |
16 | // 栈底元素移除掉
17 | // 上面的元素盖下来
18 | // 返回移除掉的栈底元素
19 | public static int f(Stack stack) {
20 | int result = stack.pop();
21 | if (stack.isEmpty()) {
22 | return result;
23 | } else {
24 | int last = f(stack);
25 | stack.push(result);
26 | return last;
27 | }
28 | }
29 |
30 | public static void main(String[] args) {
31 | Stack test = new Stack();
32 | test.push(1);
33 | test.push(2);
34 | test.push(3);
35 | test.push(4);
36 | test.push(5);
37 | reverse(test);
38 | while (!test.isEmpty()) {
39 | System.out.println(test.pop());
40 | }
41 |
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class17/Edge.java:
--------------------------------------------------------------------------------
1 | package class17;
2 |
3 | public class Edge {
4 | public int weight;
5 | public Node from;
6 | public Node to;
7 |
8 | public Edge(int weight, Node from, Node to) {
9 | this.weight = weight;
10 | this.from = from;
11 | this.to = to;
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class17/Graph.java:
--------------------------------------------------------------------------------
1 | package class17;
2 |
3 | import java.util.HashMap;
4 | import java.util.HashSet;
5 |
6 | public class Graph {
7 | public HashMap nodes;
8 | public HashSet edges;
9 |
10 | public Graph() {
11 | nodes = new HashMap<>();
12 | edges = new HashSet<>();
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class17/Node.java:
--------------------------------------------------------------------------------
1 | package class17;
2 |
3 | import java.util.ArrayList;
4 |
5 | // 点结构的描述
6 | public class Node {
7 | public int value;
8 | public int in;
9 | public int out;
10 | public ArrayList nexts;
11 | public ArrayList edges;
12 |
13 | public Node(int value) {
14 | this.value = value;
15 | in = 0;
16 | out = 0;
17 | nexts = new ArrayList<>();
18 | edges = new ArrayList<>();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class34/ReadMe.java:
--------------------------------------------------------------------------------
1 | // 本章并无code,因为资源限制类题目输入需要的条件较多并且真的实现代码量巨大
2 | // 面试中这类题目出现也就和面试官聊解法,不会有代码实现的要求
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class38/Code01_AppleMinBags.java:
--------------------------------------------------------------------------------
1 | package class38;
2 |
3 | public class Code01_AppleMinBags {
4 |
5 | public static int minBags(int apple) {
6 | if (apple < 0) {
7 | return -1;
8 | }
9 | int bag8 = (apple >> 3);
10 | int rest = apple - (bag8 << 3);
11 | while(bag8 >= 0) {
12 | // rest 个
13 | if(rest % 6 ==0) {
14 | return bag8 + (rest / 6);
15 | } else {
16 | bag8--;
17 | rest += 8;
18 | }
19 | }
20 | return -1;
21 | }
22 |
23 | public static int minBagAwesome(int apple) {
24 | if ((apple & 1) != 0) { // 如果是奇数,返回-1
25 | return -1;
26 | }
27 | if (apple < 18) {
28 | return apple == 0 ? 0 : (apple == 6 || apple == 8) ? 1
29 | : (apple == 12 || apple == 14 || apple == 16) ? 2 : -1;
30 | }
31 | return (apple - 18) / 8 + 3;
32 | }
33 |
34 | public static void main(String[] args) {
35 | for(int apple = 1; apple < 200;apple++) {
36 | System.out.println(apple + " : "+ minBags(apple));
37 | }
38 |
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/算法和数据结构体系学习班/algorithmbasic2020/src/class44/DC3_Algorithm.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shuhongfan/Data_Structure_Demo03/2a93620cb36f9684567e9962d33e1dc993ef30d1/算法和数据结构体系学习班/algorithmbasic2020/src/class44/DC3_Algorithm.pdf
--------------------------------------------------------------------------------
/算法和数据结构新手班/algorithm-primary/src/class01/Code02_SumOfFactorial.java:
--------------------------------------------------------------------------------
1 | package class01;
2 |
3 | public class Code02_SumOfFactorial {
4 |
5 | public static long f1(int N) {
6 | long ans = 0;
7 | for (int i = 1; i <= N; i++) {
8 | ans += factorial(i);
9 | }
10 | return ans;
11 | }
12 |
13 | public static long factorial(int N) {
14 | long ans = 1;
15 | for (int i = 1; i <= N; i++) {
16 | ans *= i;
17 | }
18 | return ans;
19 | }
20 |
21 | public static long f2(int N) {
22 | long ans = 0;
23 | long cur = 1;
24 | for (int i = 1; i <= N; i++) {
25 | cur = cur * i;
26 | ans += cur;
27 | }
28 | return ans;
29 | }
30 |
31 | public static void main(String[] args) {
32 | int N = 10;
33 | System.out.println(f1(N));
34 | System.out.println(f2(N));
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/算法和数据结构新手班/algorithm-primary/src/class02/Code01_PreSum.java:
--------------------------------------------------------------------------------
1 | package class02;
2 |
3 | public class Code01_PreSum {
4 |
5 | public static class RangeSum1 {
6 |
7 | private int[] arr;
8 |
9 | public RangeSum1(int[] array) {
10 | arr = array;
11 | }
12 |
13 | public int rangeSum(int L, int R) {
14 | int sum = 0;
15 | for (int i = L; i <= R; i++) {
16 | sum += arr[i];
17 | }
18 | return sum;
19 | }
20 |
21 | }
22 |
23 | public static class RangeSum2 {
24 |
25 | private int[] preSum;
26 |
27 | public RangeSum2(int[] array) {
28 | int N = array.length;
29 | preSum = new int[N];
30 | preSum[0] = array[0];
31 | for (int i = 1; i < N; i++) {
32 | preSum[i] = preSum[i - 1] + array[i];
33 | }
34 | }
35 |
36 | public int rangeSum(int L, int R) {
37 | return L == 0 ? preSum[R] : preSum[R] - preSum[L - 1];
38 | }
39 |
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/算法和数据结构新手班/algorithm-primary/src/class04/Code06_MergeTwoSortedLinkedList.java:
--------------------------------------------------------------------------------
1 | package class04;
2 |
3 | // 测试链接:https://leetcode.com/problems/merge-two-sorted-lists
4 | public class Code06_MergeTwoSortedLinkedList {
5 |
6 | // 不要提交这个类
7 | public static class ListNode {
8 | public int val;
9 | public ListNode next;
10 | }
11 |
12 | public static ListNode mergeTwoLists(ListNode head1, ListNode head2) {
13 | if (head1 == null || head2 == null) {
14 | return head1 == null ? head2 : head1;
15 | }
16 | ListNode head = head1.val <= head2.val ? head1 : head2;
17 | ListNode cur1 = head.next;
18 | ListNode cur2 = head == head1 ? head2 : head1;
19 | ListNode pre = head;
20 | while (cur1 != null && cur2 != null) {
21 | if (cur1.val <= cur2.val) {
22 | pre.next = cur1;
23 | cur1 = cur1.next;
24 | } else {
25 | pre.next = cur2;
26 | cur2 = cur2.next;
27 | }
28 | pre = pre.next;
29 | }
30 | pre.next = cur1 != null ? cur1 : cur2;
31 | return head;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/算法和数据结构新手班/algorithm-primary/src/class06/Code02_SameTree.java:
--------------------------------------------------------------------------------
1 | package class06;
2 |
3 | // 测试链接:https://leetcode.com/problems/same-tree
4 | public class Code02_SameTree {
5 |
6 | public static class TreeNode {
7 | public int val;
8 | public TreeNode left;
9 | public TreeNode right;
10 | }
11 |
12 | public static boolean isSameTree(TreeNode p, TreeNode q) {
13 | if (p == null ^ q == null) {
14 | return false;
15 | }
16 | if (p == null && q == null) {
17 | return true;
18 | }
19 | // 都不为空
20 | return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/算法和数据结构新手班/algorithm-primary/src/class06/Code03_SymmetricTree.java:
--------------------------------------------------------------------------------
1 | package class06;
2 |
3 | // 测试链接:https://leetcode.com/problems/symmetric-tree
4 | public class Code03_SymmetricTree {
5 |
6 | public static class TreeNode {
7 | public int val;
8 | public TreeNode left;
9 | public TreeNode right;
10 | }
11 |
12 | public static boolean isSymmetric(TreeNode root) {
13 | return isMirror(root, root);
14 | }
15 |
16 | public static boolean isMirror(TreeNode h1, TreeNode h2) {
17 | if (h1 == null ^ h2 == null) {
18 | return false;
19 | }
20 | if (h1 == null && h2 == null) {
21 | return true;
22 | }
23 | return h1.val == h2.val && isMirror(h1.left, h2.right) && isMirror(h1.right, h2.left);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/算法和数据结构新手班/algorithm-primary/src/class06/Code04_MaximumDepthOfBinaryTree.java:
--------------------------------------------------------------------------------
1 | package class06;
2 |
3 | // 测试链接:https://leetcode.com/problems/maximum-depth-of-binary-tree
4 | public class Code04_MaximumDepthOfBinaryTree {
5 |
6 | public static class TreeNode {
7 | public int val;
8 | public TreeNode left;
9 | public TreeNode right;
10 | }
11 |
12 | // 以root为头的树,最大高度是多少返回!
13 | public static int maxDepth(TreeNode root) {
14 | if (root == null) {
15 | return 0;
16 | }
17 | return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------