• 等级
  • 29598 访问
  • 99 原创
  • 341 转发
  • 29593 排名
  • 12 评论
  • 2 获赞

桶排序,计数排序,基数排序

桶排序: 要排序的数据有n个,均匀地划分到m个桶内,每个桶里就有k=n/m个元素。每个桶内部使用快速排序,时间复杂度为O(k*logk)。m个桶排序的时间复杂度是O(m*k*logk),因为k=n/m,所以整个桶排序的时间复杂度就是O(n*log(n/m))。当桶个数m接近数据个数n时,log(n/m)就是一个非常小的常量,这个时候桶排序的时间复杂度接近O(n)。 如果有些桶内的数据非常多,有...

2018-10-22 08:29:00

863. All Nodes Distance K in Binary Tree

We are given a binary tree (with root node root), a target node, and an integer value K. Return a list of the values of all nodes that have a distance K from the target node.  The answer can be retur...

2018-09-28 09:09:17

865. Smallest Subtree with all the Deepest Nodes

Given a binary tree rooted at root, the depth of each node is the shortest distance to the root. A node is deepest if it has the largest depth possible among any node in the entire tree. The subtree...

2018-09-28 08:50:36

877. Stone Game

Alex and Lee play a game with piles of stones.  There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of the game is to en...

2018-09-17 16:53:37

685. Redundant Connection II

In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, excep...

2018-09-14 09:26:44

684. Redundant Connection

In this problem, a tree is an undirected graph that is connected and has no cycles. The given input is a graph that started as a tree with N nodes (with distinct values 1, 2, ..., N), with one additi...

2018-09-13 09:27:58

563. Binary Tree Tilt

Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtree ...

2018-09-10 08:42:49

543. Diameter of Binary Tree

Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or may n...

2018-09-10 08:21:28

515. Find Largest Value in Each Tree Row

You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9] /** * Definition f...

2018-09-07 09:06:58

513. Find Bottom Left Tree Value

Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / \ 1 3 Output: 1   Example 2:  Input: 1 / \ 2 3 / / \...

2018-09-07 08:55:46

508. Most Frequent Subtree Sum

Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a node is defined as the sum of all the node values formed by the subtree rooted at that node (includi...

2018-09-07 08:44:06

108. Convert Sorted Array to Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the...

2018-09-06 09:08:48

96. Unique Binary Search Trees

Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n? Example: Input: 3 Output: 5 Explanation: Given n = 3, there are a total of 5 unique BST's: 1 ...

2018-09-06 08:44:07

257. Binary Tree Paths

Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example: Input: 1 / \ 2 3 \ 5 Output: ["1->2->5", "1->3"] Explanation: All roo...

2018-09-06 08:36:15

501. Find Mode in Binary Search Tree

Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is defined as follows: The left subtree of a node contain...

2018-09-05 09:28:49

98. Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The ...

2018-09-05 09:08:45

213. House Robber II

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is ...

2018-09-05 08:58:48

337. House Robber III

The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour...

2018-09-05 08:45:54

199. Binary Tree Right Side View

Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Example: Input: [1,2,3,null,5,null,4] Output: [1, 3, 4...

2018-09-04 09:12:10

173. Binary Search Tree Iterator

Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST. Calling next() will return the next smallest number in the BST. Note: next() and...

2018-09-04 09:01:36

无名_1989

1、每天坚持读书1小时;2、坚持提升专业,成为单位 专业权威;3、战胜两个坏毛病——拖延与抱怨;4、先从形象上改变,提升你的自信;5、时常反省自己,但不诋毁自己;6、向优秀的人学习;7、坚持早睡早起;8、坚持体育锻炼;9、保持微笑;10、帮助他人 ​​​​ ...展开 收起
关注
  • 计算机软件/程序员
  • 中国 北京 海淀区
奖章
  • 专栏达人