文章
162. Find Peak Element
Apeakelementisanelementthatisgreaterthanitsneighbors.Givenaninputarraynums,wherenumsi≠numsi1,findapeakelementandreturni
173. Binary Search Tree Iterator
Implementaniteratoroverabinarysearchtree(BST).YouriteratorwillbeinitializedwiththerootnodeofaBST.Callingnext()willreturnthene
94. Binary Tree Inorder Traversal
Givenabinarytree,returntheinordertraversalofitsnodes&39;values.Example:<pre<codeInput:1,null,2,31\2/3O
PAT A1038
!clipboard.png(/img/bVboj1h?w1488&h501)还是贪心算法应用;建立string的数组,输入之后,两两进行比较,ab>ba,则两两交换位置,将每个string放到合适的位置,从而使得局部最优,变为整体最优;这里示例代码使用的是sort函数
PAT A1101
!clipboard.png(/img/bVbojVe?w1481&h713)这道题的题目和之前的PAT题目相同,也是采用打表的方法;先预先算好所有的元素;建立两个数组,left,right;left从左到右遍历,索引index装从左到index中最大的元素;right从右到左遍历,
165. Compare Version Numbers
Comparetwoversionnumbersversion1andversion2.Ifversion1>version2return1;ifversion1<version2return1;otherwisereturn0.Youmaya
179. Largest Number
Givenalistofnonnegativeintegers,arrangethemsuchthattheyformthelargestnumber.Example1:<pre<codeInput:10,2Output:&34;210&3
199. Binary Tree Right Side View
Givenabinarytree,imagineyourselfstandingontherightsideofit,returnthevaluesofthenodesyoucanseeorderedfromtoptobottom.Exampl
PAT A1029
!clipboard.png(/img/bVboiyX?w1496&h565)起先自己想尝试性的直接排序找中位数,内存直接超限;其实这道题可以采用归并排序的思路来做:但是示例依旧白给。。。不过还是展现了一种思想,代码如下:<pre<codeinclude<ios
93. Restore IP Addresses
Givenastringcontainingonlydigits,restoreitbyreturningallpossiblevalidIPaddresscombinations.Example:<pre<codeInput:&34;25525511
已加载文章中没有匹配内容,试试其他关键词或清空搜索。