c++
文章平均质量分 61
lqcsp
这个作者很懒,什么都没留下…
展开
-
Line reconstruction by height
ProblemSuppose you have a line of n people in which the k-th person is described by a pair (h,t) , where h is the height of the k-th person and t is the number of people in front of k who have a height原创 2016-08-23 16:03:13 · 662 阅读 · 0 评论 -
LeetCode(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原创 2014-04-10 07:22:55 · 512 阅读 · 0 评论 -
LeetCode(Path Sum and Path Sum 2)
题目要求:Path Sum Total Accepted: 10595 Total Submissions: 35321My SubmissionsGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the原创 2014-04-11 04:57:34 · 1031 阅读 · 0 评论 -
LeetCode Search for a Range
题目要求:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is原创 2014-05-14 03:43:41 · 480 阅读 · 0 评论 -
LeetCode Multiply Strings 大数相乘
题目要求:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.daima原创 2014-05-13 02:14:37 · 865 阅读 · 0 评论 -
LeetCode 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原创 2014-05-13 04:43:58 · 716 阅读 · 0 评论 -
LeetCode(Longest Consecutive Sequence ) 最长连续序列
题目要求:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence原创 2014-05-12 23:40:58 · 678 阅读 · 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 us原创 2014-05-13 23:02:49 · 531 阅读 · 0 评论 -
Leetcode Distinct Subsequences
题目要求:原创 2014-08-19 14:31:32 · 575 阅读 · 0 评论 -
LeetCode(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原创 2014-04-25 05:15:37 · 533 阅读 · 0 评论 -
LeetCode(Binary Tree Maximum Path Sum) 在二叉树中找出一条和最大的路径
题目要求:Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3R原创 2014-04-25 01:56:25 · 938 阅读 · 0 评论 -
LeetCode(Permutations) 数列的全排列
题目要求: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-04-09 09:35:26 · 764 阅读 · 0 评论 -
LeetCode(Permutations II)
题目要求:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], a原创 2014-04-09 12:28:29 · 678 阅读 · 0 评论 -
LeetCode(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.原创 2014-04-25 03:17:32 · 2483 阅读 · 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 nodes with keys less than the no原创 2014-04-25 02:32:58 · 948 阅读 · 0 评论 -
LeetCode (Longest Palindromic Substring ) 找出最长回文字串
题目要求:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.思路: 遍原创 2014-04-10 22:27:43 · 542 阅读 · 0 评论 -
LeetCode(Permutation Sequence)输出全排列中第k个排列
题目要求: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""原创 2014-04-10 05:23:16 · 6777 阅读 · 0 评论 -
LeetCode(atoi)实现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-04-10 23:17:01 · 680 阅读 · 0 评论 -
LeetCode(3 Sum, 4sum, ksum)
题目要求: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 tri原创 2014-04-11 04:00:54 · 750 阅读 · 0 评论 -
Leetcode 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,1,0,2,1,0,1,3,2,1,2,1]原创 2014-08-10 16:12:04 · 443 阅读 · 0 评论 -
Leetcode(Sort Colors )
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers原创 2014-08-09 16:44:37 · 580 阅读 · 0 评论 -
37. Sudoku Solver
ProblemWrite a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character .You may assume that there will be only one unique solution. A sudoku puzzle…Solut原创 2016-08-21 16:01:08 · 346 阅读 · 0 评论 -
38. Count and Say
ProblemThe count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, ...1is read off as "one 1" or 11 11is read off as"two 1s"or21 21is read off as"one 2then原创 2016-08-21 16:01:57 · 330 阅读 · 0 评论 -
384. Shuffle an Array
@(leetcode)[数组]ProblemShuffle a set of numbers without duplicates.Example: // Init an array with set 1, 2, and 3. int[] nums = {1,2,3}; Solution solution = new Solution(nums); // Shuffle the原创 2016-08-21 16:02:53 · 385 阅读 · 0 评论 -
386. Lexicographical Numbers
ProblemGiven an integer n, return 1 - n in lexicographical order.For example, given 13, return:[1,10,11,12,13,2,3,4,5,6,7,8,9].Please optimize your algorithm to use less time and space. The input size原创 2016-08-21 16:28:49 · 1432 阅读 · 0 评论 -
Maximum traffic between city and its neighbors
@(leetcode)[图论|Google]ProblemYou are given a graph with no cycles, each node representing different cities and there are stadiums for baseball games in all cities. Each node contains a value representi原创 2016-08-22 16:54:17 · 647 阅读 · 0 评论 -
Shortest substring containing three short strings
@(leetcode)[字符串, Google]ProblemGiven a long string s and short strings t1, t2, t3 (which can have different length) find the shortest substring of s which contains t1, t2 and t3.Example: s = "abcdefgh原创 2016-08-22 16:55:10 · 523 阅读 · 0 评论 -
Find number of subsets with equal sum
@(leetcode)[动态规划|Google]ProblemGiven a number N ( N > 1), gives a set S = [1,2,..., N]. Divide S in two subsets such that S1 ∪ S2 = S and S1 ∩ S2 = Ø and return the number of subsets with equal sum.Ex原创 2016-08-23 13:26:47 · 534 阅读 · 0 评论 -
The longest absolute path in file system
The longest absolute path in file system@(leetcode)[字符串|DFS|Google] The string "dir\n\tsubdir1\n\tsubdir2\n\t\tfile.ext" represents:dir subdir1 subdir2 file.exta directory dir contains an原创 2016-08-23 13:07:48 · 595 阅读 · 0 评论 -
59. Spiral Matrix II
ProblemGiven an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example, Given n = 3,You should return the following matrix: [ [ 1, 2, 3 ], [ 8, 9,原创 2016-08-21 15:59:54 · 284 阅读 · 0 评论 -
Word Ladder II
Given two words (beginWord and endWord), and a dictionary’s word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one letter can be changed at a time Each i原创 2016-08-21 15:58:47 · 380 阅读 · 0 评论 -
Leetcode (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-08-09 17:18:50 · 481 阅读 · 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-08-09 21:36:39 · 474 阅读 · 0 评论 -
LeetCode Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1原创 2014-08-11 22:02:59 · 669 阅读 · 0 评论 -
算法乐趣--三只水桶等分水问题
有一个容积为8升的水桶里装满了水,另外还有一个容积为3升的空桶和一个容积为5升的空桶,如何利用这两个空桶等分8升水?附加条件是三个水桶都没有体积刻度,也不能使用其它辅助容器。 这是一道经典题目,一般人都可以在一分钟内给出答案,不过,很多人可能没有注意到这道题的答案不是唯一的。先来看看最常见的一个答案,也是目前已知最快的操作步骤,共需要7次倒水动作:bucket_sta原创 2016-01-22 17:19:01 · 9883 阅读 · 0 评论 -
二叉树的最小深度
1,题目要求,求一个二叉树的最小深度?int minHeight(TreeNode* root) { if(NULL == root) return 0; int left = minHeight(root->left); int right minHeight(root->right); if(left == 0 && right == 0)原创 2016-01-11 23:19:55 · 347 阅读 · 0 评论 -
133. Clone Graph
# @(leetcode)[BFS, 图论]Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ’s undirected graph serialization: Nodes are labeled uniquely.We use # as a sepa原创 2016-08-21 15:55:35 · 316 阅读 · 0 评论 -
Unique Binary Search Trees II
Unique Binary Search Trees II@(leetcode)[枚举, DFS]Given an integer n, generate all structurally unique BST’s (binary search trees) that store values 1…n.For example, Given n = 3, your program should re原创 2016-08-21 15:54:36 · 941 阅读 · 0 评论 -
65. Valid Number
65. Valid NumberProblemValidate if a given string is numeric.Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => trueNote: It is intended for the problem statement t原创 2016-08-21 15:52:49 · 376 阅读 · 0 评论 -
LeetCode(Sum Root to Leaf Numbers)
题目要求:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.原创 2014-04-23 10:40:06 · 572 阅读 · 0 评论