[Algo] 253. Longest Substring Without Repeating Characters
Given a string, find the longest substring without any repeating characters and return the length of it. The input string is guaranteed to be not null.
For example, the longest substring without repeating letters for "bcdfbd" is "bcdf", we should return 4 in this case.
public class Solution {
public int longest(String input) {
// Write your solution here
if (input.length() == 0) {
return 0;
}
char[] charArr = input.toCharArray();
Set<Character> set = new HashSet<>();
int res = 0;
int start = 0, i = 0;
while (i < charArr.length) {
char cur = charArr[i];
if (!set.contains(cur)) {
set.add(cur);
res = Math.max(res, i - start + 1);
i += 1;
} else {
set.remove(charArr[start]);
start += 1;
}
}
return res;
}
}
[Algo] 253. Longest Substring Without Repeating Characters的更多相关文章
- LeetCode[3] 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, ...
- Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- 3. Longest Substring Without Repeating Characters(c++) 15ms
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- 【leetcode】Longest Substring Without Repeating Characters
题目描述: Given a string, find the length of the longest substring without repeating characters. For exa ...
- Longest Substring Without Repeating Characters(C语言实现)
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- leetcode: longest substring without repeating characters
July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http: ...
- [LeetCode_3] Longest Substring Without Repeating Characters
LeetCode: 3. Longest Substring Without Repeating Characters class Solution { public: int lengthOfLon ...
- Longest Substring Without Repeating Characters (c#)
Given a string, find the length of the longest substring without repeating characters. For example, ...
随机推荐
- java多线程并发(二)--线程的生命周期及方法详解
上篇随笔介绍了线程的相关基础知识以及新启线程的几种方法,本片将继续介绍线程的生命周期及方法详解. 一.线程的生命周期 在Thread代码中,线程的状态被分为6种 public enum State { ...
- Jenkins-在windows上配置自动化部署(Jenkins+Gitlab+IIS)
Jenkins-在windows上配置自动化部署(Jenkins+Gitlab+IIS) web部署样例 windows服务部署样例 系统备份 在服务器上创建后缀名为.ps1的文件,例:BackUpD ...
- uboot 学习笔记
ram 初始化: 在 start.S 中, bl cpu_init_crit 这句,在 tq2440 中是直接调用,在韦东山里面是通过和 TEXT_BASE 进行比较,如果从 RAM 中运行就不进行 ...
- VSFTP 连接时425 Security: Bad IP connecting.报错-----解决方法
当登录FTP时候出现这个报错时.是因为PASV模式的安全检查是开启的(默认是开启的) ftp> ls227 Entering Passive Mode (172,16,101,33,35,58 ...
- selumium 中 xpath获取文本、属性正确写法
报错“The result of the xpath expression is: [object Attr]. It should be an element” yutube爬虫动态加载,需要用到s ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习:语句
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 开始linux课程预习工作
预习的过程,就是在老师讲课之前,自己学习的过程.重点,难点,疑点,不等老师先讲,自己先趟一遍,老师在讲的时候,相信会吸收的更好一些.
- Sequence Models Week 1 Building a recurrent neural network - step by step
Building your Recurrent Neural Network - Step by Step Welcome to Course 5's first assignment! In thi ...
- 18 12 24 html 表单学习
html表单 表单用于搜集不同类型的用户输入,表单由不同类型的标签组成,相关标签及属性用法如下: 1.<form>标签 定义整体的表单区域 action属性 定义表单数据提交地址 meth ...
- OC中浮点数转整数的进一法和去尾法
//去尾法,最小去尾单位为0.000001 floorf(4.1)4 floorf(4.9)4 floorf(4.999999)4 floorf(4.9999999)5 //进一法,最小进位单位为0. ...