I tried to find subarray in an array. It works for only one subarray but I want that if there are more than one subarray, it returns last one's index. For example, for [3,4,1,2,0,1,2,5,6] and [1,2] should return 5.
public int FindArray(int[] array, int[] subArray)
{
//throw new NotImplementedException();
int y=0;
int index=0;
bool find= false;
for(int x=0;x< array.Length && y< subArray.Length;)
{
if(array[x]!= subArray[y])
{
if(find==true)
{
y=0;
index=x;
}
else
{
x++;
y=0;
index=x;
}
}
else
{
find=true;
x++;
y++;
}
}
if(y==subArray.Length)
return index;
else
return -1;
}
}