![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
默默前行的蜗牛
Data Mining ML
展开
-
[leetcode]Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.public int findKthLargest(int[] nums, int k) {原创 2017-04-04 13:05:48 · 190 阅读 · 0 评论 -
[leetcode]Kth Smallest Element in an Array
利用QuickSelect的思想进行递归查找QuickSelect:https://en.wikipedia.org/wiki/Quickselect主要思想是借鉴QuickSort的分割思路,不同的是,QuickSelect只从一边进行遍历,以最后一个元素为pivot,将原无序数组分割为两部分The basic idea is to use Quick Select algo原创 2017-04-04 16:21:33 · 298 阅读 · 0 评论 -
[leetcode]Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number原创 2017-04-04 17:01:39 · 282 阅读 · 0 评论 -
[leetcode]230. Kth Smallest Element in a BST
BST二叉搜索树,性质:每个节点的左孩子小于根节点,右孩子大于根节点根据BST的性质,以及数组中第k大数的思想(QuickSelect分割思想),先计算当前结点的左孩子节点的个数,与k比较如果小于k-1(考虑当前节点),则第k大的数在右孩子节点如果大于k-1,则第k大的数载左孩子节点如果等于k-1,则返回当前结点的值 public int kthSmallest(Tr原创 2017-04-04 21:13:11 · 319 阅读 · 0 评论 -
[leetcode]110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe原创 2017-04-05 09:34:00 · 220 阅读 · 0 评论