Longest Substring Without Repeating Characters

3 Longest Substring Without Repeating Characters(无重复字符的最长子串)Python实现 Longest Substring Without Repeating Characters(无重复字符的最长子串),其内容如下: 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。 示例 2: 输入: "bbbbb" 输出: 1 解释: 因为无重复字符的最... 阅读详情

题目:

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.

代码:

public class Solution {
    public int lengthOfLongestSubstring(String s) {
        int head = 0, longlenth = 0;
		char[] ch = s.toCharArray();
		for (int i = 0; i < s.length(); i++) {
			int lastIndex = s.indexOf(ch[i], head);
			if (head <= lastIndex && lastIndex <= i) {
				if (lastIndex != i) {
					head = lastIndex + 1;
				}
			}
			longlenth = Math.max(longlenth, i - head + 1);
		}
		return longlenth;
    }
}

PS:由于用的java,时间上有点慢,各种超时,只能慢慢调慢慢优化,最后总算通过了。
Leetcode回文串拼接-leetcode_note:用于记录leetcode题目的解析 Leetcode回文串拼接 leetcode_node 题解 该项目主要用于基于Leetcode的刷题记录,与日常学习,对Leetcode上的题目按照解题方法进行分明别类的整理。 题目列表 1.Two Sum 2.Add Two Numbers 3.Longest Substring Without Repeating Characters 4.Median of Two Sorted Arrays 5.Longest Palindromic Substring 6.ZigZag Conversion 7.Reverse Integer 8.String To Integer 9.Palindrome Number 10.String To Integer 11.Container With Most Water 12.Integer To Roman 13.Roman To Integer 289 347 380 442 457 Circular Array Loop 535 Encode and Decode TinyURL 560 565 566 Maximum Binary T 立即下载

相关推荐

WebRTC Qos优化杂记

本文是笔者对WebRTC Qos性能研究、优化的一些思考,希望对有兴趣的读者有一些启发。

sonysuqin的专栏 6683

LeetCode— Longest Substring Without Repeating Characters(应该全是比较全的,有思路分析)

有思路分析,有图示,相当于带你debug一遍,但是有图更清晰。方法应该也是比较全的

Blackoutdragon的博客 689

004.PADS VX2.4常用快捷键及无模命令

PADS系列文章

qq_36492361的博客 4983

【Leetcode-python】3.Longest Substring Without Repeating Characters(最长不重复连续子字符串)

题目:给定一个字符串,输出没有重复字符的最长子字符串的长度。 例:Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Input: "bbbbb" Output: 1 Explanation: The answer is "b", wi...

vita2dolce的博客 402

Conda环境创建报错?教你快速解决Solving environment: failed和ResolvePackageNotFound问题

本文深入解析Conda环境创建中常见的'Solving environment: failed'和'ResolvePackageNotFound'报错原因,并提供从基础到高级的系统化解决方案。涵盖渠道配置、版本通配、环境文件编辑等实用技巧,帮助开发者快速解决conda环境创建问题,提升工作效率。

weixin_28677451的博客 265

二维otsu算法python_OpenCV-Python系列之OTSU算法

上一个教程中,我们谈到了关于图像二值化的两种方法,一种是固定阈值法,另一种是自适应阈值法,总的来说,自适应阈值法在某些方面要由于固定阈值法,但还没完,这次我们将隆重介绍我们的重量级选手,也就是OTSU算法(又称为大津算法和最大类间方差法)。最大类间方差法是1979年由日本学者大津提出的,是一种自适应阈值确定的方法,又叫大津法,简称OTSU,是一种基于全局的二值化算法,它是根据图像的灰度特性,将图像...

weixin_28834169的博客 1432

LeetCode:3.无重复字符的最长字串(longest-substring-without-repeating-characters)思路与题解

LeetCode:3.无重复字符的最长字串(longest-substring-without-repeating-characters) 题目描述 思路 这是典型的滑动窗口问题,即通过滑动窗口来找到最长的字串,我们来看一下具体过程: 首先字符串abcabcbb如下: 然后在字符串第一个位置展开窗口 此时,窗口的起始位置start=0,终止位置end=0(注意字符串也是从0开始的),窗口的长度为length=end-start+1=1 此时窗口内还没有重复元素,所以end向右移动一位,得到: 此时

野犬17的博客 603

深度学习二分类实战:用Python+Keras搞定基因表达数据预测(附完整代码)

