400 028 6601

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

求珠子的长度最小区间

有一串首尾相连的珠子,共有m个,每一个珠子有一种颜色,并且颜色的总数不超过n(n<=10),求连续的珠子的颜色总数为n时,长度最小的区间。

#include 
using namespace std;
#define MAXN 10
int colors[MAXN];//record the counter of one color
int colorsCounter;
void find(int arr[],int len, int colorsNeed)
{
    int bestStartIndex = 0;
    int bestLen = len;
    int lastStartIndex = 0;
    
    for ( int i=0; i1) {
                colors[arr[j]]--;
                ++j;
            }
            if (i-j+1            
            
                    
新闻名称:求珠子的长度最小区间
分享链接:http://mbwzsj.com/article/gdsgso.html

其他资讯

让你的专属顾问为你服务