随笔分类 -  LeetCode

摘要: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 阅读(32585) 评论(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 阅读(17537) 评论(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 阅读(34666) 评论(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 阅读(22191) 评论(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 阅读(34657) 评论(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 阅读(14385) 评论(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 阅读(19741) 评论(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 阅读(14150) 评论(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 阅读(40634) 评论(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 阅读(16698) 评论(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 阅读(17017) 评论(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 阅读(15634) 评论(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 阅读(22813) 评论(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 阅读(18510) 评论(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 阅读(17204) 评论(0) 推荐(1) 编辑
摘要: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 阅读全文
posted @ 2015-02-11 15:14 Grandyang 阅读(15968) 评论(6) 推荐(1) 编辑
摘要:The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'. For example, "ACGAATTCCG" is a DNA sequence. When study 阅读全文
posted @ 2015-02-10 16:11 Grandyang 阅读(17876) 评论(17) 推荐(1) 编辑
摘要: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-09 17:09 Grandyang 阅读(39966) 评论(18) 推荐(1) 编辑
摘要: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-09 08:39 Grandyang 阅读(28020) 评论(3) 推荐(1) 编辑
摘要: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 transaction 阅读全文
posted @ 2015-02-08 16:12 Grandyang 阅读(22786) 评论(1) 推荐(1) 编辑

Fork me on GitHub