leetcode
文章平均质量分 79
salutlu
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 elements from原创 2014-03-15 00:15:09 · 603 阅读 · 0 评论 -
[LeetCode]Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product. For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the larges原创 2014-09-25 23:29:18 · 2923 阅读 · 1 评论 -
Best Time to Buy and Sell Stock III
Total Accepted: 8400 Total Submissions: 38235 My Submissions 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 profi原创 2014-05-14 13:35:57 · 869 阅读 · 0 评论 -
Convert Sorted List to Binary Search Tree
Convert Sorted List to Binary Search Tree Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 想了好久想不出来,后来看了题目分类里面说是DFS,但是没有想出DFS的算法来。后来想到了原创 2014-04-26 00:02:38 · 8166 阅读 · 1 评论 -
Trapping Rain Water
Trapping Rain Water 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原创 2014-04-25 13:33:32 · 958 阅读 · 0 评论 -
K sum
这里有一个介绍的比较系统的Ksum文章 http://tech-wonderland.net/blog/summary-of-ksum-problems.html 前言: 做过leetcode的人都知道, 里面有2sum, 3sum(closest), 4sum等问题, 这些也是面试里面经典的问题, 考察是否能够合理利用排序这个性质, 一步一步得到高效的算法. 经过总结,转载 2014-05-16 16:06:28 · 7382 阅读 · 0 评论 -
Palindrome Partitioning
http://blog.youkuaiyun.com/u011095253/article/details/9177451 这道题mei'you原创 2014-05-04 21:54:30 · 596 阅读 · 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 sequence of原创 2014-03-15 12:50:19 · 732 阅读 · 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? 这个for循环中的下标非常容易搞混,一定要区分清楚,到底固定哪一列,对于第二个for里面,i相当于常量原创 2014-03-15 21:19:55 · 652 阅读 · 0 评论 -
Best Time to Buy and Sell Stock II
Best Time to Buy and Sell Stock II 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 as ma原创 2014-03-10 17:28:08 · 1311 阅读 · 0 评论 -
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, given s = "leetcode", dict = ["leet"原创 2014-02-18 15:06:04 · 653 阅读 · 0 评论 -
Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the fo原创 2014-03-14 13:36:24 · 617 阅读 · 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 length. 刚看到原创 2014-03-12 12:33:16 · 599 阅读 · 0 评论 -
Climbing Stairs
You 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-03-12 11:15:52 · 623 阅读 · 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,2,1] ha原创 2014-03-12 10:46:28 · 4027 阅读 · 0 评论 -
Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. 相比第一次写的代码,这次的看起来有点代码之原创 2014-03-11 13:08:21 · 666 阅读 · 0 评论 -
Pow(x, n)
Implement pow(x, n). 第一感觉就是不能O(n),于是想了一个递归O(lgn)的办法,但是为了处理x和n的符号情况用了一个子函数。 发现了一个int最小值问题,这里(http://bukkake.iteye.com/blog/712953)有详细的介绍。 如果int值是(-2147483648),int的最小值,则取符号相反的情况,在VS里面是不会有变化的。但是原创 2014-02-20 15:33:23 · 2165 阅读 · 0 评论 -
Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the target, whe原创 2014-02-20 14:00:31 · 636 阅读 · 0 评论 -
Gas Station
Gas Station There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from st原创 2014-02-19 16:48:33 · 816 阅读 · 0 评论
分享