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. 使用jspatch进行热修复的实战总结

    最近正式在线上项目中集成了jspatch进行热修复,这里做一个简单的总结. 工具篇: 首先,用xcode来编辑js非常困难,基本上没有缩进,完全需要手写:经过研究发现使用 Sublime text3 ...

  2. JAVA修饰符

    修饰符用来定义类.方法或者变量,通常放在语句的最前端.我们通过下面的例子来说明: public class className { // ... } private boolean myFlag; s ...

  3. Asp.net 加载事件(转载)

    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...

  4. oracle 查询结果集运算

    intersec:交集minus:差集union:进行表连接后会筛选掉重复的记录,表连接之后对结果进行排序运算,删除重复记录在返回结果. union all:只是简单的将两个结果合并就返回.无论是否有 ...

  5. Open Close Principle 开闭合原则

  6. u-boot FIT image介绍_转自“蜗窝科技”

    转自:http://www.wowotech.net/u-boot/fit_image_overview.html 1. 前言 Linux kernel在ARM架构中引入设备树device tree( ...

  7. 解决windows下FileZilla server中文乱码问题

    最利用cuteftppro FTP做文件夹同步,发现中文的文件夹及文件名都出现了乱码问题, 一开始以为是cuteftppro的问题,谷哥度娘找了一堆的解决方案都没有解决乱码问题,真是头疼啊! 后来终于 ...

  8. java内省机制及PropertyUtils使用方法

    背景 一般情况下,在Java中你可以通过get方法轻松获取beans中的属性值.但是,当你事先不知道beans的类型或者将要访问或修改的属性名时,该怎么办?Java语言中提供了一些像java.bean ...

  9. linux查看某个进程内存占用情况以及/proc/pid/status解释

    以nginx 为例1.toptop -b -n 1 |grep nginx|awk '{print "VIRT:"$5,"RES:"$6,"cpu:& ...

  10. APP开发流程

    1.申请一个开发者账号: 2. App的idea形成: 3. App的主要功能设计: 4. App的大概界面构思和设计(使用流程设计): 5. 大功能模块代码编写: 6. 大概的界面模块编写: 7. ...