![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
千寻221
这个作者很懒,什么都没留下…
展开
-
Best Time to Buy and Sell Stock
题目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 (ie, buy one and sell one share of the原创 2014-06-03 13:01:12 · 798 阅读 · 0 评论 -
Best Time to Buy and Sell Stock II
题目原创 2014-06-03 14:13:05 · 778 阅读 · 0 评论 -
Binary Tree Maximum Path Sum
题目原创 2014-06-03 11:24:40 · 572 阅读 · 0 评论 -
Pascal's Triangle II
题目原创 2014-06-03 18:59:39 · 415 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node
题目原创 2014-06-03 20:42:06 · 421 阅读 · 0 评论 -
Sum Root to Leaf Numbers
题目方法原创 2014-06-03 21:48:01 · 481 阅读 · 0 评论 -
Surrounded Regions
题目方法一方法二原创 2014-06-03 21:59:32 · 435 阅读 · 0 评论 -
Palindrome Partitioning II
题目Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "a原创 2014-06-03 22:43:14 · 542 阅读 · 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 us原创 2014-06-03 21:24:58 · 378 阅读 · 0 评论 -
Valid Palindrome
题目Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" i原创 2014-06-03 21:41:40 · 393 阅读 · 0 评论 -
Word Break II
题目方法原创 2014-06-03 23:03:14 · 796 阅读 · 0 评论 -
Palindrome Partitioning
题目方法一方法二原创 2014-06-03 22:29:42 · 536 阅读 · 0 评论 -
Pascal's Triangle
题目Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]原创 2014-06-03 18:52:29 · 464 阅读 · 0 评论 -
Add Two Numbers
题目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 digit. Add the two numbers and return原创 2014-06-22 16:22:10 · 463 阅读 · 0 评论 -
Regular Expression Matching
题目Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the ent原创 2014-06-23 13:47:59 · 499 阅读 · 0 评论 -
Word Break
题目Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict =原创 2014-06-03 22:58:22 · 588 阅读 · 0 评论 -
Minimum Depth of Binary Tree
题目Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.方法一后序遍历树,使用递归,原创 2014-06-04 20:07:47 · 533 阅读 · 0 评论 -
Balanced Binary Tree
题目Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node原创 2014-06-04 22:38:40 · 480 阅读 · 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 t原创 2014-06-04 17:08:05 · 552 阅读 · 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原创 2014-06-04 18:20:01 · 565 阅读 · 0 评论 -
Maximum Depth of Binary Tree
题目Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.方法使用DFS对树进行遍原创 2014-06-05 15:22:56 · 563 阅读 · 0 评论 -
Wildcard Matching
题目Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching sh原创 2014-06-24 08:32:26 · 533 阅读 · 0 评论 -
Convert Sorted Array to Binary Search Tree
题目Given an array where elements are sorted in ascending order, convert it to a height balanced BST.方法数组是有序的,要求创建的二叉树尽量平衡,很容易想到对数组进行二分操作,左边的数组元素是左子树,右边的数组元素是右子树。进行递归操作就可以了。 TreeNode原创 2014-06-05 09:40:39 · 466 阅读 · 0 评论 -
Construct Binary Tree from Inorder and Postorder Traversal
题目Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.方法根据树的中序遍历和后序遍历,来恢复树,使用递归的思想。 Tr原创 2014-06-05 12:25:32 · 958 阅读 · 0 评论 -
Binary Tree Zigzag Level Order Traversal
题目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 alternate between).For example:G原创 2014-06-05 15:15:03 · 534 阅读 · 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 3原创 2014-06-05 16:03:19 · 537 阅读 · 0 评论 -
Same Tree
题目方法使用递归,先判断当前节点,原创 2014-06-05 16:20:11 · 318 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
题目Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.方法和有序数组的思想基本一样,将链表进行二分。 TreeNode getBST(ListNode head, int len) { i原创 2014-06-05 09:44:02 · 527 阅读 · 0 评论 -
Construct Binary Tree from Preorder and Inorder Traversal
题目Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.方法根据树的中序遍历和前序遍历,来构造树,使用递归的思想。 Tre原创 2014-06-05 12:23:24 · 1079 阅读 · 0 评论 -
Binary Tree Inorder Traversal
题目Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recur原创 2014-06-05 12:48:11 · 578 阅读 · 0 评论 -
Binary Tree Level Order Traversal II
题目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).For example:Given binary tree {3,9,20原创 2014-06-05 14:37:37 · 553 阅读 · 0 评论 -
Recover Binary Search Tree
题目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) space is pretty straight forward. Cou原创 2014-06-05 20:15:01 · 579 阅读 · 0 评论 -
Validate Binary Search Tree
题目方法一方法二原创 2014-06-05 22:18:00 · 331 阅读 · 0 评论 -
Binary Tree Level Order Traversal
题目 Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \原创 2014-06-05 14:32:32 · 593 阅读 · 0 评论 -
Unique Binary Search Trees
题目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 BST's. 1 3 3 2原创 2014-06-06 13:18:57 · 663 阅读 · 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.原创 2014-06-06 13:34:58 · 567 阅读 · 0 评论 -
Interleaving String
题目Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadb原创 2014-06-06 15:03:12 · 515 阅读 · 0 评论 -
Container With Most Water
题目Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (原创 2014-06-24 12:26:23 · 434 阅读 · 0 评论 -
Valid Sudoku
题目Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A par原创 2014-06-26 14:45:11 · 1388 阅读 · 0 评论 -
Restore IP Addresses
题目Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.3原创 2014-06-06 15:50:57 · 514 阅读 · 0 评论