问题描述:

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;}

转载于:https://www.cnblogs.com/zheng123/p/9713411.html

滑动窗口解决最小子串问题 leetcode3. Longest Substring Without Repeating Characters相关推荐

  1. LeetCode3:Longest Substring Without Repeating Characters

    原题链接:传送门 Given a string, find the length of the longest substring without repeating characters. For ...

  2. leetcode3. Longest Substring Without Repeating Characters

    解法一: 1.维护三个变量: max用于记录当前最大值, next表示当前维护的正确子串, pre表示之前出现的重复字符再上一次出现的最靠前位置 A1:当前重复字符当前位置 A2:当前重复字符上一次位 ...

  3. leetcode算法—无重复字符的最长子串 Longest Substring Without Repeating Characters

    关注微信公众号:CodingTechWork,一起学习进步. 题目 Longest Substring Without Repeating Characters: Given a string, fi ...

  4. LeetCode.3-最长无重复字符子串(Longest Substring Without Repeating Characters)

    这是悦乐书的第341次更新,第365篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Medium级别的第2题Longest Substring Without Repeating Cha ...

  5. LeetCode:Longest Substring Without Repeating Characters(最长不重复子串)

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

  6. leetcode(三)—— Longest Substring Without Repeating Characters(最长不重复子串 Python/C++)

    Longest Substring Without Repeating Characters | LeetCode OJ 使用 hash 判重问题首先想到的就是 hash(或者使用 map): 思路: ...

  7. Leetcode 3:Longest Substring Without Repeating Characters(最长不重复子串)

    Description Given a string, find the length of the longest substring without repeating characters. 给 ...

  8. 3.longest substring without repeating characters

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

  9. LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之一:解题思路

    笔者在完成LeetCode第三题(Longest Substring Without Repeating Characters)时,经历了设计.实现.优化三个阶段,于是通过这个三部曲系列,将当初的整个 ...

最新文章

  1. nagios 使用MSN 发报警消息
  2. php mysql 读取中文数据的函数_php读取mysql中文数据出现乱码的解决方法
  3. 脑细胞膜等效神经网路12分类实例
  4. 我的世界拿java开服务器_我的世界如何开服务器
  5. vba 跳到下一个循环_VBA野知识分享:从一个数组中取部分值生成新数组,不使用循环的思路...
  6. 51单片机雾化片自动扫频程序_单片机简介
  7. linux awk 日志分析,Linux Awk使用案例总结 nginx日志统计
  8. 混口饭吃,谈不上喜欢
  9. 技术谈 | SDN 和 NFV 之间的爱与恨
  10. centos7 常用命令参考
  11. bzoj 4522: [Cqoi2016]密钥破解
  12. 不是区块链的特征_《区块链的特征》阅读练习及答案
  13. 寿光农商行计算机机房,寿光农村商业银行:新系统上线前奏——培训
  14. Typora简易教程
  15. 如何在Mac上打开和使用AirPlay,以便在更大的显示器上进行屏幕镜像?
  16. 树莓派系列二:openCV之头像添加国旗
  17. 推荐一些网络安全的网站和论坛
  18. 微信动态表情保存到手机相册
  19. myeclipse浅灰色主题/配色
  20. 使用HTML创建表单

热门文章

  1. 投票列表排序 - 默认,投票数
  2. ios6.0,程序为横屏,出现闪退
  3. c# 事件和委托的区别,使用事件的好处
  4. html控件的id和name属性有什么不同
  5. ZOJ 2540 Form a Square
  6. 迭代开发需要一种不同的观点[4]
  7. 收藏 | 小目标检测的一些问题,思路和方案
  8. 《Python编程从入门到实践》记录之字典遍历
  9. 指针数组、数组指针、指针函数、函数指针
  10. 深度学习时代的计算机视觉