随笔分类 -  LeetCode

摘要:Given an integer array nums of unique elements, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Retu 阅读全文
posted @ 2015-03-02 17:29 Grandyang 阅读(32829) 评论(8) 推荐(6)
摘要:Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Example: Input: 1->2->3->4->5->NULL, m = 2, n = 4 Out 阅读全文
posted @ 2015-03-01 09:17 Grandyang 阅读(21693) 评论(11) 推荐(1)
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations. Example: Input: "25525511135" Output: ["255 阅读全文
posted @ 2015-02-28 15:28 Grandyang 阅读(21800) 评论(5) 推荐(5)
摘要:Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n. Example: Input: 3 Output: [ [1,null,3,2], 阅读全文
posted @ 2015-02-26 13:16 Grandyang 阅读(22901) 评论(9) 推荐(3)
摘要: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, the 阅读全文
posted @ 2015-02-25 14:56 Grandyang 阅读(24164) 评论(4) 推荐(4)
摘要:Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Example 2: Note: Try to come up as many solutions as you 阅读全文
posted @ 2015-02-24 15:13 Grandyang 阅读(33198) 评论(15) 推荐(2)
摘要:Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. Example 1: Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac" Output: 阅读全文
posted @ 2015-02-24 14:03 Grandyang 阅读(17927) 评论(14) 推荐(3)
摘要: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 阅读全文
posted @ 2015-02-24 02:26 Grandyang 阅读(35195) 评论(17) 推荐(2)
摘要:Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Example 1: Input: [1,3,null,null,2 阅读全文
posted @ 2015-02-23 15:13 Grandyang 阅读(22546) 评论(8) 推荐(4)
摘要:Given a binary tree, return the inorder traversal of its nodes' values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,3,2] Follow up: Recursive so 阅读全文
posted @ 2015-02-22 05:51 Grandyang 阅读(35216) 评论(11) 推荐(8)
摘要: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 阅读全文
posted @ 2015-02-21 14:55 Grandyang 阅读(14618) 评论(7) 推荐(0)
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. For example, 阅读全文
posted @ 2015-02-20 13:52 Grandyang 阅读(20279) 评论(5) 推荐(2)
摘要:Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. For example, 阅读全文
posted @ 2015-02-19 17:29 Grandyang 阅读(14446) 评论(4) 推荐(0)
摘要: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 comple 阅读全文
posted @ 2015-02-18 14:36 Grandyang 阅读(40989) 评论(2) 推荐(2)
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced bina 阅读全文
posted @ 2015-02-18 07:54 Grandyang 阅读(16893) 评论(11) 推荐(0)
摘要: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 d 阅读全文
posted @ 2015-02-17 14:45 Grandyang 阅读(17288) 评论(6) 推荐(0)
摘要:Given two strings s and t, return the number of distinct subsequences of s which equals t. The test cases are generated so that the answer fits on a 3 阅读全文
posted @ 2015-02-16 14:50 Grandyang 阅读(16065) 评论(11) 推荐(1)
摘要:Given a binary tree, flatten it to a linked list in-place. For example,Given The flattened tree should look like: click to show hints. Hints: If you n 阅读全文
posted @ 2015-02-16 11:07 Grandyang 阅读(23247) 评论(3) 推荐(3)
摘要:Given a binary tree struct Node { int val; Node *left; Node *right; Node *next; } Populate each next pointer to point to its next right node. If there 阅读全文
posted @ 2015-02-13 13:51 Grandyang 阅读(18745) 评论(14) 推荐(1)
摘要:You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following defin 阅读全文
posted @ 2015-02-12 15:07 Grandyang 阅读(17426) 评论(0) 推荐(1)

Fork me on GitHub