历经41天,面了华为OD拿到了offer,难点在于拒绝这个OFFER
/*
* 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
如:
输入: s = "abcabcbb"
输出: 3
解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。
*/
#include <iostream>
#include <string>
using namespace std;
int func(string str) {
if (0 == str.size()) return 0;
string res, ret;
char hash[300];
for (int i = 0; i < 300; ++i)
hash[i] = 0;
hash[str[0]] = 1, res += str[0], ret += str[0];
for (int i = 1; i < str.size(); ++i) {
for (int j = i + 1; j < str.size(); ++j) {
if (0 == hash[str[j]]) {
hash[str[j]] = 1;
res += str[j];
if (res.size() > ret.size())
ret = res;
}
else {
if (res.size() > ret.size())
ret = res;
res.clear();
memset(hash, 0 ,sizeof(hash));
res += str[j], hash[str[j]] = 1;
break;
}
}
}
return ret.size();
}
int main(){
string s = "aabbcc";
cout << func(s) << endl;
return 0;
}