码迷,mamicode.com
首页 >  
搜索关键字:longest consecutive    ( 3017个结果
LIS问题:二分+DP
实现代码: int Longest_increasing_subseq(vector<int> &array){ vector<int> dp(array.size()); dp[0]=-1; int left,right,mid; int count=0; for(int i=0;i<array. ...
分类:其他好文   时间:2020-02-09 16:27:01    阅读次数:89
[哈希] leetcode 1124 Longest Well-Performing Interval
https://leetcode.com/problems/longest-well-performing-interval/ 将满足条件的视为+1,不满足的视为-1,计算前缀和。该题可以转换为计算和大于0的最小区间。 class Solution { public: int longestWPI( ...
分类:其他好文   时间:2020-02-08 09:49:21    阅读次数:86
Leetcode 3 Longest Substring Without Repeating Characters. (最长无重复字符子串) (滑动窗口, 双指针)
[TOC] "Leetcode 3" 问题描述 例子 方法 保留一个将字符串中的字符存储为键并将其位置存储为值的hashmap,并保留两个定义最大子字符串的指针。移动右指针以浏览字符串,同时更新hashmap。如果字符已经在hashmap中,则将左指针移到最后找到的相同字符的右边。请注意,两个指针只 ...
分类:其他好文   时间:2020-02-08 09:44:27    阅读次数:54
[leetcode]Longest Absolute File Path
使用栈 class Solution: def lengthLongestPath(self, input: str) -> int: input = input + '\n' # add trailing dummy \n stack = [] level = 1 current = '' res ...
分类:其他好文   时间:2020-02-07 01:38:00    阅读次数:85
leetcode5 Longest Palindromic Substring
1 """ 2 Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. 3 Example 1: 4 Input: "bab ...
分类:其他好文   时间:2020-02-06 16:22:50    阅读次数:60
刷题32. Longest Valid Parentheses
一、题目说明 题目是32. Longest Valid Parentheses,求最大匹配的括号长度。题目的难度是Hard 二、我的做题方法 简单理解了一下,用栈就可以实现。实际上是我考虑简单了,经过5次提交终于正确了。 性能如下: 代码如下: 三、优化措施 题解给了4种方法,这4种方法都比较好理解 ...
分类:其他好文   时间:2020-02-06 10:20:13    阅读次数:50
LeetCode-3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer ...
分类:其他好文   时间:2020-02-05 13:42:39    阅读次数:59
「POJ 3764」The xor-longest Path
给定一棵 N 个节点的树,树上的每条边都有一个权值。从数中选择两个点 x 和 y ,把从 x 到 y 路径上的所有边权 xor 起来,得到的结果最大是多少? "POJ3764" 分析 显然, $d[u]=d[fa_u] \ xor \ w_{u,fa_u}$ ,于是我们可以通过一遍 bfs 来求出每 ...
分类:其他好文   时间:2020-02-04 20:45:33    阅读次数:78
Leetcode 5 Longest Palindromic Substring (最长回文子字符串)(动态规划)
Leetcode 5 题目描述 例子 方法一 方法一关键思想,每当我们向右移动时,我们只需要考虑使用这个新字符作为尾巴是否可以产生新的回文字符串,其长度为(当前长度+1)或(当前长度+2)。 方法一优于方法二采用的动态规划。 Java我们提供两种方法,由运行时间,我们可以看出使用char[]性能比s ...
分类:其他好文   时间:2020-02-04 00:15:06    阅读次数:74
leetcode104 Maximum Depth of Binary Tree
1 """ 2 Given a binary tree, find its maximum depth. 3 The maximum depth is the number of nodes along the longest path from the root node down to the ...
分类:其他好文   时间:2020-02-02 23:16:12    阅读次数:93
3017条   上一页 1 ... 15 16 17 18 19 ... 302 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!