![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
cjneo
这个作者很懒,什么都没留下…
展开
-
Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.原创 2014-10-29 20:50:48 · 413 阅读 · 0 评论 -
Longest Palindromic Substring
b a a a将字符串s扩展为: $ # b # a # a # a # ^前后加的特殊字符是为了避免去判断边界的条件,算法维护两个域:id:表示能到达最右边的回文的中心,mx表示能到达最右的边界。 其次还需要一个数组v记录下以i为中心的回文长度(的一半)。 然后我们从左往右遍历新生成字符串,更新mx和id,对于某一位置i,设j=2*id-原创 2015-06-02 21:57:23 · 301 阅读 · 0 评论 -
leetcode Interleaving String
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. Whe原创 2015-05-22 14:47:24 · 307 阅读 · 0 评论 -
leetcode permutation
1 利用回溯法进行数据交换。第一次交换时将第零位分别与 第0,1,..n-1位交换。第二次交换时将第1位与第1,2...n-1位交换。注意由于是递归地进行交换,故实际的交换顺序是按深度优先搜索来的。 class Solution { public: vector > permute(vector &num) { int len =num.size(); v原创 2015-05-18 11:07:24 · 327 阅读 · 0 评论 -
关于longest 的一些题目
Longest Common Subsequence Given two strings, find the longest common subsequence (LCS). Your code should return the length of LCS. Have you met this question in a real interview? Y原创 2015-06-16 23:50:59 · 447 阅读 · 0 评论 -
leetcode Course Schedule II
这道题可以用拓扑排序去做, 对于图的拓扑排序,有邻接表和邻接矩阵的做法,邻接表会快一些。 邻接矩阵的复杂度O(V*V) 邻接表复杂度(V+E) class Solution { public: vector findOrder(int numCourses, vector>& prerequisites) { vector res;原创 2015-06-17 15:16:31 · 427 阅读 · 0 评论 -
leetcode 关于树的一些题目
class Solution { public: int maxPathSum(TreeNode *root) { int chain=0,value=0,maxx=root->val; submax(root,chain,maxx); return maxx; } void submax(TreeNode *nod原创 2015-06-16 21:06:45 · 629 阅读 · 0 评论 -
Maximum Gap
题目大意: 在一个无序的数组中,求这个数组排序完以后,相邻的两个数最大差值,要求保证O(n)的复杂度。 解题思路:桶排序http://bookshadow.com/weblog/2014/12/14/leetcode-maximum-gap/ 假设有N个元素A到B。 那么最大差值不会小于ceiling[(B - A) / (N - 1)], 根据鸽巢原理。转载 2015-06-16 23:53:47 · 345 阅读 · 0 评论 -
leetcode wordbreak
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, given s = "原创 2015-05-19 00:01:58 · 417 阅读 · 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-12-06 22:06:29 · 322 阅读 · 0 评论 -
leetcode 一句话算法
jump game :一个数组里放着可以往前跳的最大步数,问是否有可能从开始走到结束。 思路:目的在于到达终点,我们要记下的就是从本点可达的最长距离,并且需要不断更新,如果这个距离变为零,那么不能达到终点。 jump game2 同上,不过要返回最小的跳数, 思路:当我们不得不跳时,即当前最大可达距离已达i,我们需要将步数加一,然后选取上一次跳转时可达的最大距离作为新的最大可达距离即原创 2014-12-19 11:24:31 · 407 阅读 · 0 评论 -
LeetCode Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2014-12-03 21:09:48 · 431 阅读 · 0 评论 -
Largest Rectangle in Histogram 直方图的最大正方形
这个算法的思想动态规划 直方体数组 height[ ] 维护一个 栈s,栈里的元素是递增排列的,存的是heigth数组的下标。从左到右扫描height[i],如果数值大于栈顶的元素,栈中元素出栈,直到栈中元素小于height[i]为止。每次出栈的元素记为last,计算之前的以此为高height[last]的长方体的体积,与最大值比较选取最大值。 这个体积的计算很有讲究,用的是此时栈顶的元素所原创 2014-12-18 13:05:59 · 856 阅读 · 0 评论 -
[Leetcode] Word Search
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically原创 2014-12-01 23:53:19 · 440 阅读 · 0 评论