使用栈 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
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,求最大匹配的括号长度。题目的难度是Hard 二、我的做题方法 简单理解了一下,用栈就可以实现。实际上是我考虑简单了,经过5次提交终于正确了。 性能如下: 代码如下: 三、优化措施 题解给了4种方法,这4种方法都比较好理解 ...
分类:
其他好文 时间:
2020-02-06 10:20:13
阅读次数:
50
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
给定一棵 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 题目描述 例子 方法一 方法一关键思想,每当我们向右移动时,我们只需要考虑使用这个新字符作为尾巴是否可以产生新的回文字符串,其长度为(当前长度+1)或(当前长度+2)。 方法一优于方法二采用的动态规划。 Java我们提供两种方法,由运行时间,我们可以看出使用char[]性能比s ...
分类:
其他好文 时间:
2020-02-04 00:15:06
阅读次数:
74
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
分析: 完整代码: // 最长公共子序列 #include <stdio.h> #include <algorithm> using namespace std; const int N = 100; char A[N], B[N]; int dp[N][N]; int main() { freop ...
分类:
其他好文 时间:
2020-02-01 14:15:10
阅读次数:
61
Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longestpath betwee ...
分类:
其他好文 时间:
2020-02-01 11:02:57
阅读次数:
105
Python3,双指针,注意K为0的情况。 class Solution: def lengthOfLongestSubstringKDistinct(self, s: str, k: int) -> int: if k == 0: return 0 charMap = {} result = 0 ...
分类:
其他好文 时间:
2020-01-31 15:49:02
阅读次数:
57