
LeetCode
文章平均质量分 72
claviclelau
这个作者很懒,什么都没留下…
展开
-
LeetCode 95: Unique Binary Search Trees II
Difficulty: 4Frequency: 1Problem: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原创 2013-09-11 22:05:04 · 357 阅读 · 0 评论 -
LeetCode 114: Flatten Binary Tree to Linked List
Difficulty: 3Frequency: 3Problem:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6原创 2013-09-03 13:13:19 · 397 阅读 · 0 评论 -
LeetCode 116: Populating Next Right Pointers in Each Node
Difficulty: 3Frequency: 3Problem:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each原创 2013-09-03 10:18:56 · 422 阅读 · 0 评论 -
LeetCode 74: Search A 2D Matrix
Difficulty: 3Frequency: 3Problem:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are原创 2013-09-02 20:01:38 · 411 阅读 · 0 评论 -
LeetCode 73: Set Matrix Zeroes
Difficulty: 3Frequency: 5Problem:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight for原创 2013-09-02 16:47:34 · 425 阅读 · 0 评论 -
LeetCode 99: Recover Binary Search Tree
Difficulty: 4Frequency: 2Problem:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) sp原创 2013-09-08 21:13:55 · 484 阅读 · 0 评论 -
LeetCode 103: Binary Tree Zigzag Level Order Traversal
Difficulty: 4Frequency: 3Problem:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and a原创 2013-09-08 20:15:31 · 418 阅读 · 0 评论 -
LeetCode 64: Minimum Path Sum
Difficulty: 3Frequency: 3Problem:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.原创 2013-09-02 15:26:32 · 398 阅读 · 0 评论 -
LeetCode 122: Best Time to Buy and Sell Stock II
Difficulty: 3Frequency: 1Problem:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may comp原创 2013-09-03 08:00:44 · 788 阅读 · 0 评论 -
LeetCode 63: Unique Paths II
Difficulty: 3Frequency: 3Problem:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty sp原创 2013-09-02 15:03:27 · 376 阅读 · 0 评论 -
LeetCode 61: Rotate List
Difficulty: 3Frequency: 2Problem:Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1-原创 2013-09-02 14:18:18 · 387 阅读 · 0 评论 -
LeetCode 59: Spiral Matrix II
Difficulty: 3Frequency: 2Problem:Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the fo原创 2013-09-02 13:52:37 · 436 阅读 · 0 评论 -
LeetCode 55: Jump Game
Difficulty: 3Frequency: 2Problem:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maxim原创 2013-09-02 13:16:46 · 750 阅读 · 0 评论 -
LeetCode 107: Binary Tree Level Order Traversal II
Difficulty: 3Frequency: 1Problem:Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).Fo原创 2013-09-03 14:03:27 · 457 阅读 · 0 评论 -
LeetCode 120: Triangle
Difficulty: 3Frequency: 1Problem:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the fo原创 2013-09-03 08:27:29 · 397 阅读 · 0 评论 -
LeetCode 49: Anagrams
Difficulty: 3Frequency: 4Problem:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.Solution:class Solution {public原创 2013-09-05 19:13:23 · 447 阅读 · 0 评论 -
LeetCode 46: Permutations
Difficulty: 3Frequency: 4Problem:Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3],原创 2013-09-05 18:45:10 · 444 阅读 · 0 评论 -
LeetCode 31: Next Permutation
Difficulty: 5Frequency: 2Problem:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possib原创 2013-09-05 14:26:18 · 500 阅读 · 0 评论 -
LeetCode 60: Permutation Sequence
Difficulty: 5Frequency: 1Problem:The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequ原创 2013-09-05 15:21:28 · 540 阅读 · 0 评论 -
LeetCode 91: Decode Ways
Difficulty: 3Frequency: 4Problem:A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded me原创 2013-09-04 18:58:18 · 359 阅读 · 0 评论 -
LeetCode 79: Word Search
Difficulty: 3Frequency: 4Problem:Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjac原创 2013-09-04 15:47:56 · 379 阅读 · 0 评论 -
LeetCode 78: Subsets
Difficulty: 3Frequency: 4Problem:Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set原创 2013-09-04 15:01:16 · 444 阅读 · 0 评论 -
LeetCode 86: Partition List
Difficulty: 3Frequency: 3Problem:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal tox.You should preserve the原创 2013-09-04 16:56:05 · 476 阅读 · 0 评论 -
LeetCode 82: Remove Duplicates from Sorted List II
Difficulty: 3Frequency: 3Problem:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1-原创 2013-09-04 16:23:57 · 373 阅读 · 0 评论 -
LeetCode 96: Unique Binary Search Tree
Difficulty: 3Frequency: 1Problem:Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique原创 2013-09-03 16:18:48 · 495 阅读 · 0 评论 -
LeetCode 98: Validate Binary Search Tree
Difficulty: 3Frequency: 5Problem: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原创 2013-09-03 15:49:27 · 432 阅读 · 0 评论 -
LeetCode 106: Construct Binary Tree from Inorder and Postorder Traversal
Difficulty: 3Frequency: 3Problem:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.Solution:原创 2013-09-03 14:37:39 · 660 阅读 · 0 评论 -
LeetCode 123: Best Time to Buy and Sell Stock III
Difficulty: 4Frequency: 2Problem:Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may comp原创 2013-09-08 19:06:56 · 455 阅读 · 0 评论 -
LeetCode 128: Longest Consecutive Sequence
Difficulty: 4Frequency: 3Problem:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The原创 2013-09-07 21:13:17 · 315 阅读 · 0 评论 -
LeetCode 3: Longest Substring Without Repeating Characters
Difficulty: 3Frequency: 2Problem:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "ab原创 2013-08-27 20:00:35 · 317 阅读 · 0 评论 -
LeetCode 2: Add Two Numbers
Difficulty: 2Frequency: 4Problem:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single dig原创 2013-08-26 16:27:10 · 347 阅读 · 0 评论 -
LeetCode 20: Valid Parentheses
Difficulty: 2Frequency: 5Problem:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in th原创 2013-08-26 15:15:55 · 255 阅读 · 0 评论 -
LeetCode 14: Longest Common Prefix
Difficulty: 2Frequency: 1Problem:Write a function to find the longest common prefix string amongst an array of strings.Solution:class Solution {public: string longestCommonPrefix(原创 2013-08-26 14:42:25 · 300 阅读 · 0 评论 -
LeetCode 129: Sum Root to Leaf Numbers
Difficulty: 2Frequency: 4Problem:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 wh原创 2013-08-22 14:45:20 · 292 阅读 · 0 评论 -
LeetCode 113: Path Sum II
Difficulty: 2Frequency: 2Problem: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原创 2013-08-22 10:02:05 · 386 阅读 · 0 评论 -
LeetCode 121: Best Time to Buy and Sell Stock
Difficulty: 2Frequency: 1Problem:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transacti原创 2013-08-22 13:42:41 · 668 阅读 · 0 评论 -
LeetCode 108: Convert Sorted Array to Binary Search Tree
Difficulty: 2Frequency: 3Problem:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.Solution:class Solution {public: TreeNode *sorted原创 2013-08-22 09:25:59 · 272 阅读 · 0 评论 -
LeetCode 131: Palindrome Partition
Difficulty: 3Frequency: 4Problem:Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For e原创 2013-08-22 20:00:47 · 567 阅读 · 1 评论 -
LeetCode 125: Valid Palindrome
Difficulty: 2Frequency: 5Problem:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal:原创 2013-08-22 14:07:34 · 383 阅读 · 0 评论 -
LeetCode 119: Pascal's Triangle II
Difficulty: 2Frequency: 1Problem:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algori原创 2013-08-22 12:58:28 · 414 阅读 · 0 评论