- 博客(52)
- 收藏
- 关注
原创 Leetcode -- 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 numb
2015-10-30 15:07:35 286
原创 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
2015-10-30 14:44:26 343
原创 Leetcode -- Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.class Solution {public: string a
2015-10-30 09:24:45 309
原创 Leetcode -- Best Time to Buy and Sell Stock IV
递推公式参考:http://blog.csdn.net/linhuanmars/article/details/23236995
2015-10-29 18:56:25 270
原创 Leetcode -- Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as
2015-10-29 18:37:28 235
原创 Leetcode -- Course Schedule
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as
2015-10-29 18:26:39 293
原创 Leetcode -- Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements
2015-10-29 17:05:45 304
原创 Leetcode -- Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window
2015-10-29 16:36:25 258
原创 Leetcode -- 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 should cover t
2015-10-29 16:23:23 284
原创 Leetcode -- The Skyline Problem
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as
2015-10-29 10:53:46 457
原创 Leetcode -- Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to solve it in-place in
2015-10-28 23:03:44 321
原创 Leetcode -- Shortest Palindrome
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For exam
2015-10-28 22:05:11 258
原创 Leetcode -- 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 = "aab",Return
2015-10-28 21:48:19 278
原创 Leetcode -- Substring with Concatenation of All Words
You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in wordsexactly once and w
2015-10-28 21:33:12 282
原创 Leetcode -- Word Break II
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "
2015-10-28 19:49:13 342
原创 Leetcode -- 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 = ["leet"
2015-10-28 14:47:24 259
原创 Leetcode -- LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if
2015-10-28 11:16:22 363
原创 Leetcode -- Expression Add Operators
Given a string that contains only digits 0-9 and a target value, return all possibilities to add binary operators (not unary) +, -, or * between the digits so they evaluate to the target value.
2015-10-28 09:36:07 310
原创 Leetcode -- Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.class Solution {public: long long divide_(long long a,long long b) {
2015-10-27 21:16:59 278
原创 Leetcode -- Find Median from Data Stream
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median
2015-10-27 19:40:10 409
原创 Leetcode -- 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
2015-10-27 18:44:14 246
原创 Leetcode -- Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.分析:穷举。对每个点,建立一个哈希表,记录与其共线的点的数目。/** * Definition for a point. * struct Point { * int
2015-10-27 16:55:04 281
原创 Leetcode -- 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
2015-10-27 16:17:35 279
原创 Leetcode -- N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.分析:典型的回溯法题目。class Solution {public: int cnt=0; b
2015-10-27 15:19:31 247
原创 Leetcode -- 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
2015-10-27 15:06:59 179
原创 Leetcode -- 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.分析:本题求解时借助了对直方图求最大矩形的解法。对每层生成一个累计直方图并求解。class Solution {public: int maxr
2015-10-27 10:56:41 229
原创 Leetcode -- Dungeon Game
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially p
2015-10-27 09:15:20 262
原创 Leetcode -- Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]
2015-10-27 08:59:01 225
原创 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
2015-10-26 22:25:49 352
原创 Leetcode -- Candy
There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at least on
2015-10-26 22:00:46 257
原创 Leetcode -- Word Search II
Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those hor
2015-10-26 21:42:19 221
原创 Leetcode -- Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.Note:You may assume that all inputs are consist of lowercase letters a-z.class TrieNode {public: // Initialize your data s
2015-10-26 21:11:12 238
原创 Leetcode -- 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
2015-10-26 20:42:20 251
原创 Leetcode -- N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.
2015-10-26 20:24:50 216
原创 Leetcode -- Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku
2015-10-26 19:45:31 341
原创 Leetcode -- Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O X
2015-10-26 18:35:13 278
原创 Leetcode -- Word Ladder II
Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one letter can be changed at a timeEac
2015-10-26 16:35:12 424
原创 Leetcode -- Word Ladder
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:Only one letter can be changed at a
2015-10-26 11:08:48 405
原创 Leetcode -- Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",
2015-10-24 20:14:18 279
原创 Leetcode -- 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].分析:题目本身的过程十分清楚,只需要对重叠的区间进行扩展即可。判断区间是否重叠的方法也是显然
2015-10-24 10:59:19 274
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人