![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
我的leetcode学习之路
文章平均质量分 64
laiqingnan
这个作者很懒,什么都没留下…
展开
-
[leetcode] 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原创 2014-07-14 18:02:47 · 269 阅读 · 0 评论 -
[leetcode] Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non原创 2014-07-14 18:26:58 · 277 阅读 · 0 评论 -
[leetcode] 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 sum原创 2014-07-15 11:21:30 · 205 阅读 · 0 评论 -
[leetcode] 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 / \ 9 20原创 2014-07-16 09:41:19 · 305 阅读 · 0 评论 -
[leetcode] 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,#,#,15,7},原创 2014-07-16 09:46:00 · 258 阅读 · 0 评论 -
[leetcode] 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.思路:递归解决,zhaoch原创 2014-07-16 14:26:15 · 264 阅读 · 0 评论 -
[leetcode] 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.思路:递归,与原创 2014-07-16 14:25:43 · 241 阅读 · 0 评论 -
[leetcode] 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:Given binary原创 2014-07-16 14:47:11 · 234 阅读 · 0 评论 -
[leetcode] 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.思路:递归代码:原创 2014-07-16 14:32:57 · 211 阅读 · 0 评论 -
[leetcode] 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 f原创 2014-07-16 16:13:00 · 264 阅读 · 0 评论 -
[leetcode] Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.思路:递归代原创 2014-07-16 16:27:44 · 240 阅读 · 0 评论 -
[leetcode] 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.Th原创 2014-07-16 18:09:34 · 265 阅读 · 0 评论 -
[leetcode] 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. Could you devis原创 2014-07-16 17:49:45 · 293 阅读 · 0 评论 -
[leetcode] 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 = "aadbbbaccc", ret原创 2014-07-17 13:00:45 · 258 阅读 · 0 评论 -
[leetcode] 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 1 \原创 2014-07-17 18:29:26 · 216 阅读 · 0 评论 -
[leetcode] 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 3原创 2014-07-17 18:30:12 · 237 阅读 · 0 评论 -
[leetcode] 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].思路:简单的xianxu原创 2014-07-17 18:34:51 · 215 阅读 · 0 评论 -
[leetcode] Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.思路:逐个遍历liangtiaolian原创 2014-07-18 18:18:31 · 279 阅读 · 0 评论 -
[leetcode] Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of原创 2014-07-19 10:07:39 · 272 阅读 · 0 评论 -
[leetcode] Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy t原创 2014-07-18 14:59:00 · 269 阅读 · 0 评论 -
[leetcode] Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.思路:两个指针,一个pre,一个cur,d原创 2014-07-18 17:47:45 · 257 阅读 · 0 评论 -
[leetcode] Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.原创 2014-07-18 17:39:23 · 232 阅读 · 0 评论 -
[leetcode] Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] ha原创 2014-07-18 18:03:23 · 255 阅读 · 0 评论 -
[leetcode] Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of原创 2014-07-19 09:20:56 · 277 阅读 · 0 评论 -
[leetcode] Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?思路:斐波那契数列,f原创 2014-07-18 18:08:46 · 271 阅读 · 0 评论 -
[leetcode] Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ gr原创 2014-07-19 09:42:30 · 363 阅读 · 0 评论 -
[leetcode] Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.思路:sqrt(x)ken原创 2014-07-20 11:12:32 · 260 阅读 · 0 评论 -
[leetcode] Pow(x, n)
Implement pow(x, n).思路:you原创 2014-07-20 18:16:53 · 234 阅读 · 0 评论 -
[leetcode] Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.思路:先找到前两个的最长qi原创 2014-07-21 14:31:28 · 235 阅读 · 0 评论 -
[leetcode] Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2014-07-19 23:16:31 · 326 阅读 · 0 评论 -
[leetcode] Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements fro原创 2014-07-19 19:10:56 · 352 阅读 · 0 评论 -
[leetcode] Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.思路:jiang原创 2014-07-20 11:14:36 · 301 阅读 · 0 评论 -
[leetcode] Jump Game II
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 maximum jump length at that position.Your goal i原创 2014-07-21 12:42:16 · 288 阅读 · 0 评论 -
[leetcode] Jump Game
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 maximum jump length at that position.Determine i原创 2014-07-21 11:50:48 · 325 阅读 · 0 评论 -
[leetcode] Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2014-07-21 22:09:00 · 311 阅读 · 0 评论 -
[leetcode] Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2014-07-22 18:59:24 · 276 阅读 · 0 评论 -
[leetcode] Minimum Path Sum
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.Note: You can only move either down or right at原创 2014-07-22 19:13:07 · 249 阅读 · 0 评论 -
[leetcode] N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.思路:N-Queens原创 2014-07-23 10:26:19 · 245 阅读 · 0 评论 -
[leetcode] Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]原创 2014-07-22 09:46:18 · 232 阅读 · 0 评论 -
[leetcode] Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".原创 2014-07-22 09:33:15 · 300 阅读 · 0 评论