Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST's ...
分类:
其他好文 时间:
2017-01-05 07:50:54
阅读次数:
139
The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with the query like to simply find the k-th smallest num ...
分类:
其他好文 时间:
2016-12-27 00:25:40
阅读次数:
130
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 that it is th ...
分类:
其他好文 时间:
2016-12-23 07:40:57
阅读次数:
240
本题的特点在于两个list nums1和nums2都是已经排序好的。本题如果把所有的(i, j)组合都排序出来,再取其中最小的K个。其实靠后的很多组合根本用不到,所以效率较低,会导致算法超时。为了简便,把nums1和nums2里面的元素写成A1,A2,...,A5, B1,...,B5. 维护一个最 ...
分类:
其他好文 时间:
2016-12-22 06:47:17
阅读次数:
169
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST's ...
分类:
其他好文 时间:
2016-12-18 22:58:18
阅读次数:
190
第二遍做法:参考https://discuss.leetcode.com/topic/64624/concise-easy-to-understand-java-5ms-solution-with-explaination Actually this is a denary tree (each n ...
分类:
其他好文 时间:
2016-12-08 09:29:48
阅读次数:
163
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 that it is th ...
分类:
其他好文 时间:
2016-12-08 01:57:41
阅读次数:
168
题目地址 简要题意: 给若干组数字,每组数据是递增的在0——9之间的数,且每组数的个数不确定。对于每组数,输出由这些数组成的两个数的差的绝对值最小是多少(每个数出现且只出现一次)。 思路分析: 对于n个数,必定为分成两个位数分别为n/2和n-n/2的数时才可能取得差的绝对值最小。两组数分别进行全排列 ...
分类:
其他好文 时间:
2016-12-05 23:21:38
阅读次数:
189
You have k lists of sorted integers. Find the smallest range that includes at least one number from each of the k lists. For example, List 1: [4, 10, ...
分类:
其他好文 时间:
2016-12-03 00:37:48
阅读次数:
176