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.Examples:Given “abcabcbb”, the answer is “abc”, which the length is 3.Given “bbbbb”, the answer is “b”, with the le 阅读详情

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.

算法思想:[begin,end]两个指针,根据end位置的字符值调整。

代码

int lengthOfLongestSubstring(string s) {
    if(s.size()==0)
        return 0;
    //用数组posChar记录end前每个字符在s中最后索引位置,
    //如果当前字符c在begin-end中出现(即pos[c]>=begin),更新begin=pos[c]+1
    vector<int> posChar(128,-1);    
    int begin=0,end=1,maxLength=1;
    posChar[s[0]]=0;
    while(end<s.size()){
        if(posChar[s[end]]>=begin){
            begin=posChar[s[end]]+1;
        }else if(end-begin+1>maxLength){
            maxLength=end-begin+1;
        }
        posChar[s[end]]=end;
        end++;
    }
    return maxLength;
}
LeetCode 题解 3. Longest Substring Without Repeating Characters(最长不含重复字符的子字符串) 阅读详情

相关推荐

KUKA机器人 - 从开机到自动运行

注1:本文仅代表本人对机器人使用的一些建议,在使用机器人前,还请详细阅读库卡机器人官方资料,道路千万条,安全第一条!!! 注2:技术有限,欢迎各位大大在阅读过程中发现各类问题,并且批评指正!!! 目录 一、准备工作 1. 机器人上电完成 2. 电脑安装Workvisual 二、学习手动移动机器人 三、项目配置 1. 设置机器人IP地址 2.电脑和机器人通过网线连接 3.查找并打开项目 4. 通讯配置 5. 项目上传 6. 检验IO配置 四、编程 1.新建程序 2. 程序...

yilunyao的博客 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...

博学 笃志 切问 近思 159

Android14_MTK调试LCD屏功能

android14 MTK平台调试LCD屏

m0_37786046的博客 1473

leetcode--3. Longest Substring Without Repeating Characters

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

林伏案的博客 459

MODIS 遥感数据批量下载(使用Cygwin)

MODIS 遥感数据批量下载(使用Cygwin)包含Cygwin的下载教程

weixin_45913084的博客 916

华为面试手撕真题【最长不重复子串】

给定一个字符串s,请你找出其中不含有重复字符的最长子串的长度。

MISAYAONE的博客 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 Expla...

weixin_30795127的博客 110

【CAD】【手把手带你写一个DXF&JAVA解析框架】02——整理DXF元数据实体类,涵盖重要属性与对照组码

