int getmaxstr(string& str) {     int max = 0,curr = 0;     if(str==nullptr) return nullptr; int position = new int [26]; for(int i=0;i<26;i++) position[i] = -1; for(int j=0;j<str.length();j++) { pre = positon[str[j]-'a']; if(pre<0|| i-pre>curr) curr++; else{ if(max<curr){ max = curr; } curr = i - pre; } position[str[j]-'a'] = i; } if(curr>max) max = curr; delete[] position; return max; }//C++的,而且返回的是最长串的的长度,要是返回这个字符串的话,可以回溯一下,有了max,有position,记录下最长那个的结尾就ok了。
点赞 评论

相关推荐

点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务