public int maxProfit(int[] prices) {
       int min = 0;
       int diff = 0;
       for(int i=0;i<prices.length;i++)
       {
           if(prices[i] < prices[min])
               min = i;
           int local_diff = prices[i] - prices[min];
           if(local_diff > diff)
               diff = local_diff;
       }
       return diff;
    }