LeetCode 3 : Longest Substring Without Repeating Characters ---- 不重复的子串
来源:互联网 发布:hash算法详解 编辑:程序博客网 时间:2024/06/17 17:10
原题链接: https://leetcode.com/problems/longest-substring-without-repeating-characters/
一:原题内容
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb"
, the answer is "abc"
, which the length is 3.
Given "bbbbb"
, the answer is "b"
, with the length of 1.
Given "pwwkew"
, the answer is "wke"
, with the length of 3. Note that the answer must be asubstring,"pwke"
is asubsequence and not a substring.
二:AC代码
class Solution {public: int lengthOfLongestSubstring(string s) { int flag[128]={0}; int ans=0;//the answer int j=0; for(int i=0;i<s.size();i++) { if(flag[s[i]]>0) { j=max(j,flag[s[i]]); } flag[s[i]]=i+1; ans=max(ans,i-j+1); } return ans; }};
class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ ret=0 left=0 d={} for index,value in enumerate(s): if value in d and d[value]>=left: left=d[value]+1 d[value]=index ret=max(ret,index-left+1) return ret
返回LeetCode 题解目录
1 0
- LeetCode 3 : Longest Substring Without Repeating Characters ---- 不重复的子串
- LeetCode 3. Longest Substring Without Repeating Characters--不包含重复字符的最长子串长度
- [C++]LeetCode 3: Longest Substring Without Repeating Characters(最长不重复子串)
- leetcode 3. Longest Substring Without Repeating Characters 最长不重复子串和重复子串
- [Leetcode #3]Longest Substring Without Repeating Characters 无重复字符的最长子串
- LeetCode-3:Longest Substring Without Repeating Characters (最长无重复字符的子串) --medium
- LeetCode Longest Substring Without Repeating Characters 最长不重复子串查找
- 【LeetCode】Longest Substring Without Repeating Characters && 【九度】题目1530:最长不重复子串
- leetcode-Longest Substring Without Repeating Characters 最长不重复子串
- LeetCode | Longest Substring Without Repeating Characters(最长连续不重复子串)
- Longest Substring Without Repeating Characters 最长不重复子串 @LeetCode
- Leetcode Longest Substring Without Repeating Characters(最长不重复子串)
- [leetcode]Longest Substring Without Repeating Characters【最长不重复字符子串】
- leetcode系列(31)Longest Substring Without Repeating Characters 最长不重复子串
- LeetCode 3. Longest Substring Without Repeating Characters(最长不重复子串)
- LeetCode OJ:Longest Substring Without Repeating Characters(最长不重复子串)
- Leetcode#3. Longest Substring Without Repeating Characters(最长不重复子串-哈希))
- leetcode Longest Substring Without Repeating Characters 最长不重复子串
- 18款开源/商用的Linux服务器控制面板
- ashx文件获取$.ajax()方法发送的数据
- Android 设置背景边框
- [疯狂Java]基础类库:命令行参数、Scanner
- Minimum Path Sum
- LeetCode 3 : Longest Substring Without Repeating Characters ---- 不重复的子串
- Python执行系统命令的方法 os.system(),os.popen(),commands
- 2016 - PayPal商家集成常见技术问题 - 官方整理
- 按钮点击多次出现多个相同页面问题
- 深入JVM虚拟机(四) Java GC收集器
- Mysql系列(九) 单引号与反引号
- Effective cpp 读书笔记5
- kickstart文件的密文生成
- Java反射