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 ...
随机推荐
- Python之路-基础数据类型之字符串
字符串类型 字符串是不可变的数据类型 索引(下标) 我们在日常生活中会遇到很多类似的情况,例如吃饭排队叫号,在学校时会有学号,工作时会有工号,这些就是一种能保证唯一准确的手段,在计算机中也是一样,它就 ...
- Python 频繁请求问题: [Errno 104] Connection reset by peer
Table of Contents 1. 记遇到的一个问题:[Errno 104] Connection reset by peer 记遇到的一个问题:[Errno 104] Connection r ...
- Sql日期时间格式转换(转 子夜.)
sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, 20) 结果:2007-0 ...
- 图学java基础篇之集合
(本文部分图片引用自其他博客,最后有链接,侵删.由于笔记使用markdown记录,格式可能不是太好看,见谅) 集合结构 红字为java.util包下的,绿字为concurrent包下扩展的与并发相关的 ...
- TCP/IP网络编程之优于select的epoll(二)
基于epoll的回声服务端 在TCP/IP网络编程之优于select的epoll(一)这一章中,我们介绍了epoll的相关函数,接下来给出基于epoll的回声服务端示例. echo_epollserv ...
- python协程--yield和yield from
字典为动词“to yield”给出了两个释义:产出和让步.对于 Python 生成器中的 yield 来说,这两个含义都成立.yield item 这行代码会产出一个值,提供给 next(...) 的 ...
- 实战项目——获取图片中的GPS位置信息和拍摄时间
今天突然看到有人写过获取图片中位置信息的程序.我觉得很有趣,也就自己实践了一下,研究了一下 话不多说,先上代码 #!/usr/bin/env python3 # -*- coding: utf-8 - ...
- SGX技术初探
一.SGX技术背景 1.1 SGX技术定义 SGX全称Intel Software Guard Extensions,顾名思义,其是对因特尔体系(IA)的一个扩展,用于增强软件的安全性.这种方式并不是 ...
- Zookeeper CreateMode
通过CreateMode 可以设置在zookeeper中创建节点的类型,节点类型共有4种: EPHEMERAL:临时节点 EPHEMERAL_SEQUENTIAL:有序的临时节点 PERSISTENT ...
- post方式的数据抓取
public static String sendPost(String url, String param) { PrintWriter out = null; Buff ...