
leetcode
文章平均质量分 60
aay.zhang
嘿嘿~~
展开
-
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.原创 2012-11-18 23:52:27 · 888 阅读 · 0 评论 -
LeetCode Search a 2D Matrix
Search a 2D MatrixWrite an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to rig原创 2012-11-20 23:12:27 · 449 阅读 · 0 评论 -
LeetCode Search in Rotated Sorted Array
Search in Rotated Sorted ArraySuppose 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原创 2012-11-21 13:06:59 · 483 阅读 · 0 评论 -
LeetCode Search in Rotated Sorted Array II
Search in Rotated Sorted Array IIFollow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function t原创 2012-11-21 13:36:32 · 760 阅读 · 0 评论 -
LeetCode Search Insert Position
Search Insert PositionGiven a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume原创 2012-11-21 13:43:44 · 459 阅读 · 0 评论 -
LeetCode Simplify Path
Simplify PathGiven an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"Corner Cases:Did you原创 2012-11-21 14:37:06 · 471 阅读 · 0 评论 -
LeetCode Search for a Range
Search for a RangeGiven a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If原创 2012-11-21 12:58:35 · 420 阅读 · 0 评论 -
LeetCode Set Matrix Zeroes
Set Matrix ZeroesGiven a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn原创 2012-11-21 14:20:06 · 462 阅读 · 0 评论 -
LeetCode Rotate List
Rotate ListGiven 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.Solution:/原创 2012-11-20 21:50:42 · 450 阅读 · 0 评论 -
LeetCode Same Tree
Same TreeGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value原创 2012-11-20 21:58:50 · 508 阅读 · 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 = "AB原创 2012-11-20 16:45:41 · 562 阅读 · 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)).原创 2012-11-20 15:41:15 · 603 阅读 · 0 评论 -
LeetCode Maximum Depth of Binary Tree
Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.原创 2012-11-19 00:56:53 · 531 阅读 · 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原创 2012-11-19 01:33:21 · 417 阅读 · 0 评论 -
LeetCode Merge Intervals
Merge IntervalsGiven 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].Solution:/** * Definitio原创 2012-11-19 01:34:15 · 529 阅读 · 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.Solution:O(n*logk),n is the length of each list,k is the number of l原创 2012-11-19 02:01:37 · 679 阅读 · 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原创 2012-11-18 01:39:44 · 449 阅读 · 0 评论 -
LeetCode Merge two Sorted Array
Merge Sorted ArrayGiven two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements from B. The number of原创 2012-11-19 02:21:34 · 589 阅读 · 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.Solution:O(m*n),a combination of the problem:LeetCod原创 2012-11-19 15:34:47 · 508 阅读 · 0 评论 -
LeetCode Minimum Path Sum
Minimum Path SumGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move原创 2012-11-19 21:33:05 · 430 阅读 · 0 评论 -
LeetCode Spiral Matrix
Spiral MatrixGiven a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6原创 2012-11-22 22:39:05 · 518 阅读 · 0 评论 -
LeetCode Spiral Matrix II
Spiral Matrix IIGiven an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1,原创 2012-11-22 22:47:15 · 470 阅读 · 0 评论 -
LeetCode Path Sum II
Path Sum IIGiven a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5原创 2012-11-23 23:34:39 · 584 阅读 · 0 评论 -
LeetCode Permutation Sequence
Permutation SequenceThe 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):原创 2012-11-24 00:05:54 · 542 阅读 · 0 评论 -
LeetCode Permutation
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,原创 2012-11-24 00:08:47 · 640 阅读 · 0 评论 -
LeetCode Permutations II
Permutations IIGiven 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],原创 2012-11-24 00:52:27 · 618 阅读 · 0 评论 -
LeetCode Plus One
Plus OneGiven a number represented as an array of digits, plus one to the number.Solution:class Solution {public: vector plusOne(vector &digits) { // Start typing your C/C++原创 2012-11-24 00:59:58 · 583 阅读 · 0 评论 -
LeetCode Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each NodeGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate ea原创 2012-11-24 01:12:02 · 619 阅读 · 0 评论 -
LeetCode Populating Next Right Pointers in Each Node II
Populating Next Right Pointers in Each Node IIFollow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solutio原创 2012-11-24 01:30:09 · 1439 阅读 · 0 评论 -
LeetCode Pow(x,n)
Pow(x, n)Implement pow(x, n).Tips:Notice negetive pows.Solution:class Solution {public: double pow(double x, int n) { // Start typing your C/C++ solution below /原创 2012-11-24 01:43:33 · 737 阅读 · 0 评论 -
LeetCode Path Sum
Path SumGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary原创 2012-11-23 23:16:32 · 481 阅读 · 0 评论 -
LeetCode Pascal's Triangle II
Pascal's Triangle IIGiven an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k)原创 2012-11-23 22:59:22 · 661 阅读 · 0 评论 -
LeetCode Pascal's Triangle
Pascal's TriangleGiven numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]S原创 2012-11-23 22:56:42 · 686 阅读 · 0 评论 -
LeetCode sqrt(x)
Sqrt(x)Implement int sqrt(int x).Compute and return the square root of x.An intreasting Solution:1+3+5+7+...+(2n-1)=n*nclass Solution {public: int sqrt(int x) { // S原创 2012-11-22 23:00:06 · 530 阅读 · 0 评论 -
LeetCode String to Integer(atoi)
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原创 2012-11-22 23:16:11 · 540 阅读 · 0 评论 -
LeetCode Sort Colors
Sort ColorsGiven an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we wil原创 2012-11-22 18:28:16 · 460 阅读 · 0 评论 -
LeetCode Subsets
SubsetsGiven 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 subset原创 2012-11-22 23:22:16 · 513 阅读 · 0 评论 -
LeetCode SubSets II
Subsets IIGiven 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 mu原创 2012-11-22 23:34:43 · 544 阅读 · 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.Solution:cl原创 2012-11-23 00:29:26 · 496 阅读 · 0 评论 -
LeetCode Palindrome Number
Palindrome NumberDetermine 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 convertin原创 2012-11-23 22:04:02 · 480 阅读 · 0 评论