#include <iostream> #include <vector> #include <stack> using namespace std; //簡單的DP演算法 class Solution { public: int maxProfit(vector<int> &prices) { // Start typing your C/C++ solution below // DO NOT write int main() function int size = prices.size(); if (!size) return 0; vector<int> min(size); min[0] = prices[0]; for (int i = 1; i < size; i++){ min[i] = std::min(min[i-1], prices[i]); } int max = 0; for (int i = 1; i < size; i++){ max = std::max(max, prices[i] - min[i]); } return max; } }; int main() { return 0; }
EOF