求珠子的长度最小区间
#include<iostream>usingnamespacestd;#defineMAXN10intcolors[MAXN];//recordthecounterofonecolorintcolorsCounter;voidfind(intarr[],intlen,intcolorsNeed){intbestStartIndex=0;intbestLen=len;intlastStartIndex=0;for(inti=0;i<len;++i){if(!colors[arr[i]])colorsCounter++;colors[arr[i]]++;if(colorsCounter==colorsNeed){intj=lastStartIndex;while(colors[arr[j]]>1){colors[arr[j]]--;++j;}if(i-j+1<bestLen){bestStartIndex=j;bestLen=i-j+1;if(bestLen==colorsNeed)break;}lastStartIndex=j;}}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。