//// Created by liushuai on 2020年4月3日.//#include "lengthOfLongestSubstring.h"int lengthOfLongestSubstring(string s){map<char, int> char_dict;int start = 0;int max_num = 0;int size = s.size();for(int end=0;end<size;end++){char current_char = s.at(end);if(!char_dict.count(current_char))//不存在字符,更新索引char_dict[current_char]=end;else{start = max(char_dict[current_char]+1,start); // 存在字符,起点为重复字符索引的下一位,防止重复出现的输出的下一位比当前的start小char_dict[current_char] = end;}max_num = std::max(end-start+1,max_num);}return max_num;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。