![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 76
le119126
这个作者很懒,什么都没留下…
展开
-
leetcode 91: 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 numb原创 2015-08-02 16:59:00 · 410 阅读 · 0 评论 -
leetcode:Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The原创 2015-11-11 22:26:35 · 461 阅读 · 0 评论 -
leetcode 95-96:Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \转载 2015-09-24 12:17:14 · 388 阅读 · 0 评论 -
leetcode 129: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.Find the tota原创 2015-11-23 22:20:11 · 353 阅读 · 0 评论 -
leetcode 128: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 is [1, 2, 3原创 2015-11-23 21:29:45 · 404 阅读 · 0 评论 -
leetcode 解题报告 Word Ladder II
别人讲得很详细,题目有点难,就转 了:http://www.cnblogs.com/ShaneZhang/p/3748494.htmlGiven two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginW转载 2015-11-19 20:22:15 · 607 阅读 · 0 评论 -
leetcode 130: Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O X原创 2015-11-24 22:43:46 · 410 阅读 · 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 = ["leet"原创 2015-12-13 21:47:38 · 438 阅读 · 0 评论 -
leetcode 143. Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it t原创 2016-01-15 20:18:42 · 393 阅读 · 0 评论 -
leetcode:word break II
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For example, givens = "原创 2015-12-15 21:22:27 · 555 阅读 · 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","原创 2015-11-30 21:39:15 · 323 阅读 · 0 评论 -
约瑟夫问题
http://zh-cn.enc.tfode.com/%E7%BA%A6%E7%91%9F%E5%A4%AB%E6%96%AF%E9%97%AE%E9%A2%98http://blog.csdn.net/niuox/article/details/9269731约瑟夫斯问题(有时也称为约瑟夫斯置换),是一个出现在计算机科学和数学中的问题。在计算机编程的算法中,类似问题又称为转载 2015-10-11 18:52:35 · 529 阅读 · 0 评论 -
leetcode: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],原创 2015-11-10 15:07:27 · 367 阅读 · 0 评论 -
kMP解析
KMP算法是一种改进的字符串匹配算法思路:http://www.cnblogs.com/c-cloud/p/3224788.html对于next的理解:next[i] 表示i点不匹配(不包括i点)时,前面有next[i]个匹配的前缀(0,next[i])下次要跳转到next[i]开始比较,P[K]不等于P[q]时(图中是j),由于已经到了目前的k,q了,那么 p[0]……p[k-1] 与 ...原创 2015-08-03 13:11:03 · 476 阅读 · 0 评论 -
leetCode 99: Recover Binary Search Tree
转自:http://blog.csdn.net/worldwindjp/article/details/21694179Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution us转载 2015-09-27 20:53:07 · 476 阅读 · 0 评论 -
leetCode 98:Validate Binary Search Tree
转自:http://blog.csdn.net/ljiabin/article/details/41699241点击打开链接【题目】Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The le转载 2015-09-27 20:32:01 · 412 阅读 · 0 评论 -
leetCode 97:Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", ret原创 2015-09-26 22:42:57 · 439 阅读 · 0 评论 -
leetcode 105-106: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./** * Definition for a binary tree node. * struct Tre原创 2015-10-17 15:00:29 · 599 阅读 · 0 评论 -
最长公共子序列
参考 http://blog.csdn.net/zhongkeli/article/details/8847694 ---没有加 strA[lenA-1]==strB[lenB-1],有误如最后一个7行6列是 4,6行5列是3 ,但是strA[7]是B ,strB[6]是A 所以不对,要加strA[lenA-1]==strB[lenB-1]原创 2015-08-05 11:51:37 · 459 阅读 · 0 评论 -
LeetCode 115: Distinct Subsequences
Distinct SubsequencesGiven 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转载 2015-11-03 21:06:46 · 496 阅读 · 0 评论 -
leetcode 116:Populating Next Right Pointers in Each Node I And II
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.原创 2015-11-08 22:37:54 · 402 阅读 · 0 评论 -
leetcode:Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3, [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]Return [1,3,3,1].Note:Could you原创 2015-11-09 20:45:44 · 289 阅读 · 0 评论 -
leetcode:Best Time to Buy and Sell Stock I II II
Best Time to Buy and Sell Stock I 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原创 2015-11-10 20:43:00 · 437 阅读 · 0 评论 -
leetcode:Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab",Return原创 2015-12-01 11:18:06 · 337 阅读 · 0 评论 -
leetcode 146. LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if原创 2016-01-02 21:30:09 · 525 阅读 · 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".思路:预处理,删除首尾空格。先翻转每一个单词,再全部翻转。在翻转每一个单词时,删除多余空格注意:1.删除连续空格,判断下个位置时一定原创 2016-07-06 23:22:40 · 652 阅读 · 0 评论 -
leetcode 1. Two Sum
题目Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example:Given原创 2016-08-31 23:20:10 · 288 阅读 · 0 评论 -
leetcode:152. 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 largest原创 2016-08-24 00:33:38 · 353 阅读 · 0 评论 -
leetcode:154. Find Minimum in Rotated Sorted Array II
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot u原创 2016-08-25 00:33:40 · 354 阅读 · 0 评论 -
Leetcode- Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2015-04-30 22:27:07 · 432 阅读 · 0 评论 -
Leetcode-median of two sorted arrays
转自:http://blog.csdn.net/yutianzuijin/article/details/11499917/这是我做的第二个leetcode题目,一开始以为和第一个一样很简单,但是做的过程中才发现这个题目非常难,给人一种“刚上战场就踩上地雷挂掉了”的感觉。后来搜了一下leetcode的难度分布表(leetcode难度及面试频率)才发现,该问题是难度为5的问题,真是小看了转载 2015-05-06 22:44:18 · 551 阅读 · 0 评论 -
leetcode-Longest Palindromic Substring
转自:http://www.cnblogs.com/TenosDoIt/p/3675788.html?utm_source=tuicoolLeetCode:Longest Palindromic Substring 最长回文子串题目链接Given a string S, find the longest palindromic substring in S. You转载 2015-05-12 22:37:06 · 604 阅读 · 0 评论 -
leetcode - ZigZag Conversion
转自:http://www.cnblogs.com/sanghai/p/3632528.html题目: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转载 2015-05-17 23:07:52 · 430 阅读 · 0 评论 -
leetcode 8 String to Integer
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原创 2017-01-24 09:07:49 · 698 阅读 · 0 评论 -
leetcode :二叉树的前中后序遍历非递归实现,以及根据前中后序构造二叉树
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas原创 2015-10-21 21:55:45 · 660 阅读 · 0 评论 -
leetcode 149. Max Points on a Line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.法一:两点确定一条直线(两两组合),然后在判断其他点是否在这条直线上,O(n^3)法二:遍历每一个点i {其他点j与该点i组成直线的斜率xl,斜率相同,统计加1----斜率相同又过同一个点i原创 2016-07-05 22:53:11 · 471 阅读 · 0 评论 -
leetcode 148. Sort List
Sort a linked list in O(n log n) time using constant space complexity./** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int原创 2016-07-03 01:26:18 · 564 阅读 · 0 评论 -
leetcode : Clone Graph
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 separator for each原创 2015-12-02 14:45:34 · 417 阅读 · 0 评论 -
leetcode :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 station i to原创 2015-12-02 23:26:35 · 367 阅读 · 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 least on原创 2015-12-08 16:12:09 · 430 阅读 · 0 评论