随笔分类 -  leetcode解题报告

leetcode : Edit Distance
摘要:Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the fol... 阅读全文

posted @ 2014-12-08 21:16 远近闻名的学渣 阅读(179) 评论(0) 推荐(0)

leetcode : Maximal Rectangle & Maximum Subarray & Largest Rectangle in Histogram
摘要:1,Maximum Subarray大致就是给一个int型数组,求一个长度最小为1的子数组,使得里面的数加起来和最大。很经典的dp题,方法是对于每一个i,求出以i结尾的最大子数组。而求以i 为结尾的最大子数组的问题可以变成,求以i - 1为结尾的最大子数组的值max_(i - 1),然后比较i 与m... 阅读全文

posted @ 2014-12-07 22:51 远近闻名的学渣 阅读(139) 评论(0) 推荐(0)

leetcode : 3sum
摘要:Given an arraySofnintegers, are there elementsa,b,cinSsuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:Elemen... 阅读全文

posted @ 2014-12-06 23:08 远近闻名的学渣 阅读(185) 评论(1) 推荐(0)

leetcode : Rotate Image
摘要:You are given annxn2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?要在(1)的空间复杂度完成,所以一次转... 阅读全文

posted @ 2014-12-06 17:37 远近闻名的学渣 阅读(124) 评论(0) 推荐(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]./** * Definiti... 阅读全文

posted @ 2014-12-05 22:34 远近闻名的学渣 阅读(131) 评论(0) 推荐(0)

leetcode : Minimum Window Substring
摘要:Given 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="ADOBECODEBA... 阅读全文

posted @ 2014-11-29 21:45 远近闻名的学渣 阅读(148) 评论(0) 推荐(0)

leetcode : Search a 2D Matrix
摘要:Write an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from l... 阅读全文

posted @ 2014-11-28 22:39 远近闻名的学渣 阅读(177) 评论(1) 推荐(0)

leetcode : Set Matrix Zeroes
摘要:Given amxnmatrix, 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... 阅读全文

posted @ 2014-11-28 22:14 远近闻名的学渣 阅读(156) 评论(0) 推荐(0)

leetcode : Largest Rectangle in Histogram
摘要:Givennnon-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histog... 阅读全文

posted @ 2014-11-28 11:30 远近闻名的学渣 阅读(180) 评论(0) 推荐(0)

leetcode : Sqrt(x)
摘要:Implementint sqrt(int x).Compute and return the square root ofx.只要返回int值,用二分查找,但是整型会溢出,更坑爹的是,当你发生溢出的时候提示的是超时。。。。。所以用除法而不用乘法AC代码:class Solution {public... 阅读全文

posted @ 2014-11-27 12:34 远近闻名的学渣 阅读(139) 评论(0) 推荐(0)

leetcode : Combinations
摘要:Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3],... 阅读全文

posted @ 2014-11-27 11:23 远近闻名的学渣 阅读(107) 评论(0) 推荐(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 "adjace... 阅读全文

posted @ 2014-11-26 21:39 远近闻名的学渣 阅读(172) 评论(0) 推荐(0)

leetcode : Partition List
摘要:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the origi... 阅读全文

posted @ 2014-11-26 14:14 远近闻名的学渣 阅读(127) 评论(0) 推荐(0)

leetcode : Scramble String
摘要:Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation... 阅读全文

posted @ 2014-11-25 21:56 远近闻名的学渣 阅读(133) 评论(0) 推荐(0)

leetcode : Merge Sorted Array
摘要:Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal... 阅读全文

posted @ 2014-11-25 09:42 远近闻名的学渣 阅读(113) 评论(0) 推荐(0)

leetcode : Decode Ways
摘要:A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message conta... 阅读全文

posted @ 2014-11-25 09:24 远近闻名的学渣 阅读(162) 评论(0) 推荐(0)

leetcode : Unique Binary Search Trees I&II
摘要:Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's.I是要求... 阅读全文

posted @ 2014-11-25 09:10 远近闻名的学渣 阅读(162) 评论(0) 推荐(0)

leetcode : Reverse Linked List II
摘要:Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No... 阅读全文

posted @ 2014-11-24 17:23 远近闻名的学渣 阅读(117) 评论(0) 推荐(0)

leetcode : Interleaving String
摘要:Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="... 阅读全文

posted @ 2014-11-24 15:03 远近闻名的学渣 阅读(168) 评论(0) 推荐(0)

leetcode : Validate Binary Search Tree
摘要:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n... 阅读全文

posted @ 2014-11-24 10:32 远近闻名的学渣 阅读(139) 评论(0) 推荐(0)

导航