leetcode
文章平均质量分 71
hycanye111
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
leetcode 复习(更新中)
1:题目:Median of Two Sorted Arrays 描述: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原创 2015-03-15 16:38:38 · 434 阅读 · 0 评论 -
Word Ladder
原文地址:http://www.mysjtu.com/page/M0/S951/951547.htmlProblem Link:http://oj.leetcode.com/problems/word-ladder/Two typical techniques are inspected in this problem:Hash Table. O转载 2015-01-14 20:38:21 · 351 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
原文地址:http://blog.youkuaiyun.com/salutlu/article/details/24502109Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.想了好久想不出来,后来看了题目分类里面说是DFS,但是没有转载 2015-01-30 17:14:06 · 352 阅读 · 0 评论 -
gas station
原文链接http://www.cnblogs.com/felixfang/p/3814463.htmlLeetCode上 Gas Station是比较经典的一题,它的魅力在于算法足够优秀的情况下,代码可以简化到非常简洁的程度。原题如下Gas StationThere are N gas stations along a circular route, where t转载 2014-12-08 13:53:08 · 333 阅读 · 0 评论 -
Maximal Rectangle
原文地址:http://blog.youkuaiyun.com/littlestream9527/article/details/19641013方法二的参考地址:http://hi.baidu.com/mzry1992/item/030f9740e0475ef7dc0f6cba隔了一个月又回来了。这题之前做过,思路就是根据上一题中求直方图中的最大矩形面积来求全部包含1的最大矩形面积,就是多加转载 2014-12-23 15:43:36 · 491 阅读 · 0 评论 -
Word Break
Problem DescriptionGiven a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "lee转载 2014-12-22 22:22:04 · 313 阅读 · 0 评论 -
POW(X,N)
原文地址:http://blog.youkuaiyun.com/fengbingyang/article/details/12236121实现浮点类型的幂运算,函数原型为:double pow(double x, int n)下面介绍一下解决该问题的几种方法以及要注意的地方:1)最直观容易想到的方法就是用递归方法求n个x的乘积,注意考虑n的正负号,时间复杂度为O(n转载 2014-12-07 23:32:07 · 295 阅读 · 0 评论 -
Largest Rectangle in Histogram
原文地址:http://blog.youkuaiyun.com/doc_sgl/article/details/11805519Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectang转载 2014-12-22 14:07:00 · 347 阅读 · 0 评论 -
sqrt(x)
原文地址:http://blog.youkuaiyun.com/doc_sgl/article/details/12404971Implement int sqrt(int x).Compute and return the square root of x.1. 二分法:这道题一看到函数的定义int sqrt(int x)都是int就高兴了,直接二分吧。但是要注意,即使用lo转载 2014-12-20 18:53:34 · 343 阅读 · 0 评论 -
Maximum Gap
题目: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 e原创 2014-12-18 23:20:00 · 363 阅读 · 0 评论 -
Best Time to Buy and Sell Stock III
原文地址:http://www.cnblogs.com/lihaozy/archive/2012/12/19/2825525.html#include #include using namespace std;class Solution {public:/*解释:首先,因为能买2次(第一次的卖可以和第二次的买在同一时间),但第二次的买不能在第一次的卖左边。所以转载 2014-12-18 22:52:19 · 323 阅读 · 0 评论 -
Edit Distance
原文地址:http://www.cnblogs.com/lihaozy/archive/2012/12/31/2840152.html[leetcode]Edit Distance先给一个例子,两个字符串eeba和abca相似度是多少呢,edit distance是一个很好的度量,定义从字符串a变到字符串b,所需要的最少的操作步骤(插入,删除,更改)为两个字符串之间的编辑距离。转载 2014-12-08 22:25:27 · 268 阅读 · 0 评论 -
Palindrome Partitioning II
原文地址:http://blog.youkuaiyun.com/doc_sgl/article/details/13418125Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindro转载 2015-01-13 22:17:26 · 271 阅读 · 0 评论 -
The Skyline Problem
题目:The Skyline ProblemA city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and原创 2015-05-28 09:33:41 · 598 阅读 · 0 评论 -
Best Time to Buy and Sell Stock IV
原文地址:http://www.cnblogs.com/grandyang/p/4295761.htmlSay 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 m转载 2015-03-11 16:20:24 · 429 阅读 · 0 评论 -
Repeated DNA Sequences
原文地址:http://blog.youkuaiyun.com/u013325815/article/details/43601367All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, i转载 2015-02-08 20:57:32 · 310 阅读 · 0 评论 -
Permutations II
Permutations IIMar 17 '124943 / 12877Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique pe转载 2014-12-15 13:09:37 · 300 阅读 · 0 评论 -
median of two sorted arrays
原文地址:http://blog.youkuaiyun.com/yutianzuijin/article/details/11499917/首先假设数组A和B的元素个数都大于k/2,我们比较A[k/2-1]和B[k/2-1]两个元素,这两个元素分别表示A的第k/2小的元素和B的第k/2小的元素。这两个元素比较共有三种情况:>、证明也很简单,可以采用反证法。假设A[k/2-1]大于合并之后的转载 2015-01-17 09:12:28 · 450 阅读 · 0 评论 -
Distinct Subsequences
原文地址:http://www.cnblogs.com/ganganloveu/p/3836519.htmlDistinct SubsequencesGiven a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is转载 2014-12-10 13:51:32 · 289 阅读 · 0 评论 -
Longest Palindromic Substring
原文地址:http://leetcode.com/2011/11/longest-palindromic-substring-part-ii.htmlGiven a string S, find the longest palindromic substring in S.Note:This is Part II of the article: Longest转载 2015-02-04 08:16:06 · 413 阅读 · 0 评论 -
Merge k Sorted Lists
自己写的就是很普通的递归,每次分成2半,返回merge后的数组,时间复杂度为nlogk下面的方法时间复杂度一样,不过思路更好,虽然在leetcode上我自己的代码时间更短些,但是相差不多,下面用来拓展思路。简单说下:下面就是利用堆来做,其余的自己看代码原文地址:http://cozilla.iteye.com/blog/1851712/** * Definitio转载 2014-12-24 21:06:26 · 301 阅读 · 0 评论 -
Substring with Concatenation of All Words
原文地址:http://www.2cto.com/kf/201406/311648.htmlYou 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 concatenati转载 2015-01-14 22:35:00 · 284 阅读 · 0 评论 -
First Missing Positive
原文地址:http://blog.163.com/ya_mzy/blog/static/199593255201361793545926/先上题目。 再谈思路。一个最简单的方法就是先排序,然后扫一遍找出第一个不连续的正数。大致的代码如下,没测试。int firstMissingPositive(int A[], int n){ sort转载 2014-12-17 16:02:36 · 274 阅读 · 0 评论 -
ZigZag Conversion
原文地址:http://www.cnblogs.com/sanghai/p/3632528.html自己的方法比较笨拙,是依此计算每个点在下面这个结构中的坐标,然后再输出,下面这个方法更加简洁。Zigzag:即循环对角线结构(0 8 16 1转载 2014-12-17 13:58:25 · 277 阅读 · 0 评论 -
Scramble String
题目: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 /原创 2014-12-16 23:31:22 · 310 阅读 · 0 评论 -
Set Matrix Zeroes
题目:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Follow up:Did you use extra space?A straight forward solution us原创 2014-07-19 17:25:45 · 406 阅读 · 0 评论 -
Search a 2D Matrix
题目:Write 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 right.The first intege原创 2014-07-18 15:48:25 · 308 阅读 · 0 评论 -
Container with most water
原文网址:http://blog.youkuaiyun.com/a83610312/article/details/8548519转载 2014-07-18 23:29:16 · 282 阅读 · 0 评论 -
Rotate Image
题目:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?思路:我原创 2014-07-18 14:31:27 · 337 阅读 · 0 评论 -
Linked List Cycle II
题目:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?原创 2014-07-19 10:05:11 · 309 阅读 · 0 评论 -
Best Time to Buy and Sell Stock
题目:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the原创 2014-07-18 10:26:45 · 263 阅读 · 0 评论 -
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 to m + n) to hold additional element原创 2014-07-17 10:58:28 · 296 阅读 · 0 评论 -
Gray Code
题目:The 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 seque原创 2014-07-17 11:46:36 · 294 阅读 · 0 评论 -
Remove Element
题目:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new lengt原创 2014-07-16 13:23:07 · 260 阅读 · 0 评论 -
Maximum Subarray
题目:Find 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 subarray [4,−1,原创 2014-07-16 10:13:32 · 334 阅读 · 0 评论 -
Generate Parentheses
题目:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())"原创 2014-07-18 08:59:29 · 331 阅读 · 0 评论 -
Trapping Rain Water
原文网址:http://blog.youkuaiyun.com/doc_sgl/article/details/12307171Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to tra转载 2014-07-31 14:58:10 · 280 阅读 · 0 评论 -
Anagrams
原文地址:http://www.cnblogs.com/easonliu/p/3643595.htmlGiven an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.这题先得知道啥叫Anagrams,知道后其实很简单。转载 2014-12-16 14:46:24 · 308 阅读 · 0 评论 -
Recover Binary Search
原文地址:http://blog.youkuaiyun.com/worldwindjp/article/details/21694179Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution转载 2014-12-16 14:45:09 · 231 阅读 · 0 评论 -
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 exactly转载 2014-10-12 15:34:46 · 263 阅读 · 0 评论
分享