LeetCode-- Longest Substring Without Repeating Characters
来源:互联网 发布:王晨芳 网络黄金 编辑:程序博客网 时间:2024/06/06 08:38
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 a substring, “pwke” is a subsequence and not a substring.
思路:用字典数组存放下标,更新start变量。
class Solution {public: int lengthOfLongestSubstring(string s) { vector<int>dict(256,-1); int maxLen=0,start=-1; for(int i=0;i<s.size();i++) { if(dict[s[i]]>start) start=dict[s[i]]; dict[s[i]]=i; maxLen=max(maxLen,i-start); } return maxLen; }};
阅读全文
1 0
- LeetCode: Longest Substring Without Repeating Characters
- LeetCode Longest Substring Without Repeating Characters
- LeetCode: Longest Substring Without Repeating Characters
- [Leetcode] Longest Substring Without Repeating Characters
- leetcode 23: Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- LeetCode 3 - Longest Substring Without Repeating Characters
- [LeetCode]Longest Substring Without Repeating Characters
- leetcode Longest Substring Without Repeating Characters
- 【leetcode】 Longest Substring Without Repeating Characters
- LeetCode-Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [leetcode] Longest Substring Without Repeating Characters
- LeetCode - Longest Substring Without Repeating Characters
- LeetCode 3: Longest Substring Without Repeating Characters
- leetcode-3:Longest Substring Without Repeating Characters
- leetcode之Longest Substring Without Repeating Characters
- 监听器 Listener
- synchronized锁不住?
- 【C语言】计算输入整数中每个数字出现的次数
- 51nod 1013 3的幂的和(逆元 or 矩阵快速幂)
- 机器学习基础(一)——人工神经网络与简单的感知器
- LeetCode-- Longest Substring Without Repeating Characters
- WordPress代码编辑页面支持的HTML标签
- 跟我开始从0学Android--从0学java--java简单介绍开始第一个java项目
- Android实现底部半透明弹出框PopUpWindow
- java三种工厂模式:简单工厂、工厂方法、抽象工厂
- 快速排序法(QuickSort)——交换类排序法(java实现)
- 浅谈CSS盒子模型
- Android 点击变色,报错 java.lang.IllegalStateException
- 710总结