请教一下各位,我有一个数组
{0,1,2,3,4,5,6,7,8,9,0,1,5,6,9.....}
很多的数据,我要找出某一个数,比如2的最大间隔,用什么方法最快

解决方案 »

  1.   

    假设list是储存的数组:function max(list;num:integer): Integer;
    var
      i,j, pre: integer;
    begin
      j:=0;
      pre:=-1;
      for i:= 1 to list.len do
        if list[i] = num then
          if (pre<>-1) and ((i-pre)>j) then
            j := i-pre;
      result := j;
    end;
      

  2.   

    2楼的应该有点错误吧。
    for i:= Low(list) to High(list) do
        if list[i] = num then
        begin
          if(pre = -1)  then
            pre := i
          else if(i-pre)>j  then
           j := i-pre;
        end;