Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double[] prices = ... // your prices
- int buy = 0; // index of 'buy' price
- int sell = 0; // index 'sell' price
- for(int i=0;i<prices.length;i++){
- if(prices[i]-prices[buy] > prices[sell] - prices[buy])
- sell = i;
- else if( prices[i] < prices[buy] ){
- buy = i;
- sell = i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement