(DP)3.Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
public class Solution {
public int lengthOfLongestSubstring(String s) {
if (s.length() == 0)
return 0;
String[] dp = new String[s.length()];
dp[0] = s.substring(0, 1);
int index = 0;
for (int i = 1; i < s.length(); i++) {
if (s.charAt(i) == s.charAt(i - 1))
dp[i] = s.substring(i - 1, i);
else {
index = dp[i - 1].indexOf(s.charAt(i));
if (index == -1)
dp[i] = dp[i - 1] + s.charAt(i);
else
dp[i] = dp[i - 1].substring(index+1) +s.charAt(i);
} }
index = 0;
for (int i = 0; i < s.length(); i++) {
if (dp[i].length() > index)
index = dp[i].length();
}
return index;
}
}
(DP)3.Longest Substring Without Repeating Characters的更多相关文章
- [LeetCode] Longest Substring Without Repeating Characters (LinkedHashSet的妙用)
Given a string, find the length of the longest substring without repeating characters. For example, ...
- leetcode 3 Longest Substring Without Repeating Characters最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- 3. Longest Substring Without Repeating Characters(c++) 15ms
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- 【leetcode】Longest Substring Without Repeating Characters
题目描述: Given a string, find the length of the longest substring without repeating characters. For exa ...
- Longest Substring Without Repeating Characters(C语言实现)
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- leetcode: longest substring without repeating characters
July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http: ...
随机推荐
- bzoj 3124: [Sdoi2013]直径
#include<cstdio> #include<iostream> #define M 400009 #define ll long long using namespac ...
- File缓存
/** * 保存对象 * @param ser * @param file * @throws IOException */ public b ...
- 在Eclipse上建立hbase 0.98.3/0.96.2源代码阅读环境
2.1. 切换到源代码目录,执行: mvn 黄色部分作用为设置代理.由于本人的编译环境在公司内网,所以需要设置代理 2.2. 生成eclipse项目环境: mvn eclipse:eclipse -D ...
- 定时调度框架Quartz随笔
最近项目中的定时批处理用到了quartz定时任务,在此记录下quartz的配置吧,一个小demo仅供参考,也方便自己今后复习! 下面直接来步骤吧! 一.首先,要搭起能让quartz正常运行的环境,至少 ...
- LVDS,MIPI,EDP
一.背景介绍: 随着显示分辨率的越来越高,传统的VGA.DVI等接口逐渐不能满足人们的视觉需求.随后就产生了以HDMI.DisplayPort为代表的新型数字接口,外部接口方面HDMI占据了较大市场优 ...
- HTML编码规则、CSS属性声明顺序--简介
From AmazeUI:http://amazeui.org/getting-started/html-css-guide HTML 属性顺序 HTML 属性应当按照以下给出的顺序依次排列,确保代码 ...
- Asp.net useful tools
fuslogvw trace the assembly binding when app start up. ILdasm to inspect the manifest of the assembl ...
- iar 错误解决
使用原来备份的项目可以正确烧写并进入调试状态,但使用新项目则报错,错误提示为Failed to load debugee: E:\工作\项目-农业\KaCES-F\Debug\Exe\kaces.tx ...
- toad 9.6和toad 12.1工具使用比较
toad是我工作中使用最频繁的软件之一,阴错阳差的把2个版本都装到了电脑上,使用过程中逐渐发现2者的差异,特此做下记录,以便提示自己和其他有需要的人们.(随时更新中······)由于能力有限,难免会有 ...
- sql语句与 数据库
create table wyx( xh int primary key, xm varchar(20) not null, nl int, zcrq timestamp default curr ...