3. [leetcode] Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.
Examples
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
Solutions
HashMap + two pointers
public int lengthOfLongestSubstring(String s) {
if(s == null || s.length() == 0){
return 0;
}
Map<Character, Character> map = new HashMap();
int j = 0;
int max = 0;
char[] ch = s.toCharArray();
for(int i = 0; i <ch.length; i++){
while(j < ch.length && !map.containsKey(ch[j])){
map.put(ch[j], ch[j]);
j++;
if(j - i > max){
max = j - i;
}
}
map.remove(ch[i]);
}
return max;
}
3. [leetcode] Longest Substring Without Repeating Characters的更多相关文章
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- leetcode: longest substring without repeating characters
July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http: ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- C++ leetcode Longest Substring Without Repeating Characters
要开学了,不开森.键盘声音有点大,担心会吵到舍友.今年要当个可爱的技术宅呀~ 题目:Given a string, find the length of the longest substring w ...
- [LeetCode]Longest Substring Without Repeating Characters题解
Longest Substring Without Repeating Characters: Given a string, find the length of the longest subst ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串 C++实现java实现
最长无重复字符的子串 Given a string, find the length of the longest substring without repeating characters. Ex ...
- LeetCode: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, ...
- [Leetcode] Longest Substring Without Repeating Characters (C++)
题目: Given a string, find the length of the longest substring without repeating characters. For examp ...
- [LeetCode] Longest Substring Without Repeating Characters (LinkedHashSet的妙用)
Given a string, find the length of the longest substring without repeating characters. For example, ...
随机推荐
- org.springframework.web.servlet.PageNotFound
2017-07-11 16:36:13.489 WARN [http-nio-8032-exec-16]org.springframework.web.servlet.PageNotFound -Re ...
- Spring Batch 专题
如今微服务架构讨论的如火如荼.但在企业架构里除了大量的OLTP交易外,还存在海量的批处理交易.在诸如银行的金融机构中,每天有3-4万笔的批处理作业需要处理.针对OLTP,业界有大量的开源框架.优秀的架 ...
- LoadRunner 11 中Analysis分析
原文:http://www.cnblogs.com/Chilam007/p/6445165.html analysis简介 分析器就是对测试结果数据进行分析的组件,它是LR三大组件之一,保存着大量用来 ...
- 阿里云部署java项目参考如下链接
http://www.cnblogs.com/softidea/p/5271746.html https://oneinstack.com/question/how-to-deploy-java-ap ...
- jQuery学习之旅 Item2 选择器【二】
这里接着上一个Item1 把jQuery的选择器讲完.主要有:属性过滤器和子元素过滤器 点击"名称"会跳转到此方法的jQuery官方说明文档. 5. 属性过滤器 Attribute ...
- 巩固java(三)---java修饰符
正文: 下面的表格列出了java中修饰符的一些信息: 修饰符名称 类型 类 变量 方法 abstract 非访问控制符 抽象类 -- 抽象方法 final ...
- Python+Selenium+PIL+Tesseract真正自动识别验证码进行一键登录
Python 2.7 IDE Pycharm 5.0.3 Selenium:Selenium的介绍及使用,强烈推荐@ Eastmount的博客 PIL : Pillow-3.3.0-cp27-cp27 ...
- Pandas的函数应用、层级索引、统计计算
1.Pandas的函数应用 1.apply 和 applymap 1. 可直接使用NumPy的函数 示例代码: # Numpy ufunc 函数 df = pd.DataFrame(np.random ...
- Python3 模拟登录知乎(requests)
# -*- coding: utf-8 -*- """ 知乎登录分为两种登录 一是手机登录 API : https://www.zhihu.com/login/phone ...
- User Profile Service服务未能登录,无法登录
不知你是否遇到这样的问题,某一天你打开PC,开机正常,可当你输入正确的密码回车,却发现Vista或Win7拒绝让你登录,提示"User Profile Service 服务未能登录.无法加载 ...