问题:找出二叉搜索树种第 k 小的元素。 一个深度遍历的应用。使用递归、或者借助栈都可以实现深度遍历。本文代码使用递归实现。
分类:
其他好文 时间:
2016-01-10 11:35:01
阅读次数:
154
题目大意:按照题目中的要求构造出一个序列,找出最短的子序列,包含1~k。解题思路:先根据题目的方法构造出序列,然后用Towpointer的方法,用v[i]来记录当前[l, r]中有几个i;当r移动时,出现v[i] == 1时, c++(用来记录有几个1~k的数字);当c == k 时,就要移动l,当...
分类:
其他好文 时间:
2016-01-10 00:18:18
阅读次数:
183
Given an array of integers, find the subarray with smallest sum.Return the sum of the subarray.Have you met this question in a real interview? YesExam...
分类:
其他好文 时间:
2016-01-09 07:32:10
阅读次数:
164
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) co...
分类:
其他好文 时间:
2016-01-09 06:17:21
阅读次数:
119
Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.+----+-----------...
分类:
数据库 时间:
2016-01-02 22:20:38
阅读次数:
202
An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black pixels are connected, i.e., there is only one bla...
分类:
其他好文 时间:
2015-12-29 08:45:18
阅读次数:
133
Problem DescriptionYou are given two positive integers X and K. Return the K-th smallest positive integer Y, for which the following equation holds: X...
分类:
其他好文 时间:
2015-12-26 18:28:49
阅读次数:
165
题意:K个数组每组K个值,每次从一组中选一个,共K^k种,问前K个小的。思路:优先队列处理多路归并,每个状态含有K个元素。详见刘汝佳算法指南。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8...
分类:
其他好文 时间:
2015-12-25 18:42:11
阅读次数:
198
sed -n '21592,23591p' logperl -pi -e 's/str1/str2/g' logprstat -s size -n 10prstat -s cpu -n 10ls -lR | sort -bn +4 (smallest to largest)ls -lR | sort...
分类:
其他好文 时间:
2015-12-24 10:33:08
阅读次数:
172
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 ...
分类:
其他好文 时间:
2015-12-19 13:44:38
阅读次数:
163