leetcode--js--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 length of 1.
Given "pwwkew"
, 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.
问题思路:
(1)审清题目:最长不重复的子串
(2)将第i个字符放在数组arr中,判断下一个字符有没有在arr中出现,如果出现,则重新从i-len+1处开始。
(3)需要记录下每次循环的arr的最大长度
code:
- var lengthOfLongestSubstring = function(s) {
- var arr=[];
- var str = s.split('');
- var max = 0;
- var len = 0; //arr[]数组的长度
- for(var i=0;i<str.length;i++){
- if(arr.indexOf(str[i])==-1){
- arr.push(str[i]);
- len = len + 1;
- max = max > len ? max : len;
- }else{
- i = i - len + 1;
- arr.splice(0, len, str[i]);
- len = 1;
- }
- }
- return max;
- };
leetcode--js--Longest Substring Without Repeating Characters的更多相关文章
- C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告
Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...
- LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)
题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...
- LeetCode 3 Longest Substring Without Repeating Characters 解题报告
LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...
- [LeetCode][Python]Longest Substring Without Repeating Characters
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...
- LeetCode之Longest Substring Without Repeating Characters
[题目描述] Given a string, find the length of the longest substring without repeating characters. Exampl ...
- Leetcode 3. Longest Substring Without Repeating Characters (Medium)
Description Given a string, find the length of the longest substring without repeating characters. E ...
- [Leetcode Week1]Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/longes ...
- [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
- 【leetcode】Longest Substring Without Repeating Characters
题目描述: Given a string, find the length of the longest substring without repeating characters. For exa ...
随机推荐
- python 线程条件
条件.事件.信号量本质上都是锁,不常用 """ 常用方法: obj,acquire() Obj.release() obj.wait(),创建是阻塞状态,等待obj.no ...
- Java入门 - 语言基础 - 18.正则表达式
原文地址:http://www.work100.net/training/java-regular-expression.html 更多教程:光束云 - 免费课程 正则表达式 序号 文内章节 视频 1 ...
- 信息: TLD skipped. URI: http://www.fusioncharts.com/jsp/core is already defined
二月 02, 2018 11:43:28 上午 org.apache.catalina.startup.TaglibUriRule body 信息: TLD skipped. URI: http:// ...
- springboot集成quartz实现任务调度
quartz 概述 特点 强大的调度功能 灵活的应用方式 分布式和集群能力 用到的设计模式 Builder 模式 factory模式 组件模式 链式写法 体系结构 调度器 任务 触发器 架构图 spr ...
- PMP——项目管理的价值观与方法论
关于项目管理的十个成语: 未雨绸缪(计划.风险):识别风险.做出计划.并指定负责人: 防微杜渐(监控.纠正):持续的实时的监控计划,监控和发现偏差,并进行纠正: 资源集成(整合.采购):把最专业的资源 ...
- springIOC源码接口分析(五):ListableBeanFactory
一 继承关系 该接口是对BeanFactory的扩展,允许预加载bean定义的BeanFactory可以实现此接口 其目的在于使实现它的BeanFactory能够枚举所有的Bean 该接口不支持分层结 ...
- Nutz | Nutz项目整合Spring实战
Nutz项目整合Spring实战 前言 Github地址 背景 实现步骤 加入springMvc与Spring 相关配置 新增Spring相关配置 新增SpringIocProvider 重写Nutz ...
- 并发队列之PriorityBlockingQueue
这一篇说一下PriorityBlockingQueue,引用书中的一句话:这就是带优先级的无界阻塞队列,每次出队都返回优先级最高或者最低的元素(这里规则可以自己制定),内部是使用平衡二叉树实现的,遍历 ...
- 如何把您现有的流程系统数据迁徙到驰骋BPM上?
关键词:流程系统版本切换\ 驰骋BPM. 如何把您现有的流程系统数据迁徙到驰骋BPM上?这是一个大问题.在处理改问题之前,首先要了解驰骋bpm的数据库结构,驰骋bpm的特性在做计划. 驰骋BPM的流程 ...
- Spring使用外部属性文件
一.在 Spring Config 文件中配置 Bean 时,有时候需要在 Bean 的配置里添加 系统部署的细节信息, 如文件路径,数据源配置信息.而这些部署细节实际上需要在配置文件外部来定义. 二 ...