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;
}
}

最新文章

  1. Shell_2 语句
  2. 《zw版&#183;Halcon-delphi系列原创教程》 Halcon分类函数008,matrix,矩阵函数
  3. 2016年 Delphi Roadmap
  4. wpf 旋转效果
  5. 迪杰斯特拉(Java)
  6. Java从入门到精通——数据库篇Oracle 11g服务详解
  7. 在.net中用Connection对象数据源的架构信息
  8. yii2配置表前缀
  9. Android 在广播接收器中弹出对话框
  10. A simple Gaussian elimination problem.
  11. python笔记-正则表达式常用函数
  12. 学习Struts2经验总结
  13. live2d添加网页看板娘
  14. Apache Ignite 学习笔记(四): Ignite缓存冗余备份策略
  15. 解题:SDOI 2011 消耗战
  16. Java Base64加密解密
  17. 网页不能显示PNG验证码的解决办法
  18. 解析UIControl
  19. Ubuntu Linux 14.04 LTS 上安装php7+mysql+nginx
  20. SQL优化之limit 1

热门文章

  1. Python学习--17 进程和线程
  2. linux系统盘使用率达到100%的问题查找和解决方法
  3. 基于Selenium2+Java的UI自动化(6)-操作Alert、confirm、prompt弹出框
  4. 关于AR,你想要的全在这儿了
  5. 使用Python实现子区域数据分类统计
  6. WDCP下安装PHPWind
  7. Java编程规范(二)
  8. Java回调机制解读
  9. show_you_my_codes 001
  10. 前端学PHP之日期与时间