![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
*
文章平均质量分 65
NoooName
这个作者很懒,什么都没留下…
展开
-
[Leetcode]Longest Substring with At Most Two Distinct Characters
Given a stringS, find the length of the longest substringTthat contains at most two distinct characters.For example,Given S= “eceba”,T is "ece" which its length is 3. 给定一个字符串S,找到最长原创 2015-03-18 04:54:02 · 340 阅读 · 0 评论 -
[Leetcode]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原创 2015-03-14 03:27:07 · 413 阅读 · 0 评论 -
[Leetcode]First Missing Positive
Given 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) time and uses constant原创 2015-02-10 22:21:12 · 366 阅读 · 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-02-02 17:14:53 · 306 阅读 · 0 评论 -
[Leetcode]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原创 2015-02-11 14:55:16 · 348 阅读 · 0 评论 -
[Leetcode]String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2015-02-10 13:46:43 · 284 阅读 · 0 评论 -
[Leetcode]Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, no原创 2015-02-09 22:11:49 · 495 阅读 · 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-01-22 17:18:38 · 414 阅读 · 0 评论 -
[Leetcode]ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I原创 2015-02-09 22:01:49 · 342 阅读 · 0 评论 -
[Leetcode]Subsets II
Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain dupli原创 2015-01-21 13:29:46 · 461 阅读 · 0 评论 -
[Leetcode]Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6.原创 2015-02-08 22:29:10 · 465 阅读 · 0 评论 -
[Leetcode]Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to原创 2015-02-08 10:43:40 · 325 阅读 · 0 评论 -
[Leetcode]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个节点~ 因为k可能超过链表的长度,所以记得对其进行取余原创 2015-01-01 19:51:41 · 282 阅读 · 0 评论 -
[Leetcode]Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The signature of the function had been updat原创 2015-02-08 15:58:47 · 235 阅读 · 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",Retu原创 2015-03-25 01:22:00 · 346 阅读 · 0 评论 -
[Leetcode]Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.合并k个有序的链表~brute force的方法是把这k个链表一个一个的合并起来,如 k个链表为[l1, l2, l3, l4],可以先合并l1, l2,再把合并得到的链表与l3合并,最后再与原创 2015-03-19 08:05:25 · 310 阅读 · 0 评论 -
[Leetcode]Word Ladder
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word m原创 2015-03-25 06:07:04 · 413 阅读 · 0 评论 -
[Leetcode]Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", r原创 2015-03-14 05:03:58 · 318 阅读 · 0 评论 -
[Leetcode]Pow(x, n)
Implement pow(x, n).用二分法~把x的n次方划分成两个x的n/2次方相乘,然后递归求解~注意n为负数的情况~代码复杂度为O(logn)~ 还可以加上越界的判断~class Solution: # @param x, a float # @param n, a integer # @return a float def pow(self,原创 2015-03-14 01:55:26 · 978 阅读 · 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.大数乘法~依旧是从低位到高位进行运算,可以先把num1, num2反转以方原创 2015-03-13 04:28:45 · 324 阅读 · 0 评论 -
[Leetcode]Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without原创 2015-03-13 05:20:21 · 404 阅读 · 0 评论 -
[Leetcode]Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible原创 2015-03-11 02:56:05 · 441 阅读 · 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].要求合并若干个区间~记得先把intervals按start值排序~# Definitio原创 2015-03-11 06:21:52 · 393 阅读 · 0 评论 -
[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-03-12 06:56:24 · 323 阅读 · 0 评论 -
[Leetcode]Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for each原创 2015-03-20 06:49:45 · 378 阅读 · 0 评论 -
[Leetcode]Valid Number
Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statement to be ambiguo原创 2015-03-17 13:59:57 · 502 阅读 · 0 评论 -
[Leetcode]Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo原创 2015-01-29 11:32:31 · 319 阅读 · 0 评论 -
[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-03-26 05:01:12 · 423 阅读 · 0 评论 -
[Leetcode]Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2015-03-26 01:13:27 · 378 阅读 · 0 评论 -
[Leetcode]Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000原创 2015-03-26 01:06:47 · 371 阅读 · 0 评论 -
[Leetcode]Subsets
Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For exa原创 2015-01-20 16:52:32 · 355 阅读 · 0 评论 -
[Leetcode]Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant原创 2015-01-17 17:47:40 · 283 阅读 · 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-02-05 16:55:01 · 280 阅读 · 0 评论 -
[Leetcode]Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","原创 2015-02-01 23:24:29 · 288 阅读 · 0 评论 -
[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-01-30 23:32:02 · 343 阅读 · 0 评论 -
[Leetcode]Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb原创 2015-01-31 17:06:39 · 286 阅读 · 0 评论 -
[Leetcode]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],]原创 2015-01-29 22:42:26 · 277 阅读 · 0 评论 -
[Leetcode]Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2015-01-28 23:07:32 · 281 阅读 · 0 评论 -
[Leetcode]3Sum Closest
Given 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 would have exact原创 2015-01-28 13:46:18 · 349 阅读 · 0 评论 -
[Leetcode]4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Element原创 2015-01-28 16:09:27 · 331 阅读 · 0 评论