字符串最长无重复字串[c++]
找到字符串的最长无重复字符子串
http://www.nowcoder.com/questionTerminal/b56799ebfd684fb394bd315e89324fb4
class Solution {
public:
int maxLength(vector<int>& arr) { // write code here map<int,int> mpTemp; int maxLength = 0; int start=0; for(int j=0;j<arr.size();j++){ if(mpTemp.count(arr[j])==0){ mpTemp[arr[j]]=j; if(j==arr.size()-1)//若数组最后一位元素之前没出现过 maxLength =std::max(j-start+1,maxLength); } else{ maxLength =std::max(j-start,maxLength); start=std::max(mpTemp[arr[j]]+1, start); //这一步想了好久 mpTemp[arr[j]]=j; } } return maxLength; }
};