寻找最长子串

简介:
if (str == null || str == string.Empty)
{
 printf"Null or empty!!!!\n";
}
int max = 1;
int count = 1;
int number = 0;
char[] theChar=new char[str.Length];
theChar[number] = str[0];
for (int i = 1; i < str.Length; i++)
{
if (str[i] == str[i - 1])
{
count++;
if(max < count)
{
max=count;
number = 0;
theChar[number]=str[i];
}
else if (max == count)
{
number++;
theChar[number] = str[i];
}
}
if (str[i] != str[i - 1])
{
count = 1;
}
}
string[] strArray = new string[number+1];
for (int i = 0; i <= number; i++)
{
strArray[i] = new string(theChar[i], max);
}
return strArray;
}
目录
相关文章
|
3月前
|
Java C++ Python
leetcode-242:有效的字母异位词
leetcode-242:有效的字母异位词
24 0
|
7月前
|
索引
LeetCode3-无重复字符的最长子串
LeetCode3-无重复字符的最长子串
|
3天前
【力扣】242. 有效的字母异位词
【力扣】242. 有效的字母异位词
|
2月前
|
存储 算法 Go
LeetCode 第三题: 无重复字符的最长子串
  给定一个字符串,请你找出其中不含有重复字符的最长子串的长度。
|
3月前
leetcode:3. 无重复字符的最长子串
leetcode:3. 无重复字符的最长子串
16 0
|
3月前
leetcode-3:无重复字符的最长子串
leetcode-3:无重复字符的最长子串
20 0
|
9月前
【LeetCode 训练营 3,5】无重复字符的最长子串+最长回文子串
【LeetCode 训练营 3,5】无重复字符的最长子串+最长回文子串
51 1
|
4月前
LeetCode 242. 有效的字母异位词
LeetCode 242. 有效的字母异位词
18 0
|
10月前
|
存储 前端开发 C++
力扣3-无重复字符的最长子串
力扣3-无重复字符的最长子串
51 0
|
10月前
|
算法 Java Python
leetcode:3.无重复字符的最长子串
首先最容易想到的就是暴力解法,列出所有的子字符串,然后逐个检查是否包含重复的字符就行了,这样思路很简单,但是效率太慢,不推荐。
36 0