【leetcode】3. Longest Substring Without Repeating Characters (medium)

Lumerical-定向耦合器1 概述:本文章使用FDE求解器对定向耦合器进行了数值仿真,讨论了耦合器的间距相关性,耦合长度相关性,波长相关性。讨论了脊形波导和条形波导两种情况。 阅读详情

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.

// 求最大无重复字符的子串
注意,是无重复字符的,最大长度子串长度。

//3. Longest Substring Without Repeating Characters
// 求最大无重复字符的子串
int Solution::lengthOfLongestSubstring(string s)
{
	unordered_map<char, int> hash;
	int first = 0;
	int res = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		char cur = s[i];
		if (hash.size() == 0 || hash.find(cur) == hash.end())
		{
			hash.insert({ cur, i });
			res = hash.size() > res ? hash.size() : res;
		}
		else
		{
			int index = hash.find(cur)->second;
			auto it = hash.begin();
			while (it != hash.end())
			{
				if (it->second <= index) // 删掉前面的
				{
					it = hash.erase(it);
					hash.insert({ cur, i });
				}
				else
					++it;
			}
		}
	}
	return res;
}

效率一般,不过是ac了。

Runtime: 68 ms, faster than 22.72% of C++ online submissions for Longest Substring Without Repeating Characters.
Memory Usage: 20.5 MB, less than 20.56% of C++ online submissions for Longest Substring Without Repeating Characters.

2020.6.16

int lengthOfLongestSubstring(string s) {
	int res = 0;
	unordered_map<char, int> hash;

	for (int i = 0; i < s.size(); i++)
	{
		if (!hash.empty() && hash.find(s[i]) != hash.cend())
		{
			int index = hash.find(s[i])->second;
			auto it = hash.begin();
			while (it != hash.end())
			{
				if (it->second <= index)
				{
					it = hash.erase(it);
				}
				else
				{
					it++;
				}
			}
			hash.insert({ s[i], i });
		}
		else{
			hash.insert(std::make_pair(s[i], i));
			res = res > hash.size() ? res : hash.size();
		}
	}
	return res;
}

IDEA 导入 jbolt项目(实验室非公开项目) 提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录准备一、准备数据库二、IDEA导入jbolt项目 准备 在实验室群文件中下载jbolt.zip和mysql.sql两个文件 将其解压到自己的目录下 一、准备数据库 打开Navicat新建一个jbolt数据库(字符集为utf8) 导入mysql.sql文件 数据库导入完毕 二、IDEA导入jbolt项目 点击打开一个项目 选择jbolt文件夹 以Maven形式打开 打开pom.xml 在里面添加jetty-server依赖 阅读详情

相关推荐

PSIM联合VS--C++实现正弦波发生

在利用VS联合PSIM仿真中,想要用VS构建一个正弦波发生模块。可以利用Sin函数进行编写,重点是需要编写一个计数器程序。首先打算用for循环语句来构建计数器,但在for循环运行时无法跳出,不能实时获得计数器的值。同理,while循环也无法实现。最后将count变量设置为static型,解决了这一问题。 体现出对于c++程序的运行不够了解,需要多进行程序的编写和调试。 //时钟计数器 static int count = 0; count++; if (count > Sinfre)

weixin_41850228的博客 1086

3. Longest Substring Without Repeating Characters题目和答案详解

1 题目简述 Given a string, find the length of the longest substring withoutrepeating characters. 给定一个字符串,找到最长的没有重复字符的子串。 Examples: Given "abcabcbb", theanswer is "abc", which the lengthis 3. 给定

Disappear_XueChao的博客 431

华为HCIP-001:PPPOE配置模拟实验

华为HCIP01:PPPOE配置模拟实验 实验环境 pppoe-client上面的接口信息 [AR1]dis ip interface brief *down: administratively down ^down: standby (l): loopback (s): spoofing The number of interface that is UP in Physical is 2 The number of interface that is DOWN in Physical is 1 Th

兔子乖乖 1797

[LeetCode] 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 is “abc”, with the length of 3. Example 2: Inpu...

Deephome的博客 221

Vue+ECharts-GL 3D地图实战:5层叠加打造炫酷中国地图(附完整代码)

本文详细介绍了如何利用Vue和ECharts-GL构建具有强烈立体感的3D中国地图。通过5层图层的巧妙叠加与样式调校,实现了从背景阴影到交互高光的完整视觉层次,并整合了动态飞线与散点标记。文章提供了完整的代码实现、核心配置解析以及性能优化与视觉调优的实战技巧,帮助开发者快速打造专业级的交互式地图可视化应用。

d6e7f8g9h的博客 649

深入剖析一个卷积块(ConvBlock)

深入剖析一个卷积块(ConvBlock)

qq_45670407的博客 1920

3. Longest Substring Without Repeating Characters

题目: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the an

