给定一个二叉搜索树,编写一个函数kthSmallest来查找其中第k个最小的元素。 注意:你可以假设k总是有效的,1≤ k ≤二叉搜索树元素个数。 进阶:如果经常修改二叉搜索树(插入/删除操作)并且你需要频繁地找到第k小值呢? 你将如何优化kthSmallest函数? 详见:https://leet ...
分类:
其他好文 时间:
2018-04-09 13:23:15
阅读次数:
212
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_3_B For a given array a1,a2,a3,...,aNa1,a2,a3,...,aN of NN elements and an integer KK, fi ...
Given a matrix of size N x M. For each row the elements are sorted in ascending order, and for each column the elements are also sorted in ascending o ...
分类:
其他好文 时间:
2018-03-29 13:27:47
阅读次数:
135
题目:找出能被两个给定参数和它们之间的连续数字整除的最小公倍数。 范围是两个数字构成的数组,两个数字不一定按数字顺序排序。 分析:首先题目的意思求一个连续数列的所有数字的最小公倍数,这连续的数字序列可能递增,也可能递减,有两种情况,为了使代码简洁, 我们将其变为一种情况,也就是递增数列,这样避免重复 ...
分类:
其他好文 时间:
2018-03-25 14:28:32
阅读次数:
168
Question: Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note tha ...
分类:
其他好文 时间:
2018-03-09 12:13:59
阅读次数:
164
题目:http://poj.org/problem?id=2718 题意: 就是输入N组数据,一组数据为,类似 【1 4 5 6 8 9】这样在0~9之间升序输入的数据,然后从这些数据中切一刀,比如 n1:【1 4 5】,n2:【6 8 9】这样,然后 abs(n1- n2),对n1 和 n2的所有 ...
分类:
其他好文 时间:
2018-03-05 20:41:59
阅读次数:
194
【链接】 "我是链接,点我呀:)" 【题意】 在这里输入题意 【题解】 尺取法。 考虑一个1..i的窗口。 里面在到达了i位置的时候恰好有1..k这些数字了。 为了更接近答案。 显然可以试着让左端点变成2.(如果还能有1..k这些数字的话。 所以有1..k这些数字之后。就让左端点尽可能往右。 然后尝 ...
分类:
其他好文 时间:
2018-02-20 20:21:00
阅读次数:
158
Given a start IP address ip and a number of ips we need to cover n, return a representation of the range as a list (of smallest possible length) of CI ...
分类:
其他好文 时间:
2018-02-11 10:43:16
阅读次数:
257
Implement a stack with min() function, which will return the smallest number in the stack. It should support push, pop and min operation all in O(1) c ...
分类:
其他好文 时间:
2018-02-04 13:56:09
阅读次数:
144
Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number quickly from the multiplication table? Given the ...
分类:
其他好文 时间:
2018-01-28 00:07:54
阅读次数:
183