leetcode
文章平均质量分 63
shashafbqc
这个作者很懒,什么都没留下…
展开
-
leetcode Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb原创 2014-05-12 20:52:12 · 362 阅读 · 0 评论 -
leetcode N-Queens
标准的回溯法,扩展了所有情况原创 2014-06-09 21:39:43 · 274 阅读 · 0 评论 -
leetcode 回溯法 模板
/*** dfs 模板.* @param[in] input 输入数据指针* @param[out] path 当前路径,也是中间结果* @param[out] result 存放最终结果* @param[inout] cur or gap 标记当前位置或距离目标的距离* @return 路径长度,如果是求路径本身,则不需要返回长度*/void dfs(type &转载 2014-05-09 21:45:45 · 1131 阅读 · 0 评论 -
leetcode Next Permutation
class Solution {public:/*组合数学,下一个全排列的生成。考虑排列P,求满足Pj-1<pj的j的最大值,设为i求满足关系式Pi-1<pk的k 的最大值,设为j。将pi-1与pj交换,并将之后的元素逆序*/ void nextPermutation(vector &num) { int n=num.size(); int i=n-2原创 2014-06-11 09:58:11 · 263 阅读 · 0 评论 -
leetcode Generate Parentheses
关于这道题目,因为和括号有关,开始想用stack原创 2014-06-10 21:55:15 · 303 阅读 · 0 评论 -
leetcode Edit Distance
class Solution {public:/*最优问题,首先选取动态规划和贪心算法。该问题使用动态规划,动态规划列出在做决定的所有选择,找最好的选择*/ int minDistance(string word1, string word2) { int n1=word1.length(),n2=word2.length(); int maxLen=m原创 2014-06-11 22:17:46 · 425 阅读 · 0 评论 -
leetcode Reverse Nodes in k-Group
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: Li原创 2014-06-13 09:48:53 · 277 阅读 · 0 评论 -
leetcode 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"Clarification:What constitutes a word?A sequence of non-space原创 2014-06-13 14:55:44 · 358 阅读 · 0 评论 -
leetcode Insertion Sort List
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *in原创 2014-06-13 21:48:05 · 326 阅读 · 0 评论 -
leetcode Permutations II
class Solution {public: vector > permuteUnique(vector &num) { sort(num.begin(),num.end()); vector> result; vector aresult; sub(result,aresult,num,0); retur原创 2014-06-13 22:26:33 · 310 阅读 · 0 评论 -
leetcode Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non原创 2014-06-16 22:02:50 · 323 阅读 · 0 评论 -
leetcode Jump Game
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.Determine i原创 2014-06-18 22:16:20 · 369 阅读 · 0 评论 -
leetcode Jump Game II
class Solution {public:/*贪心算法即可解决这个问题*/ int jump(int A[], int n) { if(n<=0) return 0; vector step(n,0); int maxIndex=0,max=A[0],last=0; for(int i=1;i<n;i++){原创 2014-06-18 22:15:08 · 341 阅读 · 0 评论 -
leetcode ZigZag Conversion
我在考虑这个问题d原创 2014-06-20 21:58:36 · 309 阅读 · 0 评论 -
leetcode Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","原创 2014-06-05 21:35:14 · 273 阅读 · 0 评论 -
leetcode Longest Substring Without Repeating Characters
class Solution {public: int lengthOfLongestSubstring(string s) { int len=s.length(); if(len==0) return 0; vector pos(256,-1); int longest=INT_MIN; int subl原创 2014-06-28 21:55:26 · 322 阅读 · 0 评论 -
leetcode Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2014-05-09 09:32:49 · 325 阅读 · 0 评论 -
leetcode Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.原创 2014-05-12 21:40:15 · 321 阅读 · 0 评论 -
leetcode Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary原创 2014-05-13 21:33:22 · 285 阅读 · 0 评论 -
leetcode Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st原创 2014-05-13 22:15:19 · 333 阅读 · 0 评论 -
leetcode 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.原创 2014-06-04 20:35:14 · 637 阅读 · 0 评论 -
leetcode Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".原创 2014-06-04 21:44:19 · 345 阅读 · 0 评论 -
leetcode 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-08 22:03:32 · 404 阅读 · 1 评论 -
leetcode Pow(x, n)
看到这个题目,一开始以为是大数原创 2014-06-23 21:48:29 · 311 阅读 · 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.这个/** * Definition for binary tree * struct TreeNode { * int val; *转载 2014-06-24 22:02:32 · 411 阅读 · 0 评论 -
leetcode Merge k Sorted Lists
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode *me原创 2014-06-25 22:01:50 · 330 阅读 · 0 评论 -
leetcode Copy List with Random Pointer
/** * Definition for singly-linked list with a random pointer. * struct RandomListNode { * int label; * RandomListNode *next, *random; * RandomListNode(int x) : label(x), next(NULL),原创 2014-06-25 21:31:04 · 347 阅读 · 0 评论 -
leetcode First Missing Positive
class Solution {public: int firstMissingPositive(int A[], int n) { for(int i=0;i<n;){ if(A[i]>0&&A[i]!=(i+1)&&A[i]<n&&A[i]!=A[A[i]-1]){ //首先确保swap的地方没有越界,之后确保swap双方不一样,否则死循环。A原创 2014-06-26 22:11:59 · 308 阅读 · 0 评论 -
leetcode Validate Binary Search Tree
在这道题目中,需要知道zuoyou原创 2014-06-10 09:38:43 · 300 阅读 · 0 评论 -
leetcode Anagrams
class Solution {public:/*思想:将每一个字符串排序,那么anagram在排序后必然相同,所以用map结构*/ vector anagrams(vector &strs) { vector res; vector flag(strs.size(),false); map temp; pair::ite原创 2014-06-20 22:25:25 · 291 阅读 · 0 评论