C++ DP
See my latest update in repo LeetCode\n## Solution 1. Brute force\n\ncpp\n// OJ: https://leetcode.com/problems/maximum-difference-between-increasing-elements/\n
See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n## Solution 1. Brute force\n\n```cpp\n// OJ: https://leetcode.com/problems/maximum-difference-between-increasing-elements/\n// Author: github.com/lzl124631x\n// Time: O(N^2)\n// Space: O(1)\nclass Solution {\npublic:\n    int maximumDifference(vector<int>& A) {\n        int N = A.size(), ans = -1;\n        for (int i = 0; i < N; ++i) {\n            for (int j = i + 1; j < N; ++j) {\n                if (A[i] < A[j]) ans = max(ans, A[j] - A[i]);\n            }\n        }\n        return ans;\n    }\n};\n```\n\n## Solution 2. DP\n\n```cpp\n// OJ: https://leetcode.com/problems/maximum-difference-between-increasing-elements/\n// Author: github.com/lzl124631x\n// Time: O(N)\n// Space: O(1)\nclass Solution {\npublic:\n    int maximumDifference(vector<int>& A) {\n        int N = A.size(), ans = -1, mn = INT_MAX;\n        for (int i = 0; i < N; ++i) {\n            mn = min(mn, A[i]);\n            if (A[i] > mn) ans = max(ans, A[i] - mn);\n        }\n        return ans;\n    }\n};\n```
[]