9. Palindrome Number

Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. Example 1: Input: 121 Output:...

2019-02-22 09:21:41

阅读数 15

评论数 0

Bitwise ORs of Subarrays

We have an array A of non-negative integers. For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bit...

2019-02-21 09:04:01

阅读数 49

评论数 0

C++11 lambda使用

lambda是匿名函数,可以拿来当作inline函数使用(用于解决程序员的“起名困难综合症”) lambda函数形式:[...] (...) ... {...} [] 内是一个capture,可以在lambda内部访问的"nonstatic外部变量",如果没...

2018-11-15 09:28:49

阅读数 28

评论数 0


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

2018-10-22 08:29:00

阅读数 84

评论数 0

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 distan...

2018-09-28 09:09:17

阅读数 54

评论数 0

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 possi...

2018-09-28 08:50:36

阅读数 45

评论数 0

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 s...

2018-09-17 16:53:37

阅读数 29

评论数 0

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 ...

2018-09-14 09:26:44

阅读数 44

评论数 0

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 (...

2018-09-13 09:27:58

阅读数 41

评论数 0

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 su...

2018-09-10 08:42:49

阅读数 42

评论数 0

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 betw...

2018-09-10 08:21:28

阅读数 32

评论数 0

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...

2018-09-07 09:06:58

阅读数 29

评论数 0

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:  In...

2018-09-07 08:55:46

阅读数 31

评论数 0

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...

2018-09-07 08:44:06

阅读数 49

评论数 0

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...

2018-09-06 09:08:48

阅读数 30

评论数 0

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,...

2018-09-06 08:44:07

阅读数 29

评论数 0

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:...

2018-09-06 08:36:15

阅读数 36

评论数 0

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 defi...

2018-09-05 09:28:49

阅读数 32

评论数 0

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 o...

2018-09-05 09:08:45

阅读数 33

评论数 0

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 a...

2018-09-05 08:58:48

阅读数 48

评论数 0

取消 删除