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. static变量引起的问题,List数据覆盖

    出现的问题:Listt加载数据时,后面加载的数据会覆盖前面的数据,把后面的数据变得和前面一样 原因:因为刚开始把添加的数据写成了静态变量,所以一个改了以后所有都改了 解决方法:把数据设成普通属性,非静 ...

  2. 关于APP程序员泡沫经济

    这些年,移动互联网非常火,火到掀起学习iOS.安卓以及H5的热潮.有人将这些新技术作为自己的实力补充,增加竞争力:更多的人将它们作为主业,专职做移动开发.但是,即便有移动开发人员不断涌入,对整个行业来 ...

  3. less简单用法

    http://less.bootcss.comless工具:koala工具url:http://koala-app.com/index-zh.html// less import: // less 文 ...

  4. Kerberos是怎么工作的?

    Kerberos是一种计算机网络授权协议,用来在非安全网络中,对个人通信以安全的手段进行身份认证. 采用客户端/服务器结构,并且能够进行相互认证,即客户端和服务器端均可对对方进行身份认证. 关键要素 ...

  5. Lucene 简单API使用

    本demo 简单模拟实现一个图书搜索功能. 模拟向数据库添加数据的时候,添加书籍索引. 提供搜索接口,支持按照书名,作者,内容进行搜索. 按默认规则排序返回搜索结果. Jar依赖: <prope ...

  6. Greenplum第三方工具链接

    在master节点的$MASTER_DATA_DIRECTORY/pg_hba.conf中添加新客户端服务器信息 #add host     all         gpadmin         0 ...

  7. 转:ProgressMonitorDialog

    http://stackoverflow.com/questions/12986912/using-progressmonitordialog-in-eclipse-4-properly public ...

  8. 初识Polymer框架

    什么是polymer? polymer由谷歌的Palm webOS团队打造,并在2013 Google I/O大会上推出,旨在实现Web Components,用最少的代码,解除框架间的限制的UI 框 ...

  9. 分组找ID

    select t.name1,t.name2,t.zx from (select row_number()over(partition by name1 order by zx desc)rn, te ...

  10. Java内存模型

    1. 概述 多任务和高并发是衡量一台计算机处理器的能力重要指标之一.一般衡量一个服务器性能的高低好坏,使用每秒事务处理数(Transactions Per Second,TPS)这个指标比较能说明问题 ...