自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(26)
  • 收藏
  • 关注

原创 [leetcode] 106.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. 题意: 给定一个树的中序以及后序遍历。构造该树。 思路: 中序的遍历次序是左子树,中,右 以上。 代码

2015-06-30 16:30:10 257

原创 [leetcode] 105.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. 题意: 给定一棵树的前序遍历以及中序遍历,构造出这棵树。 思路: 对于前序遍历,是先根再左右,对于中序遍历是

2015-06-30 15:48:54 250

原创 [leetcode] 103.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

2015-06-29 21:14:56 221

原创 [leetcode] 102.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

2015-06-29 20:55:54 303

原创 [leetcode] 101.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 But the following is n

2015-06-29 20:45:12 288

原创 [leetcode] 100.Recover Binary Search Tree

题目: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure. 题意: 二叉搜索树中有两个节点互换了位置,现在需要找出这两个节点来修复这个二叉搜索树。思路: 依旧依据搜索二叉树的顺序的性质,如果搜索二叉树是正确的,那么所

2015-06-28 22:47:29 299

原创 [leetcode] 98.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. The

2015-06-28 21:40:24 243

原创 [leetcode] 97.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”, return

2015-06-28 00:08:55 281

原创 [leetcode] 95.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 3

2015-06-27 23:01:12 264

原创 [leetcode] 96.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 \

2015-06-26 17:04:33 294

原创 [leetcode] 100.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. 题意: 给定两个二叉树

2015-06-26 15:54:24 308

原创 [leetcode] 93.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.35”]. (Order does

2015-06-25 22:35:42 377

原创 [leetcode] 91.Decode Ways

题目: A message containing letters from A-Z is being encoded to numbers using the following mapping:‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26Given an encoded message containing digits, determine the total numbe

2015-06-25 21:25:37 304

原创 [leetcode] 89.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

2015-06-25 14:28:51 341

原创 [leetcode] 85.Maximal Rectangle

题目:Given a 2D binary matrix filled with 0’s and 1’s, find the largest rectangle containing all ones and return its area. 题意:给一个二维的数组,数组里的元素是0或者1.找到包含元素全部是1的最大面积的数组。 分析:看到这道题的求最大面积会联想到上一道题,即84道题的求最大面积

2015-06-22 21:23:40 342

原创 [leetcode] 88.Merge Sorted Array

题目: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note: You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold addit

2015-06-19 10:32:46 307

原创 [leetode] 77.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],

2015-06-19 10:29:13 309

原创 [leetcode] 72.Edit Distance

题目: Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:

2015-06-11 22:48:50 268

原创 [leetcode] 77.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],

2015-06-11 21:32:21 359

原创 [leetcode] 81.Search in Rotated Sorted Array II

题目: Follow up for “Search in Rotated Sorted Array”: What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the arr

2015-06-11 16:32:48 312

原创 [leetcode] 80.Remove Duplicates from Sorted Array II

题目: Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array nums = [1,1,1,2,2,3], Your function should return length = 5, with the first fiv

2015-06-10 16:56:54 293

原创 [leetcode] 82.Remove Duplicates from Sorted List II

题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1-

2015-06-10 10:53:45 417

原创 [leetcode] 83.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. 比较简单就是删除相同的元素,代码如下:/*

2015-06-09 17:50:05 300

原创 [leetcode] 75.Sort Colors

题目: Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers

2015-06-04 15:35:21 320

原创 [leetcode] 74.Search a 2D Matrix

题目: 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 sorted from left to right. The first integer of each r

2015-06-03 17:28:51 316

原创 [leetcode] 73.Set Matrix Zeroes

题目: Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. 题意: 给一个m x n的矩阵,如果某个元素是0,那么就将这个元素所在的行与这个元素所在的列都设为0. 思路: 这道题的一般思路是扫描所有元素,使用一个一维数组line[m]存储哪些行需要设为0,

2015-06-02 17:28:53 334

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除