lintcode(384)最长无重复字符的子串
来源:互联网 发布:怎么搜索微博域名 编辑:程序博客网 时间:2024/05/21 19:47
描述:
给定一个字符串,请找出其中无重复字符的最长子字符串。
样例:
例如,在"abcabcbb"
中,其无重复字符的最长子字符串是"abc"
,其长度为 3
。
对于,"bbbbb"
,其无重复字符的最长子字符串为"b"
,长度为1
。
思路:
逐个字符起开始遍历,创建哈希表来存储元素
public class Solution { /** * @param s: a string * @return: an integer */ public int lengthOfLongestSubstring(String s) { // write your code here if(s == null || s.length() == 0){ return 0; } int result = 0; for(int i = 0;i<s.length();i++){ int count = 0; HashSet<Character> temp = new HashSet<Character>(); temp.add(s.charAt(i)); count++; for(int j = i+1;j<s.length();j++){ if(temp.contains(s.charAt(j))){ break; }else{ temp.add(s.charAt(j)); count++; } } result = Math.max(result,count); } return result; }}
0 0
- lintcode(384)最长无重复字符的子串
- [LintCode 384] 最长无重复字符的子串(Python)
- LintCode-最长无重复字符的子串
- LintCode-最长无重复字符的子串
- LintCode:最长无重复字符的子串
- 最长无重复字符的子串 lintcode
- lintcode,最长无重复字符的子串
- lintcode--最长无重复字符的子串
- [LintCode]384.最长无重复字符的子串
- LintCode:M-最长无重复字符的子串
- lintcode最长无重复字符的子串
- LintCode 最长无重复字符的子串
- 最长无重复字符的子串-LintCode
- 最长无重复字符的子串
- 最长无重复字符的子串
- 最长无重复字符的子串
- 最长无重复字符的子串
- 最长无重复字符的子串
- Sqlserver like参数化
- Script component 用法
- Linu编译器vim的基本操作
- .canvas绘制出来的东西有锯齿,怎么解决?
- SpringMVC controller层模板
- lintcode(384)最长无重复字符的子串
- WebRTC常用知识点
- DPDK学习笔记<4>源代码分析(1)
- web网站嵌入QQ临时会话代码
- c++控制台程序实现定时器
- Android事件分发机制详解:史上最全面、最易懂
- 线性代数mooc课(3.2)
- 敏感词的简单实现
- 数据库邮件