LeetCode
文章平均质量分 59
童话bye
请看我漂亮的坚持
展开
-
Perfect Squares
1.问题描述Given a positive integer n, find the least number of perfect square numbers (for example,1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because12 = 4 + 4 + 4; giv原创 2015-11-20 15:45:46 · 250 阅读 · 0 评论 -
Path Sum II
问题Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \原创 2015-11-20 15:52:06 · 303 阅读 · 0 评论 -
Kth Smallest Element in a BST
问题Given a binary search tree, write a function kthSmallest to find thekth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.解答class Solution1 {pu原创 2015-11-20 16:29:45 · 315 阅读 · 0 评论 -
Lowest Common Ancestor of a Binary Tree
问题Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two no原创 2015-11-20 15:49:40 · 261 阅读 · 0 评论 -
Symmetric Tree
问题Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the follo原创 2015-11-20 16:03:29 · 300 阅读 · 0 评论 -
Binary Tree Maximum Path Sum
问题Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. Th原创 2015-11-20 15:47:46 · 302 阅读 · 0 评论 -
Sort List
1.问题描述Sort a linked list in O(n log n) time using constant space complexity.链表排序。2.解答/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; *原创 2015-11-20 15:42:47 · 251 阅读 · 0 评论 -
Unique Binary Search Trees II
问题Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1原创 2015-11-20 15:56:42 · 246 阅读 · 0 评论 -
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.原创 2015-11-20 15:55:02 · 243 阅读 · 0 评论 -
Factorial Trailing Zeroes
1.问题描述Given an integer n, return the number of trailing zeroes in n!.阶乘的连续后缀零个数。2.解答int trailingZeroes(int n) { int sum=0; while(n) { while(n%5==0)原创 2015-11-20 15:40:32 · 252 阅读 · 0 评论 -
Palindrome Partitioning
1.问题描述Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [原创 2015-11-20 15:37:35 · 258 阅读 · 0 评论 -
Binary Tree Maximum Path Sum
问题Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. Th原创 2015-11-20 16:31:17 · 309 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node
问题Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If原创 2015-11-20 16:05:32 · 268 阅读 · 0 评论 -
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.For example:Given the following binary tree,原创 2015-11-20 16:33:12 · 336 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node II
问题Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant原创 2015-11-20 16:26:21 · 253 阅读 · 0 评论 -
Path Sum
问题Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and原创 2015-11-20 16:27:51 · 284 阅读 · 0 评论