![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
文章平均质量分 68
Moon_flower
这个作者很懒,什么都没留下…
展开
-
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 · 270 阅读 · 0 评论 -
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 · 331 阅读 · 0 评论 -
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 · 240 阅读 · 0 评论 -
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 · 323 阅读 · 0 评论 -
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 · 263 阅读 · 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原创 2015-10-26 22:25:49 · 322 阅读 · 0 评论 -
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 · 219 阅读 · 0 评论 -
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 · 227 阅读 · 0 评论 -
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 · 243 阅读 · 0 评论 -
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 · 261 阅读 · 0 评论 -
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 · 204 阅读 · 0 评论 -
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 · 239 阅读 · 0 评论 -
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 · 256 阅读 · 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原创 2015-10-30 14:44:26 · 317 阅读 · 0 评论 -
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 · 287 阅读 · 0 评论 -
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 · 247 阅读 · 0 评论 -
Leetcode -- Best Time to Buy and Sell Stock IV
递推公式参考:http://blog.csdn.net/linhuanmars/article/details/23236995原创 2015-10-29 18:56:25 · 255 阅读 · 0 评论 -
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 · 285 阅读 · 0 评论 -
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 · 239 阅读 · 0 评论 -
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 · 262 阅读 · 0 评论 -
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 · 419 阅读 · 0 评论 -
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 · 305 阅读 · 0 评论 -
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 · 217 阅读 · 0 评论 -
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 · 295 阅读 · 0 评论 -
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 · 340 阅读 · 0 评论 -
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 · 377 阅读 · 0 评论 -
Leetcode -- Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).class Solution {public:原创 2015-10-24 10:07:35 · 197 阅读 · 0 评论 -
Leetcode -- Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array retur原创 2015-10-24 09:39:32 · 214 阅读 · 0 评论 -
Leetcode -- Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.本题使用优先队列,自定义优先级。/** * Definition for singly-linked list. * struct ListNode { * int原创 2015-10-23 20:39:04 · 246 阅读 · 0 评论 -
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 · 262 阅读 · 0 评论 -
Leetcode -- Find Minimum in Rotated Sorted Array II
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).Find the minimum element.The array may contain duplicates.分原创 2015-10-24 09:26:47 · 227 阅读 · 0 评论 -
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 · 235 阅读 · 0 评论 -
Leetcode -- Find the Duplicate Number
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number,原创 2015-10-24 10:31:24 · 277 阅读 · 0 评论 -
Leetcode -- Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The原创 2015-10-24 08:53:10 · 242 阅读 · 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原创 2015-10-23 22:08:32 · 277 阅读 · 0 评论 -
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 · 233 阅读 · 0 评论 -
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 · 218 阅读 · 0 评论 -
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 · 209 阅读 · 0 评论 -
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 · 241 阅读 · 0 评论 -
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 · 257 阅读 · 0 评论