问题描述:

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.

解决:
class Solution {
public int lengthOfLongestSubstring(String s) {
int left = 0,right = 0,res = 0;
HashSet<Character> m = new HashSet<>();
while (right<s.length()){
if (!m.contains(s.charAt(right))){
m.add(s.charAt(right++));
res = Math.max(res,m.size());
}else {
m.remove(s.charAt(left));
left++;
}
}
return res;
}

滑动窗口解决最小子串问题 leetcode3. Longest Substring Without Repeating Characters的更多相关文章

  1. 最长子串(Leetcode-3 Longest Substring Without Repeating Characters)

    Question: Given a string, find the length of the longest substring without repeating characters. Exa ...

  2. LeetCode3 Longest Substring Without Repeating Characters

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

  3. Leetcode3:Longest Substring Without Repeating Characters@Python

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

  4. Leetcode3.Longest Substring Without Repeating Characters无重复字符的最长字串

    给定一个字符串,找出不含有重复字符的最长子串的长度. 示例 1: 输入: "abcabcbb" 输出: 3 解释: 无重复字符的最长子串是 "abc",其长度为 ...

  5. [Swift]LeetCode3. 无重复字符的最长子串 | Longest Substring Without Repeating Characters

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

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

    Given a string, find the length of the longest substring without repeating characters. Example 1: In ...

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

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

  8. [LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串

    Given a string, find the length of the longest substring without repeating characters. Example 1: In ...

  9. 19.Longest Substring Without Repeating Characters(长度最长的不重复子串)

    Level:   Medium 题目描述: Given a string, find the length of the longest substring without repeating cha ...

随机推荐

  1. 桶排序 && leetcode 41

    桶排序 对于0-1000 ,用1001个桶  简单版 或者用10个桶0-9,先按各位装桶,然后依(桶)次放回,然后再按十位放桶,放回,然后百位. 也就是基数排序 https://www.cnblogs ...

  2. Os-hackNos-1(drupal7+suid提权)

    一.信息收集 得到 ip是 192.168.56.101 , 端口开启了22和80,扫目录发现drupal 7 访问一下呢 在exploit-db上面搜索到存在相关的漏洞,而且是用直接上msf 使用第 ...

  3. github gist 无法访问

    转自这里 以管理员身份在hosts文件: Windows: C:\Windows\System32\drivers\etc Ubuntu: /etc/hosts 添加: 192.30.253.118 ...

  4. Android四大组件简介:Android 基础知识,开发教程

    Android 四大组件: Activity.Service.Broadcast Receiver.Content Provider. http://developer.android.com/int ...

  5. jQuery 使用注意事项 与 小技巧(tips)

    jQuery 使用注意事项 与 小技巧(tips) 1 $( document ).ready() https://learn.jquery.com/using-jquery-core/documen ...

  6. Contributor License Agreement

    Contributor License Agreement CLA https://cla.js.foundation/lodash/lodash?pullRequest=4756 https://g ...

  7. SVG & convert polygon/polyline to path

    SVG & convert polygon/polyline to path SVG Polygon/Polyline to Path Converter https://codepen.io ...

  8. 比特币跌破3.5万美元,巨鲸们将目光瞄向SPC算力币

    比特币最近又迎来了大幅下跌,截至周三(1月20日),比特币跌幅超过5%,跌破3.5万美元.很显然,比特币没有预期那样顺顺利利地登顶4万美元,反而又出现了回调迹象.有些巨鲸们在大肆囤币,然而也有些巨鲸们 ...

  9. vue最好的ssr服务器渲染框架

    vue和angular js.react三大框架非常好用,现在大部分人都使用了这三大框架进行开发. 但是vue这些框架到目前位置,大部分还是用来做管理后台,用来做移动端.而官网网站却很少用他们来开发. ...

  10. Codeforces Round #703 (Div. 2) (A~E)

    A. Shifting Stacks 题目链接 点我跳转 题目大意 给定 \(N\) 个土堆,第 \(i\) 个土堆有 \(Ai\) 个木块 你可以将第 \(i\) 个土堆的木块转移至第 \(i + ...