首页 > 编程语言 > 详细

算法题---最长不含重复字符的子字符串

时间:2020-11-02 10:14:26      阅读:18      评论:0      收藏:0      [点我收藏+]
// 遍历字符串,使用set集合记录走过的字符

//
字符串不含重复字符的最长子串 int longChirldStr(string s){ set<char> tmpSet; int ret = 0; int right = 0; int size = s.length(); if(size ==0 || size == 1){ return size; } for(int i=0; i<size; i++){ while(right < size && !tmpSet.count(s[right])){ tmpSet.insert(s[right]); right++; } ret = max(ret, right-i); tmpSet.erase(s[i]); } return ret; }

 

算法题---最长不含重复字符的子字符串

原文:https://www.cnblogs.com/syw-home/p/13912855.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!