本文系统梳理了DXF文件解析中的核心元数据类,重点分析了Tables段(图层、块记录)、Blocks段和Entities段的关键数据结构。通过详细的组码说明和对照代码实现,阐述了图层定义(DXFLayer)、块记录(DXFBlockRecord)、应用程序标识(DXFAppId)等表对象的属性构成;同时解析了直线(DXFLine)、多段线(DXFLwPolyLine)、圆弧(DXFArc)、文字(DXFText)等实体类的几何特征与属性定义。文章还构建了顶点(Vertex)、基类(DXFEntity、DXF

Wonder ZH 268

[LeetCode]3. 无重复字符的最长子串(Longest Substring Without Repeating Characters)题解

在leetcode中该题网址:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/ 题目描述: 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 ...

sultry_yi的博客 524

游戏引擎定制化:大厂如何玩转性能极限(大白话生动有趣版)

游戏大厂如何深度定制游戏引擎?本文系统解析了商业引擎的局限性及大厂定制化的核心诉求。主要内容包括: 大厂定制引擎的根本原因:性能瓶颈、差异化需求、自有生态整合等 主流引擎的优劣势对比及适用场景 定制化重点领域:渲染管线优化、物理系统重构、网络架构改造等 全流程定制方案:从需求分析到模块重构再到工具链开发 典型案例:如腾讯CF手游的渲染优化、原神的热更新系统等 文章指出,顶级游戏产品必须对引擎核心模块动刀,通过深度定制实现性能突破和创新功能开发。同时提供了风险规避建议和技术演进趋势,为游戏开发者提供了宝贵的实

本博客聚焦游戏开发技巧、创业实战心得及大学热门课程干货。这里既有技术深度,也有思维广度,无论你是开发者、创业者还是高校学子,都能在这里找到适合自己的成长之路! 635

多物理场光学仿真软件:Lumerical_(15).多物理场耦合仿真案例分析

在多物理场光学仿真中,Lumerical 软件提供了强大的工具来模拟复杂的光学系统,包括光子学、热学、力学和电学等多物理场的耦合。本节将通过具体的案例分析,展示如何在 Lumerical 中进行多物理场耦合仿真的开发和实现。我们将从简单的热光效应仿真入手,逐步深入到更复杂的多物理场耦合场景,如光电效应和光力学效应。每个案例都将包括详细的原理说明和具体的代码示例,帮助读者更好地理解和应用这些技术。

kkchenjj的博客 1022

闯关leetcode——3.Longest Substring Without Repeating Characters

leetcode第三题

方亮的专栏 1340

基于STM32设计的智能防盗单车锁_349

本设计基于STM32F103RCT6单片机,研制了一种适用于户外环境的智能防盗单车锁系统。系统集成了GPS定位模块、ADXL345加速度传感器、4G通信模块(Air780E)、OLED显示屏、继电器模拟锁控模块等硬件,通过姿态感知实现车辆异常移动检测,在锁车状态下自动触发蜂鸣器报警并通过短信与APP通知用户。

867

LeetCode(3) Longest Substring Without Repeating Characters

LeetCode的第3题,给定一个字符串,找到其中的一个最长的字串,使得这个子串不包含重复的字符。 // // Solution.h // LeetCodeOJ_003_LongestUniqueSubstr // // Created by feliciafay on 11/21/13. // Copyright (c) 2013 feliciafay. All rights rese

BUILD 1万+

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【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向后遍......

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

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

LeetCode 3. Longest Substring Without Repeating Characters

LeetCode 3. Longest Substring Without Repeating Characters (Medium) 主要知识点:sliding window;优先级:4

温迪今天刷题了吗 269

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

【LeetCode】3. Longest Substring Without Repeating Characters

题目: Given a string, find the length of thelongest substringwithout repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3. Exampl...

希望的专栏 446

LeetCode之3. Longest Substring Without Repeating Characters

LeetCode上给的解决办法尝试 #1 暴力方法思考 一个个查看所有的子字符串看看是否没有相同的字符 算法 ——假设我们有一个函数,boolean allUnique(String substring),这个函数在String的每个子字符串中的字符都是两两不同的时候返回True。我们可以迭代字符串S中的所有子字符串并调用allUnique这个函数。如果返回True的话,我们就更新不

梦想,就现在! 485

[LeetCode] 3. Longest Substring Without Repeating Characters

题目链接: https://leetcode.com/problems/longest-substring-without-repeating-characters/description/ DescriptionGiven a string, find the length of the longest substring without repeating characters.Examples

从入门到扑街 424

Leetcode 3. Longest Substring Without Repeating Characters

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

ysCover 374

【leetcode】3. Longest Substring Without Repeating Characters

思路:begin记录longest substring开始的位置;longest当前substring的长度;map存放字符的index。实质上是维护了一个substring区间,使得substring内的所有字符都是独一无二的。 class Solution { public: int lengthOfLongestSubstring(string s) { if (...

zxc120389574的博客 183

LeetCode 3:Longest Substring Without Repeating Characters

滑动窗口方法滑动窗口例题 滑动窗口 滑动窗口是数组/字符串问题中常用的抽象概念。 窗口通常是在数组/字符串中由开始和结束索引定义的一系列元素的集合。 例题 LeetCode 3:无重复字符的最长子串 使用 HashSet 作为滑动窗口, 将字符存储在当前窗口 [i, j)最初 j = i)中。 然后我们向右侧滑动索引 j,如果它不在 HashSet 中,也就是当前窗口没有重复字符时,继续滑动 ,也...

qq_24367757的博客 236

leetcode【3】Longest Substring Without Repeating Characters

leetcode【3】Longest Substring Without Repeating CharacterstagsquestionExample:myAnswer 滑动窗口:尾部处理更为重要 tags **hash-table | two-pointers | string | sliding-window ** question Given a string, find the le...

qq_43305329的博客 131

[leetcode][python] 3. Longest Substring Without Repeating Characters

3. Longest Substring Without Repeating Characters 知识点:two pointers 1. 原题 Given a string, find the length of the longest substring without repeating characters. Example 1: Input: “abcabcbb” Output: 3 ...

qq_40670635的博客 406

[leetcode] 3. Longest Substring Without Repeating Characters @ python

原题 https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, find the length of the longest substring without repeating characters. Example 1: Input: “abcabcbb” Out...

闲庭信步 363
上一篇: leetcode 152 Maximum Product Subarray
下一篇: 网易163邮箱配置-iOS、OS X邮箱客户端
HelloCooper
博客等级 码龄11年 13粉丝 37原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值