3. Longest Substring Without Repeating Characters - 最长无重复字符子串-Medium
Examples:
Description:
Given a string, find the length of the longest substring without repeating characters.
Example:
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.
思路分析:
1.第一想法:从第一个字符起,逐个计算出最长字串长度,然后到遍历到最后一个字符,得到最大值;
2.其中逐个计算最长字串部分,跟之前的1.Tow Num 问题几乎一样;
3.于是可以开始编码了........
一般测试可以通过,但是,当输入字符串特别长的时候会超时,提交失败...看来的重新想解决的方法了
C#代码:
public class Solution {
public int LengthOfLongestSubstring(string s) {
int max = ;
char[] sArr = s.ToCharArray();
for(int i=;i<s.Length;i++){
int tempMax=;
int j =i+;
Hashtable ht = new Hashtable();
ht.Add(i,sArr[i]);
while(j<s.Length&&(!ht.ContainsValue(sArr[j]))){
ht.Add(j,sArr[j]);
j++;
tempMax++;
}
if(max<tempMax){
max = tempMax;
}
}
return max;
}
}
3. Longest Substring Without Repeating Characters - 最长无重复字符子串-Medium的更多相关文章
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串 C++实现java实现
最长无重复字符的子串 Given a string, find the length of the longest substring without repeating characters. Ex ...
- 3 Longest Substring Without Repeating Characters(最长不重复连续子串Medium)
题目意思:求字符串中,最长不重复连续子串 思路:使用hashmap,发现unordered_map会比map快,设置一个起始位置,计算长度时,去减起始位置的值 eg:a,b,c,d,e,c,b,a,e ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- 【LeetCode每天一题】Longest Substring Without Repeating Characters(最长无重复的字串)
Given a string, find the length of the longest substring without repeating characters. Example 1: ...
- [LeetCode] Longest Substring Without Repeating Characters最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- [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. Examples: ...
- leetcode 3 Longest Substring Without Repeating Characters最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
随机推荐
- 基于服务的SOA架构_后续篇
今天是元宵节,首先祝各位广大博友在接下来的光阴中技术更上一层,事事如意! 昨天简单介绍了一下本人在近期开发过的一个电商购物平台的架构流程和一些技术说明:今天将详细总结一下在项目中用到的各个架构技术的环 ...
- SQL Server-聚焦存储过程性能优化、数据压缩和页压缩提高IO性能(一)
前言 关于SQL Server基础系列尚未结束,还剩下最后一点内容未写,后面会继续.有园友询问我什么时候开始写SQL Server性能系列,估计还得等一段时间,最近工作也比较忙,但是会陆陆续续的更新S ...
- Code forces 719A Vitya in the Countryside
A. Vitya in the Countryside time limit per test:1 second memory limit per test:256 megabytes input:s ...
- js 将php生成的time()类型时间戳转化成具体date格式的日期
需求: 将首页显示的int类型的时间转化为date类型的时间格式: QuestionModel获取到question列表数据时,包括question['pub_time'],在显示 ...
- C语言中的函数、数组与指针
1.函数:当程序很小的时候,我们可以使用一个main函数就能搞定,但当程序变大的时候,就超出了人的大脑承受范围,逻辑不清了,这时候就需要把一个大程序分成许多小的模块来组织,于是就出现了函数概念: 函 ...
- collectionView布局
关于 collectionView的layout布局方法: 设置cell的间距,行间距,组与组之间的间距,都是在layout里面来设置. 包括,滚动方向. -(void)prepareLayout [ ...
- Troubleshooting OpenStack 瘫痪 - 每天5分钟玩转 OpenStack(160)
这是 OpenStack 实施经验分享系列的第 10 篇.是软件就会有 bug,OpenStack 也不例外,只要用它就一定会遇到故障.Troubleshooting(故障排除)是运维 OpenSta ...
- Spring RESTful + Redis全注解实现恶意登录保护机制
好久没更博了... 最近看了个真正全注解实现的 SpringMVC 博客,感觉很不错,终于可以彻底丢弃 web.xml 了.其实这玩意也是老东西了,丢弃 web.xml,是基于 5.6年前发布的 Se ...
- 《你不知道的JavaScript》整理(五)——值与原生函数
一.值 1)数字 JavaScript只有一种数值类型:number(数字),包括"整数"和带小数的十进制数. //数字的语法 a.toExponential(); // &quo ...
- Mac上关于shell使用Python3和C++11声明
1.使用Python3 Mac上的shell上自带的Python版本是2.7,当需要使用Python3时,下载安装好Python时,在shell上敲入Python发现却还是显示Python2.7,这是 ...