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的更多相关文章

  1. [LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串

    Given a string, find the length of the longest substring without repeating characters. Example 1: In ...

  2. [LeetCode] Longest Substring Without Repeating Characters 最长无重复字符的子串 C++实现java实现

    最长无重复字符的子串 Given a string, find the length of the longest substring without repeating characters. Ex ...

  3. 3 Longest Substring Without Repeating Characters(最长不重复连续子串Medium)

    题目意思:求字符串中,最长不重复连续子串 思路:使用hashmap,发现unordered_map会比map快,设置一个起始位置,计算长度时,去减起始位置的值 eg:a,b,c,d,e,c,b,a,e ...

  4. [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  5. 【LeetCode每天一题】Longest Substring Without Repeating Characters(最长无重复的字串)

    Given a string, find the length of the longest substring without repeating characters. Example 1:    ...

  6. [LeetCode] Longest Substring Without Repeating Characters最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  7. [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. Example 1: In ...

  8. 【LeetCode】3.Longest Substring Without Repeating Characters 最长无重复子串

    题目: Given a string, find the length of the longest substring without repeating characters. Examples: ...

  9. leetcode 3 Longest Substring Without Repeating Characters最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. For example, ...

随机推荐

  1. Sass与Compass——回顾

    compass 是sass的一个工具库 compass在sass 的基础上封装了一系列有用的模块,用来补充和丰富sass的工能, 安装: compass是用 ruby语言开发的,所以安装它之前必须安装 ...

  2. java 重写的学习

    本文全文转自:http://www.cnblogs.com/happyframework/p/3332243.html,非常感谢 Java中的重写规则比较灵活,具体如下: 除了 private 修饰之 ...

  3. 初探 discuz

    测试: vim /etc/hosts       ##ip地址转换 修改windows 的配置文件,写字板打开 vim /usr/local/apache/conf/httpd.conf vim /u ...

  4. Python求解登楼梯问题(京东2016笔试题)

    问题:假设一段楼梯共15个台阶,小明一步最多能上3个台阶,那么小明上这段楼梯一共有多少种方法? 解析:从第15个台阶上往回看,有3种方法可以上来(从第14个台阶上一步迈1个台阶上来,从第13个台阶上一 ...

  5. devexpress表格控件gridcontrol实现纵向标头

    1.devexpress控件gridcontrol中的标头默认是横向的,如果要实现纵向标头应该怎么做呢.通过官网的资料整理了一个简单的案例,给大家分享一下.运行效果图如下: 2.数据绑定代码如下: D ...

  6. C# 6 与 .NET Core 1.0 高级编程 - 41 ASP.NET MVC(上)

    译文,个人原创,转载请注明出处(C# 6 与 .NET Core 1.0 高级编程 - 41 ASP.NET MVC(上)),不对的地方欢迎指出与交流. 章节出自<Professional C# ...

  7. 使用StyleCop.Analyzers进行代码审查

    为什么要进行代码审核? 提早发现代码中的BUG,避免将BUG带到生产环境 极大的提高软件质量,以及可维护性 统一代码规范.提高可读性,减少新加入成员的熟悉时间 加速个人和团队的成长,知识和经验的积累 ...

  8. p1154 地平线

    题目描述 Farmer John的牛们认为,太阳升起的那一刻是一天中最美好的,在那时她们可以看到远方城市模糊的轮廓.显然,这些轮廓其实是城市里建筑物模糊的影子. 建筑物的影子实在太模糊了,牛们只好把它 ...

  9. SQL Server 2008R2 企业版 百度云下载地址

    SQL Server 2008R2 (百度云下载地址:链接: http://pan.baidu.com/s/1mi34II8 密码: yc1w)   ASP.NET MVC4.0+ WebAPI+Ea ...

  10. 谈JavaScript的继承

    最近在忙前端的工作,因为之前做.net和php的开发比较多,前端开发喜欢把库拿来就用,几次事实证明,不懂原理,连改代码也改不好,所以还是下定决心研究下JavaScript的几个技术难点. 0x1.Ja ...