mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 3_puck.cpp
This commit is contained in:
parent
e999d09913
commit
ada93fa0db
35
LeetCode-CN/3_puck.cpp
Normal file
35
LeetCode-CN/3_puck.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <set>
|
||||
using std::string;
|
||||
class Solution
|
||||
{
|
||||
public:
|
||||
int lengthOfLongestSubstring(string s)
|
||||
{
|
||||
int result{};
|
||||
for (std::size_t i{}; i < s.size(); ++i)
|
||||
{
|
||||
string tmp_str = s.substr(i);
|
||||
int cu_length{};
|
||||
std::set<char> set_except;
|
||||
|
||||
for (auto ch : tmp_str)
|
||||
{
|
||||
if (set_except.end() == set_except.find(ch))
|
||||
{
|
||||
set_except.insert(ch);
|
||||
++cu_length;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
result = std::max(result, cu_length);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user