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, ...
随机推荐
- idea常用设置
Idea删除当前行的快捷键是Ctrl+y,复制当前行的快捷键是Ctrl+d,和eclipse的习惯不一样.虽然可以一键把idea的快捷键映射成eclipse,但是这样做代价太大,如果这样,idea的官 ...
- java学习笔记——IO流部分
IO流常用的有:字符流.字节流.缓冲流.序列化.RandomAccessFile类等,以上列出的都是开发中比较常用的. 1.字节流: 字节流包含:FileInputStream/FileOutputS ...
- Angular.js之Router学习笔记
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 程序点滴001_Python模拟点阵数字
尝试过很多编程语言,写过不少程序(当然,基本上都是些自娱自乐或给自己用的工具类的小玩意儿),逐渐认识到编写程序是一个不断完善.不断优化的过程——编程首先要有一个想法(目标),围绕这个目标形成最基本的功 ...
- 【Zookeeper】源码分析之Leader选举(二)
一.前言 前面学习了Leader选举的总体框架,接着来学习Zookeeper中默认的选举策略,FastLeaderElection. 二.FastLeaderElection源码分析 2.1 类的继承 ...
- smarty实例登陆、显示、分页
1.先建立登陆页面,登陆页面的PHP文件和HTML文件是分开写的. 先建立一个登陆页的PHP文件, <?php include("../init.inc.php");//引入 ...
- maven 项目发布时,无法引用 修改的domain 问题
其实是在bo 的smart-score 里面引用了这个interface 所以还要把 smart -Score 重新发布一下.让这个smart 引用 新的 Player-service 中的i ...
- [Selenium With C#学习笔记] Lesson-06 单选按钮
作者:Surpassme 来源:http://www.jianshu.com/p/08ee1929875f 声明:本文为原创文章,如需转载请在文章页面明显位置给出原文链接,谢谢. 单选按钮通常用在需要 ...
- Java 注解 入门
这几天在学习Spring3.x,发觉现在许多框架都用上了java注解功能,然后自己就对java注解这方面初步学习了一下. 首先,注解跟注释不是一个意思,也根本不是同一个事物. 注释就是我们平常平常中对 ...
- jquery事件与绑定事件
1.首先,我们来看一下经常使用的添加事件的方式: <input type="button" id="btn" value="click me!& ...