leetcode
文章平均质量分 65
mlweixiao
这个作者很懒,什么都没留下…
展开
-
leetcode 4 ADD TWO NUMBERS
Youare given two linked lists representing two non-negative numbers. The digitsare stored in reverse order and each of their nodes contain a single digit. Addthe two numbers and return it as a linke原创 2014-05-06 22:11:24 · 448 阅读 · 0 评论 -
leetcode 9 Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.原创 2014-05-06 22:18:13 · 455 阅读 · 0 评论 -
leetcode 25 Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2014-05-06 22:58:09 · 389 阅读 · 0 评论 -
leetcode 3 LONGEST SUBSTRING WITHOUT REPEATING CHARACTERS
Given astring, 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. For"bbb原创 2014-05-06 22:08:10 · 473 阅读 · 0 评论 -
leetcode 11 Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin原创 2014-05-06 22:36:01 · 635 阅读 · 0 评论 -
leetcode 16 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 exact原创 2014-05-06 22:44:09 · 420 阅读 · 0 评论 -
leetcode 13 Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.原创 2014-05-06 22:41:23 · 549 阅读 · 0 评论 -
leetcode 15 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 (a,b,c原创 2014-05-06 22:42:56 · 444 阅读 · 0 评论 -
leetcode 12 Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.class Solution {public: string intToRoman(int num) { string ans;原创 2014-05-06 22:39:24 · 722 阅读 · 0 评论 -
leetcode 19 Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2014-05-06 22:48:44 · 371 阅读 · 0 评论 -
leetcode 2 MEDIAN OF TWO SORTED ARRAYS
There are two sorted arrays A and B of size mand n respectively. Find the median of the two sorted arrays. The overall runtime complexity should be O(log (m+n)).原创 2014-05-06 22:05:45 · 437 阅读 · 0 评论 -
leetcode 7 REVERSE INTEGER
Reversedigits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Haveyou thought about this?Here are some good questions to askbefore coding. Bonus points for you if you原创 2014-05-06 22:13:31 · 484 阅读 · 0 评论 -
leetcode 20 Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2014-05-06 22:50:00 · 342 阅读 · 0 评论 -
leetcode 8 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-05-06 22:16:20 · 433 阅读 · 0 评论 -
leetcode 26 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.p原创 2014-05-06 22:59:21 · 386 阅读 · 0 评论 -
leetcode 151 Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Clarification:What constitutes原创 2014-05-06 23:01:24 · 572 阅读 · 0 评论 -
LeetCode 14 Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.原创 2014-06-23 13:39:19 · 406 阅读 · 0 评论 -
LeetCode 52 Maximum Subarray
Given 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,1].原创 2014-06-25 06:47:44 · 405 阅读 · 0 评论 -
LeetCode 123 Best Time to Buy and Sell Stock III
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 at most two transactions.Note:You ma原创 2014-06-25 21:05:54 · 750 阅读 · 0 评论 -
LeetCode 90 Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total nu原创 2014-06-27 09:29:57 · 739 阅读 · 0 评论 -
LeetCode 22 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.递归版原创 2014-06-25 16:29:42 · 397 阅读 · 0 评论 -
LeerCode 123 Best Time to Buy and Sell Stock III之O(n)解法
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 at most two transactions.Note:You转载 2014-06-25 21:27:15 · 1237 阅读 · 0 评论 -
LeetCode 121 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-21 09:57:48 · 1051 阅读 · 0 评论 -
leetcode 1 Two Sum
Given an array of integers,find two numbers such that they add up to a specific target number.The function twoSum shouldreturn indices of the two numbers such that they add up to the target, wherein原创 2014-05-06 22:02:50 · 458 阅读 · 0 评论 -
LeetCode 28 Divide Two Integers
Divide two integers without using multiplication, division and mod operator.思路:1.先将被除数和除数转化为long的非负数,注意一定要为long,因为Integer.MIN_VALUE的绝对值超出了Integer的范围。 2.常理:任何正整数num都可以表示为num=2^a+2^b+2^c+..原创 2014-06-23 12:34:57 · 1382 阅读 · 0 评论 -
LeetCode 118 Pascal's Triangle
Given 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]]原创 2014-07-01 11:44:29 · 379 阅读 · 0 评论 -
LeetCode 119 Pascal's Triangle II
Given 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) extra space?原创 2014-07-01 11:46:20 · 471 阅读 · 0 评论 -
LeetCode 120 Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [原创 2014-07-01 09:57:27 · 458 阅读 · 0 评论 -
LeetCode 56 Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.E原创 2014-07-02 20:53:38 · 540 阅读 · 0 评论 -
LeetCode 78 Subsets
Given 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 subsets.For example,原创 2014-07-02 01:12:29 · 430 阅读 · 0 评论 -
LeetCode 31 Longest Valid Parentheses
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()",原创 2014-07-01 16:41:44 · 370 阅读 · 0 评论 -
LeetCode 32 Search in Rotated Sorted Array
Suppose 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 to search. If found in the array retur原创 2014-07-02 18:40:13 · 386 阅读 · 0 评论 -
LeetCode 81 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-07-02 18:42:37 · 505 阅读 · 0 评论 -
LeetCode 91 Subsets II
Given 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 must not contain duplica原创 2014-07-02 18:46:22 · 446 阅读 · 0 评论 -
LeetCode 55 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].原创 2014-07-02 20:40:36 · 397 阅读 · 0 评论 -
LeetCode 105 Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.思路:digui原创 2014-07-03 19:10:03 · 463 阅读 · 0 评论 -
LeetCode 147 Insertion Sort List
Sort a linked list using insertion sort.原创 2014-07-03 16:01:01 · 477 阅读 · 0 评论 -
LeetCode 110 Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe原创 2014-07-03 22:36:53 · 537 阅读 · 0 评论 -
LeetCode 74 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 integer of each原创 2014-07-03 12:35:55 · 660 阅读 · 0 评论 -
LeetCode 106 Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.silu原创 2014-07-03 19:11:50 · 786 阅读 · 0 评论