Memory Limit Exceeded


  • 0
    K

    class Solution {
    public:
    int maxProduct(int A[], int n) {

    	int** B = new int*[n];
    	for (int i=0;i<n;i++)
    	{
    		B[i] = new int[n];
    	}
    
    	for(int i=0;i<n;i++){
    		B[i][i]=A[i];
    		for(int j=i+1;j<n;j++){
    			B[i][j]=B[i][j-1]*A[j];
    		}
    	}
    
    	int max=A[0];
    	for(int i=0;i<n;i++){
    		for(int j=i;j<n;j++){
    			cout<<B[i][j]<<" ";
    			if(B[i][j]>max)
    				max=B[i][j];
    			else continue;
    		}
    		cout<<endl;
    	}
    
    	for (int i=0;i<n;i++)
    	{
    		delete[] B[i];
    	}
    	delete[] B;                          
    	return max;
    }
    

    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.