Time limit exceeding help me fix it

//https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
int maxProfit(int* prices, int pricesSize){
int sum=0,t=0;
for(int i=0;i<pricesSize;i++)
for(int j=i+1;j<pricesSize;j++)
{
if((prices[j]-prices[i])>0)
sum=prices[j]-prices[i];
if(sum>t)
t=sum;
}
if(t==0||t<0)
return 0;
return t;
}

Check the following O(pricesSize) dynamic programming solution.

Accepted