
Leetcode hard
文章平均质量分 75
豆腐脑是咸的
这个作者很懒,什么都没留下…
展开
-
Distinct Subsequences (Java)
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-29 11:52:18 · 373 阅读 · 0 评论 -
Merge k Sorted Lists (Java)
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.merge two sorted lists那道题的升级版。Source/** * Definition for singly-linked list. * public class原创 2015-02-06 18:49:26 · 388 阅读 · 0 评论 -
Longest Valid Parentheses (Java)
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-08 08:55:41 · 364 阅读 · 0 评论 -
Binary Tree Maximum Path Sum (Java)
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-06 21:02:30 · 487 阅读 · 0 评论 -
Interleaving String (Java)
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", ret原创 2015-02-08 10:34:20 · 364 阅读 · 0 评论 -
Palindrome Partitioning II (Java)
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-02-09 11:59:54 · 366 阅读 · 0 评论 -
Repeated DNA Sequences (Java)
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri原创 2015-02-18 15:31:09 · 823 阅读 · 0 评论 -
Search in Rotated Sorted Array (Java)
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-01-23 11:35:45 · 337 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node II (Java)
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-23 21:49:56 · 347 阅读 · 0 评论 -
N-Queens II (Java)
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.八皇后问题:所有皇后所在行、列、斜线上不能有其他皇后出现。用回溯法做,枚举第一行皇后可以在的所有位置,根据所在原创 2015-01-23 19:23:05 · 281 阅读 · 0 评论 -
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-23 20:36:32 · 332 阅读 · 0 评论 -
Find Minimum in Rotated Sorted Array II (Java)
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot unk原创 2015-01-24 10:48:31 · 330 阅读 · 0 评论 -
Max Points on a Line (Java)
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.用斜率算,遍历每一个点,然后以这个点和剩下的所有点连线,斜率相同的放在hash的同一位置。如果有和这个点相同的点统计下来最后算进去。Source public int maxPoi原创 2015-02-12 14:04:17 · 437 阅读 · 0 评论 -
Valid Number (Java)
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-02-12 14:42:02 · 499 阅读 · 0 评论 -
Median of Two Sorted Arrays (Java)
There 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)).参考:http://blog.youkuaiyun.com/yutianzui原创 2015-02-12 15:31:42 · 424 阅读 · 0 评论 -
Trapping Rain Water (Java)
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-01-24 11:50:33 · 333 阅读 · 0 评论 -
Candy (Java)
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-02-09 10:35:08 · 470 阅读 · 0 评论 -
Insert Interval (Java)
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-02-06 19:53:47 · 496 阅读 · 0 评论 -
Reverse Nodes in k-Group (Java)
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is原创 2015-01-29 16:14:10 · 363 阅读 · 0 评论 -
Permutations II (Java)
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].原创 2015-01-29 12:15:18 · 409 阅读 · 0 评论 -
Jump Game II (Java)
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-01-29 17:16:22 · 398 阅读 · 0 评论 -
Edit Distance (Java)
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:原创 2015-01-29 11:15:44 · 1091 阅读 · 0 评论 -
Copy List with Random Pointer (Java)
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.这道题和clone graph那道题不同的地方在于,图可以d原创 2015-01-29 19:51:33 · 451 阅读 · 0 评论 -
Longest Consecutive Sequence (Java)
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2, 3原创 2015-01-29 10:06:38 · 412 阅读 · 0 评论 -
Recover Binary Search Tree (Java)
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-01-29 20:56:46 · 339 阅读 · 0 评论 -
Maximum Gap (Java)
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-01-31 10:32:02 · 1799 阅读 · 0 评论 -
First Missing Positive (Java)
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-04 16:17:39 · 425 阅读 · 0 评论 -
Best Time to Buy and Sell Stock III (Java)
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.Note:You may原创 2015-02-04 16:05:10 · 327 阅读 · 0 评论 -
Largest Rectangle in Histogram (Java)
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-02-04 20:56:57 · 376 阅读 · 0 评论 -
Scramble String (Java)
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原创 2015-02-04 22:22:32 · 487 阅读 · 0 评论 -
Maximal Rectangle (Java)
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.设一个数组表示从第一行开始遍历的当前列的高度,再用largest rectangle in histogram那道题的方法算最大面积。Sourcepubl原创 2015-02-05 10:33:20 · 386 阅读 · 0 评论 -
Merge Intervals (Java)
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].Source public List merge(List interva原创 2015-02-06 16:04:19 · 394 阅读 · 0 评论 -
Sudoku Solver (Java)
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-02-06 16:24:45 · 337 阅读 · 0 评论 -
Regular Expression Matching (Java)
Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input st原创 2015-02-07 11:21:57 · 429 阅读 · 0 评论 -
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-02-16 13:46:29 · 501 阅读 · 0 评论