121. Best Time to Buy and Sell Stock
The only difference from 121. Best Time to Buy and Sell Stock is that we need to return -1 if no profit can be made.\n\nC++\ncpp\nint maximumDifference(vector<i
The only difference from [121. Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) is that we need to return `-1` if no profit can be made.\n\n**C++**\n```cpp\nint maximumDifference(vector<int>& nums) {\n    int mn = nums[0], res = -1;\n    for (int i = 1; i < nums.size(); ++i) {\n        res = max(res, nums[i] - mn);\n        mn = min(mn, nums[i]);\n    }\n    return res == 0 ? -1 : res;\n}\n```
[]