https://leetcode.com/problems/longest-substring-without-repeating-characters/

思路:从某点结束所能取到的最早开头是到目前出现倒数第二次的字符的最末位置后一位

如图:(S代表起点,T代表终点)

abcabcab

**S*T

假设现在在4位,向前找,a出现的倒数第二次在0位,b出现的在1位,所以可以从2位开始取

class Solution {
public:
int lengthOfLongestSubstring(string s) {
int ans = 0;
typedef pair<int,int> P;
priority_queue<P> que;
int vis[256];memset(vis,-1,sizeof vis);
int used[256];memset(used,-1,sizeof used);
for(int i = 0;i < s.length();i++){
used[s[i]] = vis[s[i]];
vis[s[i]] = i;
que.push(P(used[s[i]],s[i]));
while(!que.empty() && used[que.top().second]!= que.top().first)que.pop();
if(!que.empty())ans = max(ans,i - que.top().first);
else {ans = max(ans,i + 1);}
}
return ans;
}
};

  

LeetCode 3 Longest Substring Without Repeating Characters 区间,想法 难度:1的更多相关文章

  1. C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告

    Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...

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

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

  3. LeetCode 3 Longest Substring Without Repeating Characters 解题报告

    LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...

  4. [LeetCode][Python]Longest Substring Without Repeating Characters

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...

  5. LeetCode之Longest Substring Without Repeating Characters

    [题目描述] Given a string, find the length of the longest substring without repeating characters. Exampl ...

  6. Leetcode 3. Longest Substring Without Repeating Characters (Medium)

    Description Given a string, find the length of the longest substring without repeating characters. E ...

  7. [Leetcode Week1]Longest Substring Without Repeating Characters

    Longest Substring Without Repeating Characters题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/longes ...

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

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

  9. LeetCode[3] Longest Substring Without Repeating Characters

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

随机推荐

  1. SQL中常用模糊查询的四种匹配模式&&正则表达式

    执行数据库查询时,有完整查询和模糊查询之分.一般模糊语句如下:SELECT 字段 FROM 表 WHERE 某字段 Like 条件 其中关于条件,SQL提供了四种匹配模式:1.%:表示任意0个或多个字 ...

  2. ionic imgBase64

    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: , destinationType: destinationTyp ...

  3. struts2漏洞集合

    [+]1 S2-005 CVE-2010-1870 CVE-2010-1870 影响版本:Struts 2.0.0 – Struts 2.1.8.1 官方公告:http://struts.apache ...

  4. Cocos2d-x 核心概念 - 坐标系(UI.OpenGL.世界坐标系.模型坐标系)

    UI坐标系与OpenGL坐标系 UI坐标就是Android和IOS等应用开发时候使用的二维坐标系,原点在左上角 OpenGL坐标是三维坐标,由于Cocos2d-x Lua 底层采用OpenGL渲染,因 ...

  5. 各种SKYPE网页代码,SKYPE在线代码

    各种SKYPE网页代码,SKYPE在线代码 <a href="skype:账户?chat" target="_blank">开始 Skype 文字聊 ...

  6. JAVA 1.8 理解面向对象程序设计

    1. break语句:经常用在循环语句中,用于跳出整个循环,执行循环后面的代码. 2. continue语句:经常用在循环语句中,用于跳出当前的这个循环(或者是跳出本次循环),开始下一次循环的执行. ...

  7. nginx rewrite 实现二级域名跳转

    当访问http://cbs.test.com跳转到http://www.test.com/test/cbs/方法一: (这种方法浏览器地址会变www.test.com/test/cbs)server ...

  8. laravel 5.2 引入第三方类

    composer 安装类依赖包 很受用 也很方便 但是要是一个有一定规模的公司技术团队 因为要照顾大局 还是引入类好些 下面是引入类的方法 1.首先在app目录下创建一个新的文件夹,命名Tools(可 ...

  9. Neo4j 3.0 存储过程

    Neo4j 3.0 提供一个新的功能“存储过程”,该功能并不是Neo4j-Server的扩展,而是可以直接运行的. 在写这篇文章的时候,只能通过预备好的语句去执行 1 CALL package.pro ...

  10. ionic实现双击返回键退出功能

    实现这个功能需要四个步骤: 步骤一: 说明:因为需要和手机的硬件(返回按钮)打交道,而ionic本身是不具备该功能的,但是有一个东西可以:ng-cordova插件,这个插件是phoneGap为了能让i ...