自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 106. Construct Binary Tree from Inorder and Postorder Traversal

Given inorder and postorder traversal of a tree, construct the binary tree.分析: 中序是左中右,后序是左右中,构建一棵树最重要的是找到其根节点,即中,因此以后序的最后一项开始遍历,然后以根节点的值在中序序列中寻找,若找到记录其位置,其位置左边的是当前根节点的左子树,其右边的则是其右子树。依次遍历即可。

2016-10-22 20:41:55 231

原创 102. 107.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,null,null,15,7], 3 / \ 9 20

2016-10-18 11:44:44 208

原创 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 [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 3B

2016-10-18 11:32:34 141

原创 99. 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 devise

2016-10-18 10:59:00 248

原创 97. Interleaving String

Given s1, s2, s3, find whethers3 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

2016-10-17 15:20:58 168

原创 85. Maximal Rectangle

Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0

2016-10-17 11:07:22 175

原创 84. Largest Rectangle in Histogram

Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogram where width of ea

2016-10-17 11:03:02 125

原创 87. 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

2016-10-17 10:58:08 426

原创 95.96. Unique Binary Search Trees II

Given an integer n, generate all structurally uniqueBST'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

2016-10-11 11:53:08 228

原创 94. Binary Tree Inorder Traversal

Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2].思路:中序遍历. 左子树,中间结点,右子树的遍历顺序

2016-10-11 09:46:15 117

原创 93. Restore IP Addresses

public class Solution {     public List restoreIpAddresses(String s) {         List res=new ArrayList();         int n=s.length();         if(n12)             return res;

2016-10-11 09:08:48 120

原创 92. Reverse Linked List II

Reverse a linked list from position m ton. 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 the foll

2016-10-11 02:07:30 113

原创 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 number

2016-10-11 01:41:52 375

原创 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 gr

2016-10-10 23:11:16 132

原创 88. Merge Sorted Array

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

2016-10-10 22:40:19 120

原创 86. Partition List

Given a linked list and a value x, partition it such that all nodes less thanx come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of

2016-10-10 21:20:47 224

原创 82. 83.Remove Duplicates from Sorted List II

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

2016-10-10 12:59:25 267

原创 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 five e

2016-10-10 01:18:49 130

原创 79. Word Search

Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically n

2016-10-09 23:56:57 132

原创 260. Single Number III

Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums =

2016-10-09 23:19:34 136

原创 78.90 Subsets

Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[ [3], [1], [2]

2016-10-09 21:03:49 187

原创 77. Combinations

Given two integers n and k, return all possible combinations ofk 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],]

2016-10-09 20:50:05 113

原创 76. Minimum Window Substring

Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BANC".

2016-10-09 20:30:08 168

原创 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 0,

2016-10-09 17:21:58 152

原创 74. Search a 2D Matrix

Write an efficient algorithm that searches for a value in anm x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each ro

2016-10-09 15:09:03 117

原创 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.思路: 将每一行是否有0保存在第一列,每一列是否有0保存在第一行,为了避免覆盖第一行和第一列,先判断第一行和第一列是否变成0.public class Solution { public

2016-10-09 14:32:35 259

原创 72. Edit Distance

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

2016-10-09 14:09:14 169

原创 71. Simplify Path

Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", =>"/c"使用栈.public class Solution { public String s

2016-10-09 12:12:01 163

原创 70. 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?分析:动态规划问题, 一层1,二层2,第i层等于第i-1

2016-10-09 11:18:22 159

原创 69. Sqrt(x)

Implement int sqrt(int x).Compute and return the square root of x.最简单的思路: 从1开始,直到其平方大于为止;public class Solution { public int mySqrt(int x) { if(x<=0) return 0;

2016-10-09 11:08:45 115

原创 68. Text Justification

Given an array of words and a length L, format the text such that each line has exactlyL characters and is fully (left and right) justified.You should pack your words in a greedy approach; that is

2016-10-09 09:45:19 126

原创 67. Add Binary

Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".public class Solution { public String addBinary(String a, String b) {

2016-10-09 02:35:08 200

原创 66. 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.code:public

2016-10-09 02:14:18 276

原创 65. Valid Number

Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => truepublic class Solution { public boolean isNumber(St

2016-10-09 01:55:21 197

原创 62.63.64.Unique Paths

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the

2016-10-08 20:05:24 168

原创 61. Rotate List

Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.分析: 当k大于链表长度时,要先将其对链表长度取余,然

2016-10-08 19:35:18 109

原创 60. Permutation Sequence

The set [1,2,3,…,n] contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""312"

2016-10-08 18:47:30 118

原创 58. Length of Last Word

Given a string s consists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defi

2016-10-08 17:41:55 128

原创 57. Insert Interval

Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Examp

2016-10-08 11:10:03 126

原创 56. Merge Intervals

Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].思路:先将集合按照start的值从小到大排序, 然后依次比较当前元素的start和前面元素的end之

2016-10-08 09:36:01 153

空空如也

空空如也

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

TA关注的人

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