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.

class Solution
{
public:
int lengthOfLongestSubstring(string s)
{
int len = s.length();
bool exist[maxn] = {false};
int maxLen = ; int i = , j = ;
while(j < len)
{
if(exist[s[j]])
{
maxLen = max(maxLen, j - i);
while(s[i] != s[j])
{
exist[s[i]] = false;
++i;
}
++i;
++j;
}
else
{
exist[s[j]] = true;
++j;
}
}
maxLen = max(maxLen, len - i);
return maxLen;
}
private:
const int maxn = ;
};

Longest Substring Without Repeating Characters ---- LeetCode 003的更多相关文章

  1. Longest Substring Without Repeating Characters leetcode java

    题目: Given a string, find the length of the longest substring without repeating characters. For examp ...

  2. Longest Substring Without Repeating Characters -- LeetCode

    原题链接: http://oj.leetcode.com/problems/longest-substring-without-repeating-characters/ 这道题用的方法是在LeetC ...

  3. 【JAVA、C++】LeetCode 003 Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  4. 【LeetCode刷题系列 - 003题】Longest Substring Without Repeating Characters

    题目: Given a string, find the length of the longest substring without repeating characters. Example 1 ...

  5. 【LeetCode】003. Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  6. [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  7. leetcode: longest substring without repeating characters

    July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http: ...

  8. No.003:Longest Substring Without Repeating Characters

    问题: Given a string, find the length of the longest substring without repeating characters.Example:Gi ...

  9. LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)

    题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...

随机推荐

  1. hust--------The Minimum Length (最短循环节)(kmp)

    F - The Minimum Length Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %l ...

  2. VS简介

    visual studio2012 代码编程常用工具 1.起始页,存放一些方便打开的快捷方式,开始-新建项目-打开项目 2.最近-最近的项目 3.视图里面有一系列面板,窗口,比如起始页,工具箱,文档大 ...

  3. Java:JDK安装

    访问Oracle网站www.oracle.com/technetwork/java/javase/downloads下载jdk 安装JDK时,不建议安装在有空格的路径名下,例如该目录c:\Progra ...

  4. partition by

    在row_number() over()中的over使用,其后需要配合order by   ROW_NUMBER () over (partition by username   order by i ...

  5. ros科大讯飞语音识别环境配置

    以在线命令词识别为例: 链接:http://www.xfyun.cn/sdk/dispatcher 1.下载SDK,解压: 2.在ROS工作空间下创建一个Package: catkin_create_ ...

  6. Chrome 开发者工具有了设备模拟器

    今天从哥们那里学到了一个小技巧,使用chrome自带的多设备模拟器来调试页面在不同设备下的显示效果. 特地上网查了一下,记录一下. 如果想要在 Chrome 上测试网站在不同设备,不同分辨率的显示情况 ...

  7. AJAX初步

    1.什么是AJAX 客户端与服务器,可以在[不必刷新整个浏览器]的情况下,与服务器进行异步通讯的技术,即,AJAX是一个[局部刷新]的[异步]通讯技术: AJAX不是全新的语言,是2005年Googl ...

  8. LightOJ 1047-Program C

    Description The people of Mohammadpur have decided to paint each of their houses red, green, or blue ...

  9. NIO基础

    通道和缓冲区 概述 通道 和 缓冲区 是 NIO 中的核心对象,几乎在每一个 I/O 操作中都要使用它们. 通道是对原 I/O 包中的流的模拟.到任何目的地(或来自任何地方)的所有数据都必须通过一个 ...

  10. 移动设备和SharePoint 2013 - 第3部分:推送通知

    博客地址:http://blog.csdn.net/foxdave 原文地址 在该系列文章中,作者展示了SharePoint 2013最显著的新功能概观--对移动设备的支持. 该系列文章: 移动设备和 ...