LeetCode OJ-- Longest Substring Without Repeating Characters ***@
https://oj.leetcode.com/problems/longest-substring-without-repeating-characters/
给一个string,找出其中不含有重复元素的最长子串的长度。
class Solution {
public:
int lengthOfLongestSubstring(string s) {
if(s.size() == || s.size() == )
return s.size(); map<char,int> map_record; int max_len = ;
int len = ;
for(int i = ; i < s.size(); i++)
{
len++; //维护当前的没有相同元素的范围长度
if(map_record.count(s[i]) != && map_record[s[i]] > i - len) //如果存在相同的元素,并且这个元素是在当前范围之内的
len = i - map_record[s[i]]; //更新当前范围的长度
map_record[s[i]] = i; max_len = max_len < len ? len : max_len;
}
return max_len;
}
};
LeetCode OJ-- Longest Substring Without Repeating Characters ***@的更多相关文章
- C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告
Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...
- [LeetCode][Python]Longest Substring Without Repeating Characters
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...
- LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)
题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...
- LeetCode 3 Longest Substring Without Repeating Characters 解题报告
LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...
- LeetCode之Longest Substring Without Repeating Characters
[题目描述] Given a string, find the length of the longest substring without repeating characters. Exampl ...
- Leetcode 3. Longest Substring Without Repeating Characters (Medium)
Description Given a string, find the length of the longest substring without repeating characters. E ...
- [Leetcode Week1]Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/longes ...
- [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
- 【leetcode】Longest Substring Without Repeating Characters
题目描述: Given a string, find the length of the longest substring without repeating characters. For exa ...
随机推荐
- Redis实现之字典跳跃表
跳跃表 跳跃表是一种有序数据结构,它通过在每个节点中维持多个指向其他节点的指针,从而达到快速访问节点的目的.跳跃表支持平均O(logN).最坏O(N)的时间复杂度查找,还可以通过顺序性操作来批量处理节 ...
- 通过js date对象获取各种开始结束日期的示例
有时候做一些任务计划的功能时候,需要提供一个开始时间或者结束时间,比如本周结束,本月结束,今天结束等等,因此,我参考网上的资料把相关的实现为一个项目: gitee: https://gitee.com ...
- models管理类抽取基类
Models类 models.py # coding:utf-8 from django.db import models from db.Base_model import Base_Model f ...
- 2、HTML基础总结 part-2
1.表单一 <html> <body> <form> 姓名: <input type="text" name="name&quo ...
- MFC定时关机程序的实现3-最小化到托盘栏
这个定时关机运行过后默认最小化到托盘栏最好了,不用每次都去点了. 现在来看看如何将程序显示在托盘栏. 首先在头文件里声明一个变量和一个消息响应函数 //最小化到托盘栏 //第一步,生成一个成员变量,或 ...
- Android Spinner组件的使用方法
Spinner是什么呢,其实就是我们常见的下拉框,比如: 首先,我们要创建一个Spinner,才能在Spinner中添加我们想要的元素,在xml文件中: <Spinner android:id= ...
- mysql环境变量配置(复制)
前面步骤完成后安装好MySQL,为MySQL配置环境变量.MySQL默认安装在C:\Program Files下. 1)新建MYSQL_HOME变量,并配置:C:\Program Files\MySQ ...
- 欧拉回路基础 HDU1878 欧拉回路||并差集
欢迎参加——每周六晚的BestCoder(有米!) 欧拉回路 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 【转】 [UnityUI]UGUI射线检测
http://blog.csdn.net/lyh916/article/details/50947026 1.Graphic Raycaster 主要用于UI上的射线检测,挂有这个组件的物体,必须要挂 ...
- Sum of Squares of the Occurrence Counts解题报告(后缀自动机+LinkCutTree+线段树思想)
题目描述 给定字符串\(S(|S|\le10^5)\),对其每个前缀求出如下的统计量: 对该字符串中的所有子串,统计其出现的次数,求其平方和. Sample Input: aaa Sample Out ...