题解 | #找到字符串的最长无重复字符子串#
找到字符串的最长无重复字符子串
http://www.nowcoder.com/practice/b56799ebfd684fb394bd315e89324fb4
更简洁的写法
class Solution {
public:
int maxLength(vector<int>& arr) {
//哈希
unordered_map<int,int> mp;
int maxLength =0;
for(int i=0; i<arr.size(); ){
if(mp.find(arr[i]) == mp.end()){
mp.insert(make_pair(arr[i],i));
maxLength = max(maxLength, int(mp.size()));
i++; //注意
}
else{
i = mp[arr[i]]+1;
mp.clear();
}
}
return maxLength;
}};
360集团公司氛围 352人发布