- 博客(73)
- 资源 (2)
- 收藏
- 关注
原创 Leetcode 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-09-30 12:52:09 1079
原创 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
2016-09-30 12:33:20 1157
原创 Leetcode 92 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 the
2016-09-28 20:04:47 1165
原创 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 nu
2016-09-28 19:14:25 1108
原创 Leetcode 90 Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,2], a sol
2016-09-28 18:21:39 1062
原创 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 gray code.
2016-09-28 17:14:07 1104
原创 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
2016-09-28 16:28:49 1048
原创 Leetcode 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-09-27 22:48:58 1214
原创 Leetcode 86 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
2016-09-26 20:44:24 1118
原创 Leetcode 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
2016-09-25 19:36:32 1183
原创 Leetcode 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 o
2016-09-24 20:15:54 1357
原创 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->1-
2016-09-24 18:48:20 1261
原创 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.删除链表中的重复元素,快慢指针解决!/**
2016-09-24 17:32:40 1202
原创 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
2016-09-23 21:28:16 1137
原创 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 fi
2016-09-23 20:12:46 1097
原创 Leetcode 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
2016-09-23 19:22:30 1180
原创 Leetcode 78 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],
2016-09-23 18:24:32 1118
原创 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],]
2016-09-23 11:08:52 1275
原创 Leetcode 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 "BAN
2016-09-23 10:19:59 1278
原创 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
2016-09-22 16:54:07 1288
原创 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
2016-09-22 16:42:15 1423
原创 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.click to show follow up.Follow up:Did you use extra space?A straight forward solution using O(m
2016-09-21 21:06:50 1611
原创 Leetcode 72 Edit Distance DP好题
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:
2016-09-21 18:58:29 1591
原创 Leetcode 71 Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"路径化简,.表示当前目录..表示上一级目录。模拟一下,也可以用栈做。注意边界情况Corner
2016-09-21 16:37:06 1441
原创 Leetcode 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?每次爬一到两步,到终点有多少种办法?简单DP,往后1步2
2016-09-20 20:34:43 1624
原创 Leetcode 69 Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.求x的平方根。二分没什么好说的,注意INT_MAX溢出的情况!class Solution {public: int mySqrt(int x) { long long l=0,r=x,mid; while
2016-09-20 20:28:15 1527
原创 Leetcode 68 Text Justification
Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy approach; that i
2016-09-20 20:19:54 1523
原创 Leetcode 67 Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".模拟二进制加法,先逆置字符串,补全短串的前导0,最后注意首位进位!class Solution {public: string addBinary(s
2016-09-20 19:10:08 1356
原创 Leetcode 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.模拟大数加法加一,注意判断首位是否有进位
2016-09-20 18:52:29 1378
原创 Leetcode 65 Valid Number DFA有限状态机
用有限状态机DFA解决,将每一位看成一种状态转移条件,每次读取的一位,就根据转移矩阵进行状态转移,若转移到不合法的状态则返回false。
2016-09-20 18:39:34 3084
原创 Leetcode 64 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
2016-09-19 19:46:52 1354
原创 Leetcode 63 Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the
2016-09-19 19:37:41 1193
原创 Leetcode 62 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-09-19 13:41:18 1404
原创 Leetcode 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-09-19 13:31:30 1192
原创 Leetcode 60 Permutation Sequence
The set [1,2,3,…,n] contains a total of n! 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""3
2016-09-19 12:31:28 1265
原创 Leetcode 59 Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [
2016-09-19 10:08:03 1071
原创 Leetcode 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
2016-09-19 09:36:41 1035
原创 Leetcode 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.E
2016-09-18 21:05:55 1093
原创 Leetcode 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].重叠区间合并,排序后检查当前区间右边和下一个区间左边是否交叉,交叉则合并/** * Defin
2016-09-18 20:21:59 1293
原创 Leetcode 55 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
2016-09-18 19:52:59 979
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人