参考思路

https://github.com/azl397985856/leetcode/blob/master/problems/3.longestSubstringWithoutRepeatingCharacters.md

public int lengthOfLongestSubstring(String s) {
HashMap<Character, Integer> repeatChar = new HashMap<>();
int left = 0;
char c;
int maxLength = 0;
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
if (!repeatChar.containsKey(c) || (i < left)) {
repeatChar.put(c, i);
continue;
}
maxLength = Math.max(maxLength,i-left);
left = Math.max(left,repeatChar.get(c)+1);//有时候重复的在最
repeatChar.put(c,i);
}
maxLength = Math.max(maxLength,s.length() - left);
return maxLength; }

  

LeetCode3-Longest_Substring_Without_Repeating_Characters的更多相关文章

  1. Leetcode3:Longest Substring Without Repeating Characters@Python

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

  2. LeetCode3:Longest Substring Without Repeating Characters

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

  3. LeetCode----3 Sum

    Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...

  4. leetcode3:不重复的最长子串长度

    package hashmap; import java.util.HashMap; import java.util.Map; public class hashmap { public stati ...

  5. LeetCode3 Longest Substring Without Repeating Characters

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

  6. leetcode3 Two Sum III – Data structure design

    Question: Design and implement a TwoSum class. It should support the following operations: add and f ...

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

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

  8. leetcode3

    public class Solution { public int LengthOfLongestSubstring(string s) { var dic = new Dictionary< ...

  9. leetcode3:无重复字符的最长子串

    给定一个字符串,找出不含有重复字符的最长子串的长度. 示例: 给定 "abcabcbb" ,没有重复字符的最长子串是 "abc" ,那么长度就是3. 给定 &q ...

  10. leetcode-[3]Max Points on a Line

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line 思 ...

随机推荐

  1. LeetCode98. 验证二叉搜索树

     验证二叉搜索树  *  * https://leetcode-cn.com/problems/validate-binary-search-tree/description/  *  * algor ...

  2. 洛谷P3157 [CQOI2011]动态逆序对

    题目大意: 给定\(1\)到\(n\)的一个排列,按照给定顺序依次删除\(m\)个元素,计算每个元素删除之前整个序列的逆序对数量 基本套路:删边变加边 那么我们不就是求满足\(pos_i<pos ...

  3. 10.12 csp-s模拟测试70 木板+打扫卫生+骆驼

    T1 木板 求$[\sqrt{n},n)$间有多少个数的平方是n的倍数 通过打表可以发现(我没带脑子我看不出来),符合条件的数构成一个等差数列,公差为首项 而首项就是将n质因数分解后每个质因数出现次数 ...

  4. 奇安信集团笔试题:二叉树的最近公共祖先(leetcode236),杀死进程(leetcode582)

    1. 二叉树最近公共祖先     奇安信集团 2020校招 服务端开发-应用开发方向在线考试 编程题|20分2/2 寻祖问宗 时间限制:C/C++语言 1000MS:其他语言 3000MS 内存限制: ...

  5. 使用puppeteer爬取网页数据实践小结

    简单介绍Puppeteer Puppeteer是一个Node库,它通过DevTools协议提供高级API来控制Chrome或Chromium.Puppeteer默认以无头方式运行,但可以配置为有头方式 ...

  6. LeetCode 622:设计循环队列 Design Circular Queue

    LeetCode 622:设计循环队列 Design Circular Queue 首先来看看队列这种数据结构: 队列:先入先出的数据结构 在 FIFO 数据结构中,将首先处理添加到队列中的第一个元素 ...

  7. 【mysql】修改mysql数据库密码

    修改mysql数据库密码 操作系统:Linux centos7 数据库:mysql5.7 一.在已知MYSQL数据库的ROOT用户密码的情况下,修改密码 1.在Linux命令行,使用mysqladmi ...

  8. [LeetCode#180]Consecutive Numbers

    Write a SQL query to find all numbers that appear at least three times consecutively. +----+-----+ | ...

  9. python批量裁剪图片

    """用Pythonp批量裁剪图片""" from PIL import Imageimport matplotlib.pyplot as ...

  10. 2019-3-20-UWP-How-to-custom-RichTextBlock-right-click-menu

    原文:2019-3-20-UWP-How-to-custom-RichTextBlock-right-click-menu title author date CreateTime categorie ...