LeetCode: 3. Longest Substring Without Repeating Characters

class Solution {
public:
int lengthOfLongestSubstring(string s) {
int ans = 0, i = 0, j = 0;
map <char , char> m;
int n = s.size();
while (i < n && j < n){
// 左闭右开
if(m.find(s[j]) == m.end()){
// 如果j符合
m[s[j]] = s[j];
j +=1;
ans = ans > (j - i ) ? ans :(j - i);
}
else {
// 否则窗口缩小,j不前进
m.erase(s[i]);// 从哈希表中移除
i +=1;
}
}
return ans;
}
};

[LeetCode_3] Longest Substring Without Repeating Characters的更多相关文章

  1. Leetcode_3. Find the longest substring without repeating characters

    3. Find the longest substring without repeating characters Given a string, find the length of the lo ...

  2. LeetCode[3] Longest Substring Without Repeating Characters

    题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...

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

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

  4. Longest Substring Without Repeating Characters

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

  5. 3. Longest Substring Without Repeating Characters(c++) 15ms

    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 exa ...

  7. Longest Substring Without Repeating Characters(C语言实现)

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

  8. leetcode: longest substring without repeating characters

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

  9. Longest Substring Without Repeating Characters (c#)

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

随机推荐

  1. CSS中有关水平居中和垂直居中的解决办法

    CCS中让div等块级元素在父级元素中居中的方法: (1)div{  margin:0 auto   } 该方法只能实现水平的居中,无法实现元素的垂直居中 (2)当div元素的宽高是固定的,然后设置位 ...

  2. [原创]Hadoop默认设置导致NameNode启动失败一例

    看到市面上很多书在讲解Hadoop的时候都轻描淡写的提到了HDFS的设置问题.大多采取的是默认设置,最多也就是设置一些副本数量之类. 笔者在工作中遇到了这样一种情况:每次重启系统之后,NameNode ...

  3. 如何在springMVC 中对REST服务使用mockmvc 做测试

    如何在springMVC 中对REST服务使用mockmvc 做测试 博客分类: java 基础 springMVCmockMVC单元测试  spring 集成测试中对mock 的集成实在是太棒了!但 ...

  4. 首次用U盘安装CentOS

    安之前看了这篇文章,http://www.osyunwei.com/archives/2307.html,然后就开始了. 首先下载ultraiso,官网下载的,将centos的iso镜像写到u盘上. ...

  5. Java 多线程之单例设计模式

    转载:https://segmentfault.com/a/1190000007504892 概念: Java中单例模式是一种常见的设计模式,单例模式的写法有好几种,这里主要介绍两种:懒汉式单例.饿汉 ...

  6. 微信小程序开发POST请求

    onLoad: function() { that = this; wx.request( { url: "http://op.juhe.cn/onebox/weather/query&qu ...

  7. iOS10配置说明

    1:如果你的App想要访问用户的相机.相册.麦克风.通讯录等等权限,都需要进行相关的配置,不然会直接crash掉. 要想解决这个问题,只需要在info.plist添加NSContactsUsageDe ...

  8. Git的.gitignore文件配置

    .gitignore是Git工具的配置文件,用于屏蔽某些文件上传到线上. 创建.gitignore 在window系统中,不允许新建文件名以"."开头的文件,所以通过git bas ...

  9. VS快速生成JSON数据格式对应的实体

          有固定好的Json数据格式,你还在手动敲对应的实体吗?有点low了!步入正题,这是一个json字符串,先去验证JSON数据格式(http://www.bejson.com/)如下: { & ...

  10. Babel下的ES6兼容性与规范

    前端开发 Babel下的ES6兼容性与规范   ES6标准发布后,前端人员也开发渐渐了解到了es6,但是由于兼容性的问题,仍然没有得到广泛的推广,不过业界也用了一些折中性的方案来解决兼容性和开发体系问 ...