StudingCoder的博客 310

Win11系统下Abaqus2022与VS2022+oneAPI2023环境配置全攻略(附VUMAT子程序避坑指南)

本文详细指导在Windows 11系统下,为Abaqus 2022配置Visual Studio 2022与Intel oneAPI 2023的Fortran编译环境,以支持VUMAT等用户子程序开发。内容涵盖软件安装顺序、环境变量关联、快捷方式修改及关键验证步骤,并提供了首个VUMAT子程序的实战编写与模型验证方法,帮助用户高效搭建稳定可靠的仿真开发平台。

pytorch8learner的博客 316

LeetCode 3.Longest Substring Without Repeating Characters c语言版

问题描述: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is

banana1006034246的博客 2352

AutoSAR系列讲解(深入篇)14.7-Mcal Adc配置(上)

详细讲解了ADC的各个配置项的作用

雪云飞星的博客 1万+

Arduino I2C for TCA9548A应答扫描程序

Arduino I2C for TCA9548A应答扫描程序

perseverance51博客 1119

找最长无重复子字符串的长度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 is “abc”, with the length of 3. Example 2: Input: ...

zgj_gutou的博客 249

FM1288回声消除芯片调试方案 - 综述

专栏文章概览

优快云mianfeixiazai001的博客 1714

【Leetcode Medium】3. Longest Substring Without Repeating Characters

原题链接 题目描述 找到一个字符串中不出现重复字符的最长字符串并返回该子串长度 解题思路 发现碰到这种问题我的第一反应永远是暴力解法× 固然能完成题目,但效率是真的低下qwq 最暴力的就是O(n²),两个for循环嵌套找子串,比较简单,代码就不贴了 其他解法 法一:滑动窗口 ——解决字符串问题&数组问题的常用方法 和暴力解法的基本思想是相同的,使用hashset来模拟滑动窗口找到符合条...

JellyFishDing的博客 179

VB摄像头监控

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

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

【Leetcode】3. Longest Substring Without Repeating Characters [Medium]

Description Given a string, find the length of the longest substring without repeating characters. Example Example1: Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3...

Joyer的博客 145

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Leetcode Medium 3 Longest Substring Without Repeating Characters

用滑动窗口  class Solution: def lengthOfLongestSubstring(self, s): i, j, ans = 0, 0, 0 len_s = len(s) max_str = '' while j &lt; len_s: if not s[j] in max_s...

likyoo的博客 146

Leetcode 3. Longest Substring Without Repeating Characters [medium][java]

Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters. Example Consideration use set to store the previous characters c...

inkhk的博客 123

LeetCode 3. Longest Substring Without Repeating Characters(medium)

题目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: The answe...

qq_38715538的博客 118

[LeetCode] (medium) 3. Longest Substring Without Repeating Characters

https://leetcode.com/problems/longest-substring-without-repeating-characters/   Given a string, find the length of the longest substringwithout repeating characters. Example 1: Input: "abcabcbb" ...

Frontier_Setter的博客 148

Leetcode3. Longest Substring Without Repeating Characters(Medium)

Source:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Time:2020/11/18 Description Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = “abcabcbb” Output: 3 Explanation

Jerome_Chen_Y的博客 164

LeetCode - Medium - 3. Longest Substring Without Repeating Characters

Topic Hash Table Two Pointers String Sliding Window Description https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string s, find the length of the longest substring without repeating characters. Example 1: Input: s = "

KISS 213

LeetCode_Medium_3. Longest Substring Without Repeating Characters

2019.1.21 题目描述: 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...

weixin_41637618的博客 156

LeetCode 3. Longest Substring Without Repeating Characters [Medium]

哈希表求最长子字符串,DP问题。

u012911419的博客 248

Leetcode 3. Longest Substring Without Repeating Characters (Medium) (cpp)

Leetcode 3. Longest Substring Without Repeating Characters (Medium) (cpp)

还是需要多学习!闷声大发财,这是坠吼的! 804

LeetCode算法题之3. Longest Substring Without Repeating Characters(medium)

声明: 因本人为AI路上的新手,文章用于辅助个人的整理记忆,理解难免有偏差之处,都是个人拙见,如给其他同僚造成困扰,还请见谅,非常非常非常欢迎私信共同讨论,共同进步 题目描述: Given a string, find the length of the longest substring without repeating characters. Example 1: Input: “abcab...

DaMoWangZQ的博客 194

Leetcode 3[medium]--- Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the l...

fawnzou2017的博客 215

[Leetcode 3, Medium] Longest Substring Without Repeating Characters

Problem: 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 ...

weixin_30911809的博客 101
上一篇: 【leetcode】728. Self Dividing Numbers -- easy
下一篇: lua/c++中的三角函数与反三角函数,操作的是弧度非角度
eclipse_c
博客等级 码龄14年 28粉丝 162原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值