/*
3.给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。
*/
public:
int lengthOfLongestSubstring(std::string s) {
int Longest = 0;
int current_index = 0;
while(current_index != s.length())
{
int substrLenth = 0;
std::set<char> substr;
for (int i = current_index; i < s.length(); ++i)
{
substr.insert(s[i]);
if (substrLenth == substr.size() || i == s.length() - 1)
{
if (Longest < substr.size())
{
Longest = substr.size();
}
break;
}
else
{
++substrLenth;
}
}
++current_index;
}
return Longest;
}
LeetCode-3-给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度
最新推荐文章于 2022-12-23 20:45:15 发布