子数组的最大乘积C++实现0(n)

void function( int a[],int N)
{
int * s = new int[N+1];
int * t = new int[N+1];
int * p = new int[N];

s[0]=t[N]=1;

for(int i =1; i < N+1 ; i++ )
{
s[i]=s[i-1]*a[i-1];

}
for( int i =N-1; i>=0; --i)
{
t[i] = a[i]*t[i+1];
}

p[0]=t[1];

for( int i = 1; i < N ; i++)
{
p[i]=s[i-1]*t[i+1];
}

int max=0;
for( int i=0;i< N;i++)
{
if(p[i]> max)
{
max=p[i];
}
}
cout<<"Max="< delete []s;
delete []p;
delete []t;
}

转载于:https://www.cnblogs.com/litana/archive/2013/05/15/3079149.html

你可能感兴趣的:(子数组的最大乘积C++实现0(n))