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 ...
随机推荐
- powershell Google Firefox
$firefox = @{ DisplayName = "Mozilla Firefox"; filename = "Firefox Setup 68.0b7.msi&q ...
- (转) XSS Attacks – Exploiting XSS Filter
中文翻译: from wooyun'drops 0x00 前言 这又是一篇来自全职赏金猎人Masato kinugawa的神作.一次双杀,用一篇报告拿下了两个CVE,分别是CVE-2015-6144和 ...
- Mixing .NET
- Java and MongoDB link for project
鉴于开源项目的发展,大力拥抱开源社区.发现Java和MongoDB不失为一个较好的选择. 与其他数据库一样,同样需要mongo-java-driver,构建了Java与MongoDB的交互. 1. 连 ...
- python 3 创建虚拟环境(Win10)
python 3 创建虚拟环境(Win10) ①为什么要用虚拟环境? 为了解决一个环境多个项目的版本冲突问题 ②如何创建虚拟环境? 用窗口键+R来打开win10的运行窗口,然后在运行输入框输入cmd, ...
- STM32 调试 24L01 心得
大部分使用STM32开发nrf24L01的用户基本都是照搬常见的几个开发板的源代码,在这里我做一些总结: 1.源代码中在while(1)的循环中有 NRF24L01_TX_Mode();或NRF24L ...
- spring中创建bean对象的三种方式以及作用范围
时间:2020/02/02 一.在spring的xml配置文件中创建bean对象的三种方式: 1.使用默认构造函数创建.在spring的配置文件中使用bean标签,配以id和class属性之后,且没有 ...
- CAD制图系列之中心线画法
我们将做个简单的笔记: CAD中心线怎么画 CAD中心线一般为点划线,画法很简单,首先先设置线型 一般步骤为: 1.首先,打开CAD,点击进入图层特性管理器 2.在图层特性管理器中点击线型进行设置 3 ...
- webdriver高级应用(2) - 滚动条操作
webdriver高级应用(2) - 滚动条操作 #-*- coding:utf-8 -*- from selenium import webdriver import unittest import ...
- Jmeter源码编译缺bouncycastle包
Jmeter源码下载后install没问题,运行newDrive时会包包不存在,因为下载时缺少三个包没下载成功,点击链接下载并放到lib目录下即可 下载