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的更多相关文章

  1. LeetCode[3] Longest Substring Without Repeating Characters

    题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...

  2. [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  3. Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  4. 3. Longest Substring Without Repeating Characters(c++) 15ms

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  5. 【leetcode】Longest Substring Without Repeating Characters

    题目描述: Given a string, find the length of the longest substring without repeating characters. For exa ...

  6. Longest Substring Without Repeating Characters(C语言实现)

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  7. leetcode: longest substring without repeating characters

    July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http: ...

  8. [LeetCode_3] Longest Substring Without Repeating Characters

    LeetCode: 3. Longest Substring Without Repeating Characters class Solution { public: int lengthOfLon ...

  9. Longest Substring Without Repeating Characters (c#)

    Given a string, find the length of the longest substring without repeating characters. For example, ...

随机推荐

  1. 抗干扰性极强非接触式读卡13.56mhz芯片:SI522

    由于智能门锁产品不断地火爆,市场上的不断出现破解的方法.对此中科微联合深圳市动能世纪科技有限公司不断满足市场需求,推出一款抗干扰性极强的13.56mhz芯片. 该芯片出了抗干扰性强以外还直接PIN2P ...

  2. Ubuntu16.04 在Windows10 系统下的安装(双系统)

    楼主最近升级了一个固态+8G双通道内存条,重装了一下win10和ubuntu系统,过程中遇到一些问题,push上来供自己和大家参考.比较好用的博客教程直接贴链接. 一.win10系统 学校有正版软件许 ...

  3. 手把手教你用Python实现“坦克大战”,附详细代码!

    小时候玩的“坦克大战”,你还记得吗? ​ 满满的回忆 ! 今天,我们使用Python以及强大的第三方库来实现一个简单的坦克大战游戏. ​ 整体效果 环境依赖 python3.7 pygame1.9.6 ...

  4. 九、CI框架之将URI转为数组原型

    一.输入以下代码,uri_to_assoc的参数默认从3开始 二.输出效果如下: 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦, ...

  5. Excel----考勤表制作自动更新日期

    起初效果 1. 我们首先输入年月日,如图 选择日期 按`ctrl+1` 来调出下图: 2. 数据填充 3.设置星期 点击1下面的单元格

  6. ArchLinux安装(BIOS)

    ArchLinux安装(BIOS) 说在前头:在经历过无数次的失败尝试过后总结出的可用的安装过程(比官方的简单一点) 官方安装指导 一.连接网络 1.连接 # wifi-menu 2.检查是否联通 ( ...

  7. POJ 2039:To and Fro

    To and Fro Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 8632   Accepted: 5797 Descri ...

  8. you-get使用

    1.pip install you-get 2.如果出错  查看错误bug    you-get http://www.iqiyi.com/v_19rrnqxz7k.html#vfrm=2-4-0-1 ...

  9. .NET技术-5.0. NETCORE设置返回数据字段的大小写

    .NET技术-5.0. NETCORE设置返回数据字段的大小写 问题来源于我写了一个接口,接口的返回类型是JsonResult,但是对接之后反应返回结果的首字母全小写了, 后来查了写资料返现.net ...

  10. studentmanagement

    package javatestywh; public class ScoreInformation { private String stunumber; private String name; ...