




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(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),用戶不需要寫(xiě)一行代碼即可自己添加題目,所以AlgoHub的題庫(kù)還在飛速增長(zhǎng)中。每道題都有完整的代碼。提下盡可能簡(jiǎn)短,方面讀者在面試中能快速寫(xiě)出來(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這類題目考察線性表的操作,例如,數(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)益歸上傳用戶所有。
- 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ì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 浙江國(guó)企招聘2025溫州機(jī)場(chǎng)集團(tuán)招聘31人筆試參考題庫(kù)附帶答案詳解
- 保山職業(yè)學(xué)院《材料測(cè)試與研究方法》2023-2024學(xué)年第二學(xué)期期末試卷
- 江西冶金職業(yè)技術(shù)學(xué)院《社會(huì)醫(yī)學(xué)與衛(wèi)生事業(yè)管理》2023-2024學(xué)年第二學(xué)期期末試卷
- 深圳大學(xué)《數(shù)字系統(tǒng)設(shè)計(jì)基礎(chǔ)》2023-2024學(xué)年第二學(xué)期期末試卷
- 湖北三峽職業(yè)技術(shù)學(xué)院《數(shù)字媒體藝術(shù)創(chuàng)作》2023-2024學(xué)年第二學(xué)期期末試卷
- 洛陽(yáng)理工學(xué)院《微機(jī)原理及單片機(jī)應(yīng)用技術(shù)》2023-2024學(xué)年第二學(xué)期期末試卷
- 四川美術(shù)學(xué)院《專題地圖設(shè)計(jì)與編繪實(shí)驗(yàn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 內(nèi)蒙古體育職業(yè)學(xué)院《生活中的生物學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 青島遠(yuǎn)洋船員職業(yè)學(xué)院《物流系統(tǒng)規(guī)劃與設(shè)計(jì)》2023-2024學(xué)年第二學(xué)期期末試卷
- 北華航天工業(yè)學(xué)院《管理會(huì)計(jì)模擬實(shí)訓(xùn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 情侶協(xié)議書(shū)電子版簡(jiǎn)單模板
- 廣東省惠州市2025屆高三數(shù)學(xué)第一次調(diào)研考試試題
- 英語(yǔ)話中國(guó)智慧樹(shù)知到答案2024年吉林大學(xué)
- 滬教版數(shù)學(xué)三年級(jí)下冊(cè)三位數(shù)乘兩位數(shù)豎式計(jì)算題100道及答案
- 山東省2025屆高三第二次模擬考試歷史試卷含解析
- DL∕Z 860.1-2018 電力自動(dòng)化通信網(wǎng)絡(luò)和系統(tǒng) 第1部分:概論
- 2022版義務(wù)教育語(yǔ)文課程標(biāo)準(zhǔn)考試測(cè)試卷及答案(共三套)
- 2024年04月南昌市2024年第二次招考120名市級(jí)專職留置看護(hù)隊(duì)員筆試筆試歷年典型考題及考點(diǎn)研判與答案解析
- 康養(yǎng)旅游項(xiàng)目策劃方案畢業(yè)設(shè)計(jì)(2篇)
- 《陸上風(fēng)電場(chǎng)工程概算定額》NBT 31010-2019
- 《論語(yǔ)》全文原文版
評(píng)論
0/150
提交評(píng)論