LintCode:M-最长无重复字符的子串
来源:互联网 发布:有意识的人工智能 编辑:程序博客网 时间:2024/05/17 11:59
LintCode链接
给定一个字符串,请找出其中无重复字符的最长子字符串。
样例
例如,在"abcabcbb"
中,其无重复字符的最长子字符串是"abc"
,其长度为 3
。
对于,"bbbbb"
,其无重复字符的最长子字符串为"b"
,长度为1
。
public class Solution { /* * @param s: a string * @return: an integer */ public int lengthOfLongestSubstring(String s) { Set<Character> set = new HashSet<Character>(); int n = s.length(); int maxLen=0; int start=0; int i=0; while(i<n){ char c = s.charAt(i); if(!set.contains(c)){ set.add(c); i++; }else{ set.remove(s.charAt(start++)); } maxLen = Math.max(maxLen, set.size()); } return maxLen; }}
阅读全文
0 0
- LintCode:M-最长无重复字符的子串
- LintCode-最长无重复字符的子串
- LintCode-最长无重复字符的子串
- LintCode:最长无重复字符的子串
- 最长无重复字符的子串 lintcode
- lintcode,最长无重复字符的子串
- lintcode(384)最长无重复字符的子串
- lintcode--最长无重复字符的子串
- [LintCode]384.最长无重复字符的子串
- [LintCode 384] 最长无重复字符的子串(Python)
- lintcode最长无重复字符的子串
- LintCode 最长无重复字符的子串
- 最长无重复字符的子串-LintCode
- LintCode(M)最长无重复子串
- 最长无重复字符的子串
- 最长无重复字符的子串
- 最长无重复字符的子串
- 最长无重复字符的子串
- hdu 3038
- 一、log4j环境搭建
- 软件安全测试·DoS·HTTP慢速攻击
- 开源 App
- Solr6.6一天总结(一)环境搭建
- LintCode:M-最长无重复字符的子串
- Android基础-初识SQLite 1-1 sqlite数据库 以及 SQL语法 介绍
- Python-读取目录所有文件的文件名并保存到txt文件
- OWASP Top 10 2017-RC1-4e2d65877248-V1.0.pdf
- 洛谷P3368 树状数组
- 2017.8.29
- JVM内存区域划分Eden Space、Survivor Space、Tenured Gen,Perm Gen解释
- 【机器学习系列1】Xgboost算法
- C3P0配置信息详解