本文详细介绍了如何使用Python和Keras构建深度学习模型进行基因表达数据的二分类预测。通过数据预处理、特征选择、神经网络构建及优化策略,特别针对小样本场景提供了调参技巧和模型解释方法。文章还包含完整的代码示例,帮助读者快速掌握深度学习在生物信息学中的应用。

weixin_30642561的博客 252

【Leetcode】3. Longest Substring Without Repeating Characters

题目地址: https://leetcode.com/problems/longest-substring-without-repeating-characters/ 题目大意是,给定一个字符串,求其中的一个子串不含重复字母,返回其长度。可以用双指针来做,用一个map保存快指针遍历到jjj的时候s[0,...,j]s[0,...,j]s[0,...,j]所有字母最后出现的位置,快指针从000向后遍......

数学、算法爱好者的博客 565

COSMO-RS理论:流体相热力学预测的核心模型与技术突破

摘要:COSMO-RS模型通过量子化学计算分子表面电荷分布,实现了从微观量子尺度到宏观化工过程的热力学预测。该模型基于介电连续介质理论,将分子表面片段化处理,通过σ-剖面描述电荷分布,并计算片段间的静电失配能和氢键能。其核心算法通过自洽化学势方程求解活度系数,克服了传统模型依赖实验参数的局限。随着技术进步,模型引入了高阶描述符和色散力修正,提升了预测精度。在药物研发、化工分离等领域广泛应用,但仍存在对长程有序结构预测不足等局限性。该模型为复杂体系的热力学性质预测提供了重要理论工具。

ASKCOS博客 981

mbedtls | 01 - 移植mbedtls库到STM32的两种方法

一、mbedtls 开源库 1. mbedtls是什么 Mbed TLS是一个开源、可移植、易于使用、代码可读性高的SSL库。可实现加密原语,X.509证书操作以及SSL / TLS和 DTLS 协议,它的代码占用空间小,非常适合用于嵌入式系统。 mbedtls遵循 Apache 2.0 开源许可协议,目前由 TrustedFirmware 维护(Linaro主持的一个治理开放社区项目),在Github上已收获 2.6k star,目前Github上发布的最新版本为 2.24.0 版本,开源仓库地址为:

Mculover666的博客(嵌入式) 1万+

Leetcode 3 Longest Substring Without Repeating Characters

Leetcode 3 Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: Th...

博学 笃志 切问 近思 162

PCL 模型滤波器【2027最新版】

根据给定的模型系数在点云中提取对应于模型的点云数据。博客长期更新,本文最新更新时间为:2026年12月1日。

点云侠的博客 4387

[LeetCode]——Longest Substring Without Repeating Characters

作为模式识别的图像狗,越发觉得毕业找工作还是得coding! 痛定思痛,入了leetcode的深坑! 在提交了无数次以后,Accepted终于向俺招手了~ 虽说复杂度高了点,但是作为一个学渣,能看到Accepted这辈子也值了!class Solution { public: int lengthOfLongestSubstring(string s) { str

vashzx的专栏 458

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

leetcode--3. Longest Substring Without Repeating Characters

尺取法 首先设置头尾两个指针,都指向头,然后尾指针开始遍历,在遍历过程中记录每个字母出现个数,每次遍历若当前字母没有出现过,则更新答案长度。若出现过,则将头指针移到重复字母的后面一位。然后继续重复上述操作。最后返回答案即可。 class Solution { public: int lengthOfLongestSubstring(string s) { if(s.le

林伏案的博客 463

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

LeetCode(003)- Longest Substring Without Repeating Characters

题目: Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters. Example 1: Input: “abcabcbb” Output: 3 Explanation: The answer...

Fly_Fly_Zhang的博客 495

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

[LeetCode] 3. Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb" Output: 3 Expla...

weixin_30795127的博客 111

3. Longest Substring Without Repeating Characters

3. Longest Substring Without Repeating Characters Description: Solution: 题解1:

qq_37053885的博客 155

【CODE】Longest Substring Without Repeating Characters

3.Longest Substring Without Repeating Characters (最长不重复子串) Medium 6874410FavoriteShare Given a string, find the length of thelongest substringwithout repeating characters. Example 1: Input: ...

Li_Jiaqian的博客 368
上一篇: Add Two Numbers
下一篇: Median of Two Sorted Arrays
子米
博客等级 码龄14年 3粉丝 17原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值