leetcode: Longest Substring Without Repeating Characters
来源:互联网 发布:淘宝母婴包括哪些类目 编辑:程序博客网 时间:2024/05/21 09:24
动规:f[i]表示以第i个字符结尾的最长无重复子串长度。
f[i]=min(len,f[i-1]+1)
其中len是上一个与s[i]相同的字符到i的距离,例如abca,i=3,s[i]='a',那么len=3-0=3,。
边界条件是n=0的情况。
public class Solution {
public int lengthOfLongestSubstring(String s) {int n=s.length();
if(n==0)
return 0;
int[] f=new int[n];
char[] ca=s.toCharArray();
f[0]=1;
int i,j,len,max=1;
for(i=1;i<n;i++)
{
for(j=i-1;j>=0;j--)
{
if(ca[j]==ca[i])
break;
}
len=i-j;
if(len>f[i-1]+1)
f[i]=f[i-1]+1;
else
f[i]=len;
if(f[i]>max)
max=f[i];
}
return max;
}
}
0 0
- LeetCode: Longest Substring Without Repeating Characters
- LeetCode Longest Substring Without Repeating Characters
- LeetCode: Longest Substring Without Repeating Characters
- [Leetcode] Longest Substring Without Repeating Characters
- leetcode 23: Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- LeetCode 3 - Longest Substring Without Repeating Characters
- [LeetCode]Longest Substring Without Repeating Characters
- leetcode Longest Substring Without Repeating Characters
- 【leetcode】 Longest Substring Without Repeating Characters
- LeetCode-Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [leetcode] Longest Substring Without Repeating Characters
- LeetCode - Longest Substring Without Repeating Characters
- LeetCode 3: Longest Substring Without Repeating Characters
- leetcode-3:Longest Substring Without Repeating Characters
- leetcode之Longest Substring Without Repeating Characters
- traceroute
- Unity3d C#脚本学习小结(九) [创建AssetBattle]
- GDB中应该知道的几个调试方法
- 【HEVC学习与研究】26、HEVC的算数编码实现
- SQL操作常规语法【以后遇到更加好的,我会继续整理】
- leetcode: Longest Substring Without Repeating Characters
- 多线程与锁的知识小结
- ZOJ 1240 IBM Minus One
- poj 2892 Tunnel Warfare
- oracle 10g recyclebin引起的dba_free_space性能问题
- 【android官方文档】android 多国语言支持 国际化
- html 文本输入框效果
- libsvm代码阅读:svm.cpp浅谈和函数指针
- 串口异步读写