文章
56. Merge Intervals
Givenacollectionofintervals,mergealloverlappingintervals.Example1:<pre<codeInput:1,3,2,6,8,10,15,18Output:1,6,8,10,
47. Permutations II
Givenacollectionofnumbersthatmightcontainduplicates,returnallpossibleuniquepermutations.Example:<pre<codeInput:1,1,2Output:
PAT A1107
!clipboard.png(/img/bVbobYg?w1498&h685)并查集的应用,但是一上来有点蒙蔽,因为这次多了一个媒介,通过活动来判断人员是否在一个集合;有一个示例思路:构建活动的集合,首次发现在该活动的人员,将对应活动索引的内容设置为该人员编号;如果后面输入还有该活动
PAT A1053
!clipboard.png(/img/bVbobL2?w1494&h841)也不难,使用DFS就能很好的解决问题;对于DFS的途中节点记录有两种方法,这个需要注意一下:1.使用vector模拟栈,每次递归的时候压栈或者弹栈,遇到符合要求的时候直接复制该栈保存;2.使用path数组,
46. Permutations
Givenacollectionofdistinctintegers,returnallpossiblepermutations.Example:<pre<codeInput:1,2,3Output:1,2,3,1,3,2,2,
40. Combination Sum II
Givenacollectionofcandidatenumbers(candidates)andatargetnumber(target),findalluniquecombinationsincandidateswherethecandidatenumb
39. Combination Sum
Givenasetofcandidatenumbers(candidates)(withoutduplicates)andatargetnumber(target),findalluniquecombinationsincandidateswherethe
PAT A1004
!clipboard.png(/img/bVbobxO?w1496&h655)还是数层数和数节点的问题,个人觉得用BFS比较好;当然用DFS也能做,具体的思路就是建立层数数组,深度遍历到x层的时候,如果是叶子节点就leafx,如果不是就不管,继续跳过;代码片段可以这样:
48. Rotate Image
Youaregivenannxn2Dmatrixrepresentinganimage.Rotatetheimageby90degrees(clockwise).Note:Youhavetorotatetheimageinplace,whichme
49. Group Anagrams
Givenanarrayofstrings,groupanagramstogether.Example:<pre<codeInput:&34;eat&34;,&34;tea&34;,&34;tan&34;,&34;ate&34;,&34;nat&
已加载文章中没有匹配内容,试试其他关键词或清空搜索。