Leetcode 14 要求,编写一个函数来查找字符串组中的最长公共前缀 使用了Java语言编写,主要是利用函数indexOf和substring,从而进行比较和剪切。 ...
分类:
其他好文 时间:
2020-02-13 16:59:21
阅读次数:
59
1 """ 2 Given two strings text1 and text2, return the length of their longest common subsequence. 3 A subsequence of a string is a new string generate ...
分类:
其他好文 时间:
2020-02-12 00:23:03
阅读次数:
70
这个嘛,我觉得是m[i]=max(m[0~i-1])+1;完了复杂度是O(n^2/2); 书上开了一个辅助数组d[],就很nice,思想是如果m[i]>d[最后一个],辣么直接添加进来, 如果m[i]<d[最后一个],就让它替换掉d[]中第一个比它大的,毕竟比它大的在前面,发展显然没有它好 当然也可 ...
分类:
其他好文 时间:
2020-02-09 20:17:48
阅读次数:
60
实现代码: 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
https://leetcode.com/problems/longest-well-performing-interval/ 将满足条件的视为+1,不满足的视为-1,计算前缀和。该题可以转换为计算和大于0的最小区间。 class Solution { public: int longestWPI( ...
分类:
其他好文 时间:
2020-02-08 09:49:21
阅读次数:
86
[TOC] "Leetcode 3" 问题描述 例子 方法 保留一个将字符串中的字符存储为键并将其位置存储为值的hashmap,并保留两个定义最大子字符串的指针。移动右指针以浏览字符串,同时更新hashmap。如果字符已经在hashmap中,则将左指针移到最后找到的相同字符的右边。请注意,两个指针只 ...
分类:
其他好文 时间:
2020-02-08 09:44:27
阅读次数:
54
使用栈 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