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 ...
随机推荐
- es-字段类型整理(6.x及以上)
以下为主要的数据类型,特殊的或者比较冷门的不予关注: 类型分类 子分类 具体类型 核心类型 字符串 text,keyword 整数 byte,short,integer,long 浮点 double, ...
- Swift与OC混合开发
一.Swift调用OC 1. 创建{targetName}-Bridging-Header.h头文件,在BuildSetting -> bridging 2. Swift文件调用的OC中的类的头 ...
- ubuntu14.04标题栏显示上下网速
首先当然是用 wget 下载 indicator-sysmonitor,终端执行命令: wget -c https://launchpad.net/indicator-sysmonitor/trunk ...
- debian 下设置Ctrl+Alt+T快捷键打开终端
在设置->键盘->快捷键->自定义快捷键->添加 名称:Terminal 命令:gnome-terminal 再右上边点击后 按Ctrl +Alt +T
- Centos7 PXE Server Install Script
#安装前配置好centos和epel yum源 #网卡ip和localip一致 localip="192.168.88.200" eth_name='eth0' dnsmasq_i ...
- 读书笔记---《Docker 技术入门与实践》---其一
一.镜像1.1.搜索 搜索所有nginx镜像 $ docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Officia ...
- linux6查看时间同步服务器的匹配源
当服务器时间与设定好的同步时间源的时间有差异的时候,一般都需要先查看本机的时间同步服务功能是否在正常的运转,以及同步的时间源是哪里,在这里为大家提供一个检查时间用的命令. linux/centos 6 ...
- netstat -pa --unix >>test.txt
netstat -pa --unix >>test.txt 输出套接字 命名socket信息
- 笔记50 Mybatis快速入门(一)
一.Mybatis简介 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis ...
- 1.Struts2快速入门
Struts2是一个基于MVC设计模式的Web层框架 Web层框架的特点:前端控制器模式 快速入门 1.下载Struts2的框架包 https://struts.apache.org/ 2.导入jar ...