void StockProcess(const vector<int>& stocks,
int* buyday,
int* sellday)
{
int min_index = 0;
*buyday = 0;
*sellday = 0;
for (int i = 1; i < stocks.size(); ++i) {
if (stocks[i] < stocks[min_index]) {
min_index = i;
} else if ( (stocks[i] - stocks[min_index]) > (stocks[*sellday] - stocks[*buyday])) {
*buyday = min_index;
*sellday = i;
}
}
}Wednesday, 21 March 2012
Puzzle : Find the best time to buy and sell a stock from a list of values in an array
Subscribe to:
Post Comments (Atom)
AWS Data Pipeline Services
https://www.youtube.com/watch?v=tykcCf-Zz1M
-
Here is the simple code for finding the maximum of a BST: /* Tree Maximum */ Tree* maxTree(struct Tree *node) { while(node->right) nod...
-
#include<iostream.h> #include<conio.h> #include<stdlib.h> class Node{ public: Node* left; Node* right; in...
-
#include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <stdlib.h> i...
No comments:
Post a Comment