![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leecode
文章平均质量分 81
youwuwei2012
这个作者很懒,什么都没留下…
展开
-
[leetcode] Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.题目就是给一个矩阵,找一个全是一的最大子矩阵。Code:[cpp] view plaincopyprint?转载 2014-06-24 14:35:19 · 469 阅读 · 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原创 2014-06-17 20:51:38 · 536 阅读 · 0 评论 -
[leetcode] pow(x,n)
实现浮点类型的幂运算,函数原型为:double pow(double x, int n)下面介绍一下解决该问题的几种方法以及要注意的地方:1)最直观容易想到的方法就是用递归方法求n个x的乘积,注意考虑n的正负号,时间复杂度为O(n).[cpp] view plaincopydouble pow(double x转载 2014-06-12 22:22:32 · 558 阅读 · 0 评论 -
[leetcode] Longest Consecutive Sequence
最初的想法是使用一个数组dp[1000]记录每个数字是否出现过,然后从小到大遍历一遍查找,看了测试数据后(数据太大),感觉这种方法不可行。实在想不出来了,参看了discuss,发现他们都是用容器实现的,首先将元素映射过去,然后判断左边和右边元素是否在map中,并且和以前的元素是否连续,这样进行之后,将访问过的元素标记为0.z这种方法是可以达到O(n)的。所以,以后想不出来的时候,试着去用一下容器。转载 2014-06-09 11:45:10 · 350 阅读 · 0 评论 -
[leetcode] Trapping Rain Water
博客原文:http://blog.csdn.net/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-06-08 22:02:18 · 361 阅读 · 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原创 2014-06-07 10:36:35 · 308 阅读 · 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原创 2014-06-20 14:53:57 · 363 阅读 · 0 评论 -
[leetcode] Palindrome Number
http://leetcode.com/2012/01/palindrome-number.html 注意边界条件的考虑原创 2014-06-07 14:59:01 · 318 阅读 · 0 评论 -
[leetcode] Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321题目很原创 2014-06-21 09:34:10 · 367 阅读 · 0 评论 -
[leetcode] Subsets II
和上一个差不多,但是有重复.有重复元素就挺麻烦的.比如1 1 1我每个1都是可以选或者不选那么第一个和第三个选了,第二个不选和第一个第二个选了第三个不选是一样的效果...可以按上一题的做法做,然后再去重... 那我们怎么搞呢? 想想我们的递归树再每一层不选重复元素,到下一层才选,那就去重了,不是么?因为转载 2014-06-11 11:31:39 · 361 阅读 · 0 评论 -
[leetcode] Search in Rotated Sorted Array II
Follow 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 to determine if a given target is in the转载 2014-06-06 12:14:00 · 269 阅读 · 0 评论 -
[leetcode] Regular Expression Matching
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转载 2014-06-22 16:32:05 · 348 阅读 · 0 评论 -
[leetcode] Merge k Sorted Lists
原文链接:http://blog.csdn.net/a83610312/article/details/8554241题目描述: 有一系列已排好序的链表,将其合并成有序的一张链表; 第一反应是运用胜者树或败者树可以很方便的求解;因为STL提供了堆操作的函数,所以这里借助堆来求解; 思路是:首先将k个链表的第一个节点集合,建堆,然转载 2014-06-19 14:48:55 · 356 阅读 · 0 评论 -
[leetcode] Recover Binary Search Tree
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 devise a转载 2014-06-19 10:19:20 · 373 阅读 · 0 评论 -
[leetcode] Combination Sum and Combination SumII
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina原创 2014-06-17 13:13:03 · 911 阅读 · 0 评论 -
[leetcode] Valid Number
1Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueclass Solution {public: bool isNumber(const char *s) {原创 2014-07-12 14:27:11 · 340 阅读 · 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转载 2014-06-18 10:26:36 · 320 阅读 · 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原创 2014-06-20 15:49:06 · 350 阅读 · 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"转载 2014-06-24 13:31:42 · 304 阅读 · 0 评论 -
[leetcode] Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.1. 二分法:这道题一看到函数的定义int sqrt(int x)都是int就高兴了,直接二分吧。但是要注意,即使用long long都TM越界,还要用unsigned long long。最后返回值还要再检查一下。[cpp转载 2014-06-24 10:03:23 · 550 阅读 · 0 评论 -
[leetcode] 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 stock转载 2014-06-23 16:39:13 · 443 阅读 · 0 评论 -
[leetcode] 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 / \ gr转载 2014-06-23 19:02:25 · 377 阅读 · 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转载 2014-06-24 14:34:43 · 375 阅读 · 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:转载 2014-06-25 13:16:07 · 322 阅读 · 0 评论 -
[leetcode] word ladder
对于之前没有接触过该类型题目的人来说,此题无疑是个难题,本人提交了10次才正确通过,期间遇到了非常多的问题,感觉几乎把OJ的所有错误遍历了一遍,下面详细说说自己做该题的经验。首先承认,我一开始并没有想到什么图模型,或者说是一点思路都没有。然后我就冥思苦想,首先想到了可以先构造一个二维矩阵,判断给定的词之间是否能两两一步到达,这一步可以通过两层循环加字符串的遍历完成,应该转载 2014-07-19 14:38:33 · 433 阅读 · 0 评论 -
[leetcode] Word Break
Given 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 = "leetcode",dict =转载 2014-06-30 10:54:13 · 338 阅读 · 0 评论 -
[leetcode] Gray Code
首先介绍格雷码的两种转换方式:递归生成码表这种方法基于格雷码是反射码的事实,利用递归的如下规则来构造:1位格雷码有两个码字(n+1)位格雷码中的前2n个码字等于n位格雷码的码字,按顺序书写,加前缀0(n+1)位格雷码中的后2n个码字等于n位格雷码的码字,按逆序书写,加前缀12位格雷码3位格雷码4元格雷码原创 2014-07-02 20:15:45 · 417 阅读 · 0 评论 -
[leetcode] Sort List
Sort List Sort a linked list in O(n log n) time using constant space complexity. 对一个链表进行排序,且时间复杂度要求为 O(n log n) ,空间复杂度为常量。一看到 O(n log n) 的排序,首先应该想到归并排序和快速排序,但是通常我们使用这两种排序方法时都是针对数组转载 2014-07-02 10:45:56 · 321 阅读 · 0 评论 -
[leetcode] 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet转载 2014-07-04 22:33:48 · 345 阅读 · 0 评论 -
[leetcode] climbing Stairs
Climbing StairsYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?题目原创 2014-07-09 15:56:14 · 372 阅读 · 0 评论 -
[leetcode] Gas Station
解题思路1:1:假设出发车站为0,初始化车内油量02:车内油量=车站油量-消耗3:如果车内油量大于0,车开到下一车站,否则出发车站前移一个车站重复2,3步,直到所有车站遍历完。如果车内油量剩余大于等于0,返回出发车站,否则返回-1.转载 2014-06-16 16:57:01 · 625 阅读 · 0 评论 -
[leetcode] Candy
原题: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 l转载 2014-07-10 10:15:35 · 343 阅读 · 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原创 2014-07-12 09:42:19 · 436 阅读 · 0 评论 -
[leetcode] Single Number II
Single Number的加强班有n个数字,除了一个只出现过一次,其他的都出现了3次!出现两次我们知道就是xor下就木有啦,那3次怎么搞? 我们还是用二进制位的方式来思考。那么这些位,除去出现过一次的那个后,其他的都是3的倍数!- -我们把所有位1的个数mod 3,那么剩下的就是只出现过一次那个啦。我们也没必要开个啥 int bit[32]的数组去统计的= =我们来模转载 2014-05-15 16:18:51 · 336 阅读 · 0 评论