#Smallest

786. K-th Smallest Prime Fraction

786.K-thSmallestPrimeFraction https://www.cnblogs.com/grandyang/p/9135156.html数组本身是排序的,所以固定一个数,从左向右得到的分数是逐渐减小的。使用二分查找,设定一个值,然后统计所有小于这个数的个数,如果个数小于期望的k,那么把这个...

leetcode 378. Kth Smallest Element in a Sorted Matrix

这道题求有序矩阵中第K小的元素,数组如下:二分的方法解决,时间复杂度: O(nlgX)。从左下角进行遍历classSolution{public:intkthSmallest(vector<vector<int>>&matrix,intk){intleft=matrix[0][...

leetcode 230. Kth Smallest Element in a BST

https://www.cnblogs.com/grandyang/p/4620012.html这个题其实就是中序遍历第k个数就好了,代码最好写的就是非递归的方式,在stack里面找第k个就好了。也可以使用递归的方式:classSolution{public:intkthSmallest(TreeNode*root,i...

230. Kth Smallest Element in a BST

https://www.cnblogs.com/grandyang/p/4620012.html...

1038 Recover the Smallest Number (30分)(贪心)

Givenacollectionofnumbersegments,youaresupposedtorecoverthesmallestnumberfromthem.Forexample,given{32,321,3214,0229,87},wecanrecovermanynumberssuchlike32-321-32...

图论-最短路径 floyd/dijkstra-Find the City With the Smallest Number of Neighbors at a Threshold Distance

2020-01-30 22:22:58问题描述:问题求解:解法一:floyd这个题目一看就是floyd解最合适,因为是要求多源最短路,floyd算法是最合适的,时间复杂度为O(n^3)。intinf=(int)1e9;publicintfindTheCity(intn,int[][]edges,intdist...

Smallest Range II

2020-01-21 21:43:52问题描述:问题求解:这个题目还是有点难度的,感觉很巧妙也很难想到。整体的思路如下:1.首先原问题等价于+0/+2*K2.那么res=Max-Min3.不断更新Max,Min期望得到更小的respublicintsmallestRangeII(int[]A,intK){in...
代码星球 ·2020-06-14

1038. Recover the Smallest Number (30)

Givenacollectionofnumbersegments,youaresupposedtorecoverthesmallestnumberfromthem.Forexample,given{32,321,3214,0229,87},wecanrecovermanynumberssuchlike32-321-32...