Create 3_puck.cpp

This commit is contained in:
Kirigaya Kazuto 2018-06-20 23:11:46 +08:00 committed by GitHub
parent e999d09913
commit ada93fa0db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

35
LeetCode-CN/3_puck.cpp Normal file
View 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;
}
};