![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 52
maqingli87
这个作者很懒,什么都没留下…
展开
-
LeetCode Anagrams
AnagramsGiven an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.善用STL,好处有两个:简单,可靠!介绍两个APIstring::compareint compare ( con原创 2012-09-12 22:38:31 · 494 阅读 · 0 评论 -
LeetCode 3Sum Closest
3Sum ClosestGiven an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input wo原创 2012-09-12 17:59:35 · 362 阅读 · 0 评论 -
LeetCode Add Binary
Add BinaryGiven two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".虽然写得很长,但是代码清楚,而且一遍就过了,这就是王道!class Solution {public: string原创 2012-09-12 21:17:57 · 650 阅读 · 0 评论 -
LeetCode Add Two Numbers
Add Two NumbersYou are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and原创 2012-09-12 21:25:10 · 666 阅读 · 0 评论 -
LeetCode 3Sum
3SumGiven an array S of n integers, are there elements a,b,c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a原创 2012-09-12 17:13:42 · 491 阅读 · 0 评论 -
LeetCode Decode Ways
Decode WaysA 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 t原创 2012-09-14 16:23:58 · 923 阅读 · 0 评论 -
LeetCode Divide Two Integers
Divide Two IntegersDivide two integers without using multiplication, division and mod operator.考虑数据类型的限制,处理溢出的情况。class Solution {public: int divide(int dividend, int divisor) {原创 2012-09-14 17:19:49 · 2831 阅读 · 0 评论 -
LeetCode Wildcard Matching
Wildcard MatchingImplement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The原创 2012-09-24 01:31:14 · 1086 阅读 · 0 评论 -
LeetCode Combination Sum II
Combination Sum IIGiven a collection of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.Each number in C may only be used原创 2012-09-14 13:16:30 · 406 阅读 · 0 评论 -
LeetCode Container With Most Water
Container With Most WaterGiven n non-negative integers a1, a2, ...,an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of linei is原创 2012-09-14 14:02:59 · 598 阅读 · 0 评论 -
LeetCode Binary Tree Inorder Traversal
Binary Tree Inorder TraversalGiven a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].原创 2012-09-14 10:04:57 · 672 阅读 · 0 评论 -
LeetCode Climbing Stairs
Climbing StairsYou 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?先写个简单的递归,只能原创 2012-09-14 10:18:09 · 357 阅读 · 0 评论 -
LeetCode Combination Sum
Combination SumGiven a set of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.The same repeated number may be chosen fro原创 2012-09-14 12:27:53 · 490 阅读 · 0 评论 -
LeetCode Combinations
CombinationsGiven 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原创 2012-09-14 13:38:08 · 536 阅读 · 0 评论 -
LeetCode First Missing Positive
First Missing PositiveGiven an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n)原创 2012-09-16 10:49:11 · 655 阅读 · 0 评论 -
LeetCode Gray Code
Gray CodeThe 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 s原创 2012-09-16 11:19:46 · 778 阅读 · 0 评论 -
LeetCode Implement strStr()
Implement strStr()Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.写了好几种求next数组的方法,都可以通过。class Solution {pub原创 2012-09-16 16:28:08 · 715 阅读 · 0 评论 -
LeetCode Integer to Roman
Integer to RomanGiven an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.class Solution {public: string intToRoman(int num) { st原创 2012-09-16 16:54:55 · 512 阅读 · 0 评论 -
LeetCode Insert Interval
Insert IntervalGiven 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原创 2012-09-16 16:46:06 · 736 阅读 · 0 评论 -
LeetCode Jump Game
Jump GameGiven 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.原创 2012-09-16 17:31:44 · 377 阅读 · 0 评论 -
LeetCode Largest Rectangle in Histogram
Largest Rectangle in HistogramGiven 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.Abov原创 2012-09-16 20:03:12 · 832 阅读 · 0 评论 -
LeetCode Length of Last Word
Length of Last WordGiven 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原创 2012-09-16 20:22:38 · 330 阅读 · 0 评论 -
LeetCode Letter Combinations of a Phone Number
Letter Combinations of a Phone NumberGiven a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone butto原创 2012-09-16 20:36:27 · 515 阅读 · 0 评论 -
LeetCode Longest Common Prefix
Longest Common PrefixWrite a function to find the longest common prefix string amongst an array of strings.class Solution {public: string longestCommonPrefix(vector &strs) { if(0 =原创 2012-09-16 20:43:46 · 879 阅读 · 0 评论 -
LeetCode Longest Palindromic Substring
Longest Palindromic SubstringGiven a string S, find the longest palindromic substring in S. You may assume that the maximum length ofS is 1000, and there exists one unique longest palindromic su原创 2012-09-16 21:42:10 · 772 阅读 · 0 评论 -
LeetCode Longest Substring Without Repeating Characters
Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo原创 2012-09-16 22:19:13 · 619 阅读 · 0 评论 -
LeetCode Longest Valid Parentheses
Longest Valid ParenthesesGiven a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parenthe原创 2012-09-16 22:46:02 · 524 阅读 · 0 评论 -
LeetCode Edit Distance
Edit DistanceGiven 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 perm原创 2012-09-16 10:17:27 · 789 阅读 · 0 评论 -
LeetCode Generate Parentheses
Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())原创 2012-09-16 11:15:34 · 765 阅读 · 0 评论 -
LeetCode Interleaving String
Interleaving StringGiven s1, s2, s3, find whether s3 is formed by the interleaving ofs1 ands2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 =原创 2012-09-16 17:18:08 · 1598 阅读 · 1 评论 -
LeetCode Jump Game II
Jump Game IIGiven 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.原创 2012-09-16 18:13:11 · 698 阅读 · 0 评论 -
LeetCode Maximal Rectangle
Maximal RectangleGiven a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.O(N^3)class Solution {public: int maximalRectan原创 2012-09-17 20:02:26 · 770 阅读 · 0 评论 -
LeetCode Median of Two Sorted Arrays
Median of Two Sorted ArraysThere are two sorted arrays A and B 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)).O(N)原创 2012-09-18 10:53:23 · 1394 阅读 · 0 评论 -
LeetCode Maximum Subarray
Maximum SubarrayFind the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous suba原创 2012-09-17 20:42:49 · 934 阅读 · 1 评论 -
LeetCode N-Queens II
N-Queens IIFollow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.class Solution {public: int totalNQueens(int n) {原创 2012-09-18 17:48:35 · 1385 阅读 · 0 评论 -
LeetCode Merge k Sorted Lists
Merge k Sorted ListsMerge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.class Solution {public: ListNode *mergeKLists(vector &lists) {原创 2012-09-18 13:45:17 · 1865 阅读 · 0 评论 -
LeetCode Minimum Window Substring
Minimum Window SubstringGiven 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"原创 2012-09-18 16:46:28 · 939 阅读 · 0 评论 -
LeetCode Multiply Strings
Multiply StringsGiven two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.import java.math.Bi原创 2012-09-18 16:59:53 · 1327 阅读 · 2 评论 -
LeetCode Partition List
Partition ListGiven 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原创 2012-09-18 20:38:41 · 747 阅读 · 0 评论 -
LeetCode Permutations
PermutationsGiven a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1],[3,1,2], and[3,2,1].遍原创 2012-09-18 22:31:16 · 3838 阅读 · 0 评论