LeetCode第三题—— Longest Substring Without Repeating Characters(最长无重复子字符串)
题目描述
Given a string, find the length of the longest substring without repeating characters.
Example 1
Input: "abcabcbb"
Output: 3
Explanation: The answer is"abc", with the length of 3.
Example 2
Input: "bbbbb"
Output: 1
Explanation: The answer is"b", with the length of 1.
Example 3
Input: "pwwkew"
Output: 3
Explanation: 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.
My solution(94ms,39.2MB)
class Solution {
public int lengthOfLongestSubstring(String s) {
HashMap<String,Integer> map = new HashMap<String,Integer>();
int result=0,current=1;
for(int i=0;i<s.length();){
String temp = s.substring(i,i+1);
if (!map.containsKey(temp)) {
map.put(temp,1);
i++;
}else{
i = current;
current++;
int len = map.size();
if(len > result){ result = len;}
map.clear();
}
if(map.size()>result){
result = map.size();
}
}
return result;
}
}
LeetCode第三题—— Longest Substring Without Repeating Characters(最长无重复子字符串)的更多相关文章
- leetcode第三题--Longest Substring Without Repeating Characters
Problem:Given a string, find the length of the longest substring without repeating characters. For e ...
- leetcode第三题Longest Substring Without Repeating Characters java
Longest Substring Without Repeating Characters Given a string, find the length of the longest substr ...
- LeetCode 第 3 题(Longest Substring Without Repeating Characters)
LeetCode 第 3 题(Longest Substring Without Repeating Characters) Given a string, find the length of th ...
- 【LeetCode每天一题】Longest Substring Without Repeating Characters(最长无重复的字串)
Given a string, find the length of the longest substring without repeating characters. Example 1: ...
- [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 最长无重复字符的子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- [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 example, ...
- [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
随机推荐
- python获取全部股票每日基本面指标,用于选股分析、报表展示等
接口:daily_basic 更新时间:交易日每日15点-17点之间 描述:获取全部股票每日重要的基本面指标,可用于选股分析.报表展示等. 积分:用户需要至少300积分才可以调取,具体请参阅本文最下方 ...
- Mybatis Generator 安装(idea+maven)
1.在Intellij IDEA创建maven项目(本过程比较简单,略) 2. 在maven项目的pom.xml 添加mybatis-generator-maven-plugin 插件 <bui ...
- undefined reference to `TTF_Init'
如果编译时遇上 undefined reference to `FunctionName' 或是这种类似错误,首先就得检查是不是函数名拼写错误,如果不是,那估计是编译时候有些链接库没加进去 比如这篇上 ...
- .net core 下的跨域设置
1.CORS中间件处理跨源请求.以下代码为具有指定源的整个应用程序启用CORS: public void Configure(IApplicationBuilder app, IHostingEnvi ...
- 如何让contenteditable元素只能输入纯文本
本文出自张旭鑫博客,要知详情,请戳右侧地址:http://www.zhangxinxu.com/wordpress/?p=5120 一.温故而知新 很多年以前,稍等,让我搜一下contentedita ...
- Linux初学习之 rm 命令
现在我们来仔细的学习一下linux的rm命令,这个命令顾名思义(我猜的,嘻嘻,是remove) 命令格式: rm [OPTION]... FILE... Remove (unlink) the FIL ...
- 74HC595点亮8个LED灯
一.原理介绍 595有两个寄存器,都是8位的,如下所示: 595是串入并出带有锁存功能移位寄存器,它的使用方法简单: - - 在正常使用时 /SCLR接高电平,/G接低电平. - - 从SER每输 ...
- python 2 学习历程(一)
在用户输入字符串的时候,有时会带有一些其他的字符,例如常见的空格 除非在网页或者某个位置声明了空格也算字符,或者一些账号等安全程度较高的环节,多了一个空格很少有人会注意到,并且愿意即时改正它们,那么这 ...
- top.location.href
window.location.href.location.href是本页面跳转 parent.location.href是上一层页面跳转 top.location.href是最外层的页面跳转 ...
- chkconfig 与 systemctl
chkconfig命令 主要用来更新(启动或停止)和查询系统服务(service)的运行级信息,用于维护/etc/rc[0-6].d目录的命令行工具. chkconfig -–add httpd 增加 ...