版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
soulmachinePublishedsoulmachine算法精粹算法精粹PAGE10PAGE10TableofContents介紹線性表數(shù)組RemoveDuplicatesfromSortedArrayRemoveDuplicatesfromSortedArrayIILongestConsecutiveSequence3Sum3Sum4SumRemoveElementMoveZeroesNextPermutationPermutationSequenceValidSudokuTrappingRainWaterRotateImagePlusOneClimbingStairsSetMatrixZeroesGasStationCandyMajorityElementRotateArrayContainsDuplicateContainsDuplicateIIContainsDuplicateIII
01ProductofArrayExceptSelfGameofLifeIncreasingTripletSubsequence單鏈表ReverseLinkedListOddEvenLinkedListAddTwoNumbersReverseLinkedListIIPartitionListRemoveDuplicatesfromSortedListRemoveDuplicatesfromSortedListIIRotateListRemoveNthNodeFromEndofListSwapNodesinPairsReverseNodesink-GroupCopyListwithRandomPointerLinkedListCycleLinkedListCycleIIReorderListLRUCachePalindromeLinkedList字符串ValidPalindromeImplementstrStr()StringtoInteger(atoi)AddBinaryLongestPalindromicSubstringRegularExpressionMatchingWildcardMatchingLongestCommonPrefix
2ValidNumberIntegertoRomanRomantoIntegerCountandSayAnagramsAnagramSimplifyPathLengthofLastWordIsomorphicStringsWordPattern棧和隊(duì)列棧MinStackParenthesesLongestParenthesesLargestRectangleinHistogramEvaluateReversePolishNotationImplementStackusingQueues隊(duì)列ImplementQueueusingStacks二叉樹(shù)二叉樹(shù)的遍歷BinaryPreorderTraversalBinaryInorderTraversalBinaryPostorderTraversalBinaryLevelOrderTraversalBinaryLevelOrderTraversalIIBinaryRightSideViewInvertBinaryTreeBinarySearchTreeIterator
34BinaryTreeZigzagLevelOrderTraversalRecoverBinarySearchTreeSameTreeSymmetricTreeBalancedBinaryTreeFlattenBinaryTreetoLinkedListPopulatingNextRightPointersinEachNodeII二叉樹(shù)的構(gòu)建ConstructBinaryfromPreorderandInorderTraversalConstructBinaryfromInorderandPostorderTraversal二叉查找樹(shù)UniqueBinarySearchTreesUniqueBinarySearchTreesIIValidateBinarySearchTreeConvertSortedArraytoBinarySearchTreeConvertSortedListtoBinarySearchTreeLCAofBSTKthSmallestElementinaBST二叉樹(shù)的遞歸MinimumDepthofBinaryMaximumDepthofBinaryPathSumPathSumIIBinaryTreeMaximumPathSumPopulatingNextRightPointersinEachNodeSumRoottoLeafNumbersLCAofBinaryTree線段樹(shù)RangeSumQuery-Mutable排序
5插入排序InsertionSortList歸并排序MergeTwoSortedArraysMergeTwoSortedListsMergekSortedListsSortList快速排序SortColorsKthLargestElementinanArray桶排序FirstMissingPositive計(jì)數(shù)排序H-Index基數(shù)排序MaximumGap其他LargestNumber小結(jié)查找SearchforaRangeSearchInsertPositionSearchinRotatedSortedArraySearchinRotatedSortedArrayIISearcha2DMatrixSearcha2DMatrixIIFindMinimuminRotatedSortedArrayFindMinimuminRotatedSortedArrayIIMedianofTwoSortedArraysH-IndexII
6暴力枚舉法SubsetsSubsetsIIPermutationsPermutationsIICombinationsLetterCombinationsofaPhoneNumber廣度優(yōu)先搜索WordLadderWordLadderIISurroundedRegions總結(jié)深度優(yōu)先搜索AdditiveNumberPalindromePartitioningUniquePathsUniquePathsIIN-QueensN-QueensIIRestoreIPAddressesCombinationSumCombinationSumIICombinationSumIIIGenerateParenthesesSudokuSolverWordSearch總結(jié)分治法Pow(x,n)Sqrt(x)
789貪心法JumpGameJumpGameIIBestTimetoBuyandSellStockBestTimetoBuyandSellStockIILongestSubstringWithoutRepeatingCharactersContainerWithMostPatchingArray動(dòng)態(tài)規(guī)劃TriangleMaximumSubarrayMaximumProductSubarrayLongestIncreasingSubsequencePalindromePartitioningIIMaximalRectangleBestTimetoBuyandSellStockIIIBestTimetoBuyandSellStockIVBestTimetoBuyandSellStockwithCooldownInterleavingStringScrambleStringMinimumPathSumEditDistanceDecodeWaysDistinctSubsequencesWordBreakWordBreakIIDungeonGameHouseRobberHouseRobberIIHouseRobberIII
RangeSumQuery-ImmutableRangeSumQuery2D-Immutable圖CloneGraph位操作ReverseBitsRepeatedDNASequencesNumberof1BitsGrayCodeSingleNumberSingleNumberIISingleNumberIIIPowerofMissingNumberMaximumProductofWordLengthsBitwiseANDofNumbersRangePowerofThreeRectangleArea數(shù)論HappyNumberUglyNumberUglyNumberIISuperUglyNumberFractiontoRecurringDecimalFactorialTrailingZeroesNimGame模擬ReverseIntegerPalindromeNumberInsertInterval
MergeIntervalsMinimumWindowSubstringMultiplyStringsSubstringwithConcatenationofAllWordsPascal'sTrianglePascal'sTriangleIISpiralMatrixSpiralMatrixIIZigZagConversionDivideIntegersJustificationMaxPointsonaLine
16.416.516.616.716.816.916.1016.1216.1316.1416.15算法精粹算法精粹介紹PAGE19介紹PAGE19算法精粹——舉一反三,拋棄題海戰(zhàn)術(shù)剛接觸ACM算法競(jìng)賽的新手。背后有強(qiáng)大的AlgoHub支持。(即將上線上在線判斷代碼。這樣的一大好處是,讀者可以邊看書(shū),邊實(shí)現(xiàn)自己的代碼,然后提交到網(wǎng)站上驗(yàn)證自己的想法是否正確。AlgoHub的使命是成為最好的算法學(xué)習(xí)和交流平臺(tái)。AlgoHubPOJ,ZOJ,leetcodeHackerRank等網(wǎng)站的經(jīng)典題目(一些質(zhì)量不高的題目則忽略),AlgoHub有非常簡(jiǎn)單的加題系統(tǒng),用戶(hù)不需要寫(xiě)一行代碼即可自己添加題目,所以AlgoHub的題庫(kù)還在飛速增長(zhǎng)中。每道題都有完整的代碼。提下盡可能簡(jiǎn)短,方面讀者在面試中能快速寫(xiě)出來(lái)。每道題都有多種解法。反三,讓讀者觸類(lèi)旁通。本書(shū)支持多種主流編程語(yǔ)言。目前支持Java,C++,C#,Python,Ruby,JavaScript,Swift,Scala,Clojure,將來(lái)還會(huì)支持更多編程語(yǔ)言。在線閱讀/book/soulmachine/algorithm-essentials/內(nèi)容目錄介紹線性表數(shù)組RemoveDuplicatesfromSortedArrayRemoveDuplicatesfromSortedArrayIILongestConsecutiveSequence3Sum3Sum4SumRemoveElementMoveZeroesNextPermutationPermutationSequenceValidSudokuTrappingRainWaterRotateImagePlusOneClimbingStairsSetMatrixZeroesGasStationCandyMajorityElementRotateArrayContainsDuplicateContainsDuplicateIIContainsDuplicateIIIProductofArrayExceptSelfGameofLifeIncreasingTripletSubsequence單鏈表ReverseLinkedListOddEvenLinkedList
AddTwoNumbersReverseLinkedListIIPartitionListRemoveDuplicatesfromSortedListRemoveDuplicatesfromSortedListIIRotateListRemoveNthNodeFromEndofListSwapNodesinPairsReverseNodesink-GroupCopyListwithRandomPointerLinkedListCycleLinkedListCycleIIReorderListLRUCachePalindromeLinkedListValidPalindromeImplementstrStr()StringtoInteger(atoi)AddBinaryLongestPalindromicSubstringRegularExpressionMatchingWildcardMatchingLongestCommonPrefixValidNumberIntegertoRomanRomantoIntegerCountandSayAnagramsAnagramSimplifyPathLengthofLastWordIsomorphicStringsWordPattern棧和隊(duì)列棧MinStackParenthesesLongestParenthesesLargestRectangleinHistogramEvaluateReversePolishNotationImplementStackusingQueues隊(duì)列ImplementQueueusingStacks二叉樹(shù)二叉樹(shù)的遍歷BinaryPreorderTraversalBinaryInorderTraversalBinaryPostorderTraversalBinaryLevelOrderTraversalBinaryLevelOrderTraversalIIBinaryRightSideViewInvertBinaryTreeBinarySearchTreeIteratorBinaryTreeZigzagLevelOrderTraversalRecoverBinarySearchTreeSameTreeSymmetricTreeBalancedBinaryTreeFlattenBinaryTreetoLinkedListPopulatingNextRightPointersinEachNodeII二叉樹(shù)的構(gòu)建ConstructBinaryTreefromPreorderandInorderTraversalConstructBinaryTreefromInorderandPostorderTraversal二叉查找樹(shù)UniqueBinarySearchTreesUniqueBinarySearchTreesIIValidateBinarySearchTreeConvertSortedArraytoBinarySearchTreeConvertSortedListtoBinarySearchTreeLCAofBSTKthSmallestElementinaBST二叉樹(shù)的遞歸MinimumDepthofBinaryMaximumDepthofBinaryPathSumPathSumIIBinaryTreeMaximumPathSumPopulatingNextRightPointersinEachNodeSumRoottoLeafNumbersLCAofBinaryTree線段樹(shù)RangeSumQuery-Mutable排序插入排序InsertionSortList歸并排序MergeTwoSortedArraysMergeTwoSortedListsMergekSortedListsSortList快速排序SortColorsKthLargestElementinanArray桶排序FirstMissingPositive計(jì)數(shù)排序H-Index基數(shù)排序MaximumGap其他LargestNumber小結(jié)查找SearchforaRangeSearchInsertPositionSearchinRotatedSortedArraySearchinRotatedSortedArrayIISearcha2DMatrixSearcha2DMatrixIIFindMinimuminRotatedSortedArrayFindMinimuminRotatedSortedArrayIIMedianofTwoSortedArraysH-IndexII暴力枚舉法SubsetsSubsetsIIPermutationsPermutationsIICombinationsLetterCombinationsofaPhoneNumber廣度優(yōu)先搜索WordLadderWordLadderIISurroundedRegions總結(jié)深度優(yōu)先搜索AdditiveNumberPalindromePartitioningUniquePathsUniquePathsIIN-QueensN-QueensIIRestoreIPAddressesCombinationSumCombinationSumIICombinationSumIIIGenerateParenthesesSudokuSolverWordSearch總結(jié)分治法Pow(x,n)Sqrt(x)貪心法JumpGameJumpGameIIBestTimetoBuyandSellStockBestTimetoBuyandSellStockIILongestSubstringWithoutRepeatingCharactersContainerWithMostPatchingArray動(dòng)態(tài)規(guī)劃TriangleMaximumSubarrayMaximumProductSubarrayLongestIncreasingSubsequencePalindromePartitioningIIMaximalRectangleBestTimetoBuyandSellStockIIIBestTimetoBuyandSellStockIVBestTimetoBuyandSellStockwithCooldownInterleavingStringScrambleStringMinimumPathSumEditDistanceDecodeWaysDistinctSubsequencesWordBreakWordBreakIIDungeonGameHouseRobberHouseRobberIIHouseRobberIIIRangeSumQuery-ImmutableRangeSumQuery2D-Immutable圖CloneGraph位操作ReverseBitsRepeatedDNASequencesNumberof1BitsGrayCodeSingleNumberSingleNumberIISingleNumberIIIPowerofMissingNumberMaximumProductofWordLengthsBitwiseANDofNumbersRangePowerofThreeRectangleArea數(shù)論HappyNumberUglyNumberUglyNumberIISuperUglyNumberFractiontoRecurringDecimalFactorialTrailingZeroesNimGame模擬ReverseIntegerPalindromeNumberInsertIntervalMergeIntervalsMinimumWindowSubstringMultiplyStringsSubstringwithConcatenationofAllWordsPascal'sTrianglePascal'sTriangleIISpiralMatrixSpiralMatrixIIZigZagConversionDivideIntegersJustificationMaxPointsonaLineCommunityQQ237669375Github:/soulmachine/algorithm-essentials微博:@靈魂機(jī)器LicenseBookLicense:CCBY-SA3.0License算法精粹算法精粹線性表PAGE20線性表PAGE20這類(lèi)題目考察線性表的操作,例如,數(shù)組,單鏈表,雙向鏈表等。算法精粹算法精粹數(shù)組PAGE21數(shù)組PAGE21本節(jié)主要講關(guān)于數(shù)組的各種算法題。算法精粹算法精粹RemoveDuplicatesfromSortedArrayRemoveDuplicatesfromSortedArrayPAGE23RemoveDuplicatesfromSortedArray描述Givenasortedarray,removetheduplicatesinplacesuchthateachelementappearonlyonceandreturnthenewlength.Donotallocateextraspaceforanotherarray,youmustdothisinplacewithconstantmemory.Forexample,GiveninputarrayA=[1,1,2],Yourfunctionshouldreturnlength=2,andAisnow[1,2].分析無(wú)代碼//RemoveDuplicatesfromSortedArray//RemoveDuplicatesfromSortedArray//時(shí)間復(fù)雜度O(n),空間復(fù)雜度O(1)classSolution{public:intremoveDuplicates(vector<int>&nums){if(nums.empty())return0;intindex=1;for(inti=1;i<nums.size();i++){if(nums[i]!=nums[index-1])nums[index++]=nums[i];}returnindex;}};相關(guān)題目RemoveDuplicatesfromSortedArrayII算法精粹算法精粹RemoveDuplicatesfromSortedArrayIIRemoveDuplicatesfromSortedArrayIIPAGE25RemoveDuplicatesfromSortedArrayII描述Followupfor"RemoveDuplicates":Whatifduplicatesareallowedatmosttwice?Forexample,givensortedarrayA=[1,1,1,2,2,3],yourfunctionshouldreturnlength=5,andAisnow[1,1,2,2,3]分析變量即可解決。如果是沒(méi)有排序的數(shù)組,則需要引入一個(gè)hashmap來(lái)記錄出現(xiàn)次數(shù)。代碼1//RemoveDuplicatesfromSortedArrayII//RemoveDuplicatesfromSortedArrayII//Timecomplexity:O(n),SpaceComplexity:O(1)classSolution{public:intremoveDuplicates(vector<int>&nums){if(nums.size()<=2)returnnums.size();intindex=2;for(inti=2;i<nums.size();i++){if(nums[i]!=nums[index-2])nums[index++]=nums[i];}returnindex;}};代碼2下面是一個(gè)更簡(jiǎn)潔的版本。上面的代碼略長(zhǎng),不過(guò)擴(kuò)展性好一些,例如將occur2改為occur3,就變成了允許重復(fù)最多3次。};};}nums[index++]=nums[i];}returnindex;//RemoveDuplicatesfromSortedArrayII//TimeComplexity:O(n),SpaceComplexity:O(1)classSolution{public:intremoveDuplicates(vector<int>&nums){constintn=nums.size();intindex=0;for(inti=0;i<n;++i){if(i>0&&i<n-1&&nums[i]==nums[i-1]&&nucontinue;相關(guān)題目RemoveDuplicatesfromSortedArray算法精粹算法精粹LongestConsecutiveSequencePAGE27LongestConsecutiveSequencePAGE27LongestConsecutiveSequence描述Givenanunsortedarrayofintegers,findthelengthofthelongestconsecutiveelementssequence.Forexample,Given[100,4,200,1,3,2],Thelongestconsecutiveelementssequenceis[1,2,3,4].Returnitslength:4.algorithmshouldruninO(n)分析如果允許O(nlogn)的復(fù)雜度,那么可以先排序,可是本題要求O(n)。由于序列里的元素是無(wú)序的,又要求O(n),首先要想到用哈希表。張,直到不連續(xù)為止,記錄下最長(zhǎng)的長(zhǎng)度。代碼};};}intlongest=0;for(autoi:nums){intlength=1;for(intj=i-1;my_set.find(j)!=my_set.end();--my_set.erase(j);++length;}for(intj=i+1;my_set.find(j)!=my_set.end();++my_set.erase(j);++length;}longest=max(longest,length);}returnlongest;//LongestConsecutiveSequence//TimeComplexity:O(n),SpaceComplexity:O(n)classSolution{public:intlongestConsecutive(constvector<int>&nums){unordered_set<int>my_set;for(autoi:nums)my_set.insert(i);算法精
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 小練(18) Unit 5 Section 2 Using language(教學(xué)設(shè)計(jì))輕松課堂2023-2024學(xué)年新教材高中英語(yǔ)選擇性必修第四冊(cè)(外研版)
- 山西省太谷縣明星中學(xué)初中信息技術(shù)《感受信息》教案 新人教版
- 標(biāo)化工地臨時(shí)用電質(zhì)量標(biāo)準(zhǔn)
- 2022年廣西梧州中考滿(mǎn)分作文《記憶中的味道》
- 2022年廣東省中考滿(mǎn)分作文《“煞星”張老師》
- 《紅領(lǐng)巾重走一大路-準(zhǔn)備階段》第1課時(shí)(教案)-2024-2025學(xué)年六年級(jí)上冊(cè)綜合實(shí)踐活動(dòng)浙教版
- Unit 1 section B 1a-2e教學(xué)設(shè)計(jì)2024-2025學(xué)年人教版八年級(jí)上冊(cè)英語(yǔ)
- 《關(guān)注身邊的垃圾:3 垃圾流浪記》教學(xué)設(shè)計(jì)-2023-2024學(xué)年三年級(jí)下冊(cè)綜合實(shí)踐活動(dòng)滬科黔科版
- 21楓橋夜泊教學(xué)設(shè)計(jì)-2024-2025學(xué)年統(tǒng)編版語(yǔ)文五年級(jí)上冊(cè)
- 習(xí)作:學(xué)寫(xiě)倡議書(shū)(教學(xué)設(shè)計(jì))-2024-2025學(xué)年統(tǒng)編版語(yǔ)文六年級(jí)上冊(cè)
- 橫向課題合作服務(wù)協(xié)議
- 物流運(yùn)輸補(bǔ)充協(xié)議書(shū)范本
- 2024年高考語(yǔ)文新高考Ⅱ卷試卷評(píng)析及備考策略
- 高中數(shù)學(xué)必修二《第九章 統(tǒng)計(jì)》同步練習(xí)
- 中職數(shù)學(xué)基礎(chǔ)模塊上冊(cè)第1章集合1-2集合之間的關(guān)系課件
- 云南省云大附中2024年高考化學(xué)四模試卷含解析2
- 2024年中國(guó)移動(dòng)通信集團(tuán)有限公司校園招聘考試試題1套
- 《陸上風(fēng)電場(chǎng)工程概算定額》NBT 31010-2019
- 手術(shù)部位識(shí)別標(biāo)識(shí)培訓(xùn)
- 2024年中國(guó)南水北調(diào)集團(tuán)新能源投資限公司秋季校園招聘公開(kāi)引進(jìn)高層次人才和急需緊缺人才筆試參考題庫(kù)(共500題)答案詳解版
- 水利工程運(yùn)維售后服務(wù)
評(píng)論
0/150
提交評(píng)論