问题描述:

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. 4.Direct交换机之使用指定routingkey完成日志记录场景

    标题 : 4.Direct交换机之使用指定routingkey完成日志记录场景 目录 : RabbitMQ 序号 : 4 const string logOthersQueueName = " ...

  2. Linux系统CentOS进入单用户模式和救援模式详解

    一.概述 目前在运维日常工作中,经常会遇到服务器异常断电.忘记root密码.系统引导文件损坏无法进入系统等等操作系统层面的问题,给运维带来诸多不便,现将上述现象的解决方法和大家分享一下,本次主要以Ce ...

  3. 全方位构造免杀 webshell 小结[一]

    转载自https://klionsec.github.io/2017/10/11/bypasswaf-for-webshell/   全方位构造免杀 webshell 小结[一]   前言:    本 ...

  4. 解决springmvc使用@ResponseBody返回String类型字符串中文乱码问题

    问题分析: 首先: 确定的是只有当返回值是 String时才会出现中文乱码,而当返回值是Map<String, Object>或者是其它类型时,并没有中文乱码的出现. 然后找原因: 原因是 ...

  5. SwiftUI render WKWebView

    SwiftUI render WKWebView // // ContentView.swift // webview-app // // Created by 夏凌晨 on 2020/10/27. ...

  6. css animation & animation-fill-mode

    css animation & animation-fill-mode css animation effect https://developer.mozilla.org/en-US/doc ...

  7. jquery.query.js

    帮助文档 var url = location.search; > "?action=view&section=info&id=123&debug&te ...

  8. 以NGK 呼叫河马为例分析智能合约漏洞在哪?

    合约交易是指买方和卖方根据约定,在未来某一时刻,以指定价格接受某一资产的协议. 合约是买卖双方之间权利义务的表现形式.合约交易是一种金融衍生工具,与现货市场相比,用户通过判断期货合约交易的涨跌,选择买 ...

  9. Go之Casbin简介,安装,模型,存储,函数

    简介 Casbin是一个强大的,高效的开源访问控制框架,其权限管理机制支持多种访问控制模型 支持编程语言 不同语言中支持的特性 我们一直致力于让 Casbin 在不同的编程语言中拥有相同的特性. 但是 ...

  10. django学习-19.admin管理后台的配置和登录

    目录结构 1.前言 2.admin管理后台的配置和登录的完整操作流程 2.1.第一步: 在[settings.py]里对常量[INSTALLED_APPS]的值进行相关配置 2.2.第二步: 在[ur ...