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, ...
随机推荐
- java学习阶段三:运算符和结构学习
import java.util.Scanner;/* * JAVA中运算符的学习: * 算术运算符:+.-.*./ 和 %,两个整数相除,结果还是整数. * 赋值运算符:=.+=.-=.*=./=. ...
- $.each()遍历json数据
var json = [ {"id":"1","tagName":"apple"}, {"id":& ...
- JavaScript中的this关键字的用法和注意点
JavaScript中的this关键字的用法和注意点 一.this关键字的用法 this一般用于指向对象(绑定对象); 01.在普通函数调用中,其内部的this指向全局对象(window); func ...
- devexpress表格控件gridcontrol图片列,按钮列,时间列等特殊列的实现
1.项目中经常会在表格中插入按钮列,图片列,表格列一些非文本的特殊列.如何在devexpress表格控件gridcontrol中实现呢?以下列举一个实现添加图片列,按钮列,时间列,按钮列,开关列的示例 ...
- 前端跨域方案-跨域请求代理(node服务)
前端开发人员在本地搭建node服务,调用接口首先走本地服务,然后转发到api站点,node服务代码如下: var express = require('express'), request = req ...
- 百度编辑器 UEditor第一次加载后台数据失败
给编辑器赋值的代码: var ue = UE.getEditor('content'); ue.ready(function (){ ue.setContent(data.data.cont ...
- Sublime Text 3 (Build 3126) 最新注册码
Sublime Text 作为程序员开发神器,听说最新版更新了 并且增加了不少新特性.马上到官网下载了最新版 Sublime Text 3 3126 使用了下,反应速度比以前的确更快了.随手找了几个S ...
- lxc.conf解析&lxc容器能力
lxd启动容器实际是生成lxc.conf.剩下的就是LXC对容器进行控制了.所以可认为lxc.conf就是lxd和lxc之间主要的接口.lxc.conf详细属性参考: http://manpages. ...
- UCSC genome browser 个人track 安装
处理基因组数据,很多时候我们会觉得直接看序列文件不够直观,如果绘图的话,把n多G把数据用画图出来不仅费劲,就算操作也不方便.因此我们可以用UCSC开发出的genome browser,可以直接把数据信 ...
- perl 正则表达式之匹配
一.用m//进行匹配 上篇用双斜线的写法表示模式,事实上是m//的简写,所谓简写,就是当用双斜线作为定界符的时候,可有省略开头的m. 不使用简写的时候,可以使用任何定界符表示模式,m().m<& ...