Leetcode - Longest Substring Without Repeating Characters
来源:互联网 发布:尼康d610调焦软件 编辑:程序博客网 时间:2024/05/16 01:04
public class Solution {
public int lengthOfLongestSubstring(String s) {
HashMap<Character, Integer> hm = new HashMap<Character, Integer>();
int Len=0, max = 0;
if(s.length()<1)
return max;
hm.put(s.charAt(0),0);
char c = s.charAt(i);
if(!hm.containsKey(c) || i>hm.get(c)+Len){
Len ++;
}
else {
Len = i-hm.get(c);
}
hm.put(c, i);
if(Len > max)
max = Len;
}
return max;
}
}
public int lengthOfLongestSubstring(String s) {
HashMap<Character, Integer> hm = new HashMap<Character, Integer>();
int Len=0, max = 0;
if(s.length()<1)
return max;
hm.put(s.charAt(0),0);
max = Len = 1;
char c = s.charAt(i);
if(!hm.containsKey(c) || i>hm.get(c)+Len){
Len ++;
}
else {
Len = i-hm.get(c);
}
hm.put(c, i);
if(Len > max)
max = Len;
}
return max;
}
}
---------------------
HINT:
1. Hashmap 的灵活运用,然后1.思路清晰2.表达完整
2. 题目要了解,这里string里面都是字母,没有特殊字符。。。。。。。这个留作my question
==============
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.
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
- LeetCode Intersection of Two Linked Lists
- Connection Statement ResultSet
- 网络设备功能
- userfull web
- typedef的用法总结
- Leetcode - Longest Substring Without Repeating Characters
- 小感悟:未来几年的计算机软件和服务行业就业前景
- 经常宕机的RAC系统 -排查案例
- 解决父类加载iframe,src参数过大导致加载失败
- AliasRegistry
- VM Depot 分布式计算框架主题应用精选
- C++ 面向对象程序设计
- Java中getFileds()和getDeclaredFileds()
- Jan. 4 daily status