✅C++ || EASY DP (very short code)
Code\n\nclass Solution {\npublic:\n    int maxProfit(vector<int>& p) {\n        int mn=p[0];\n        int ans=0;\n        for(int i=1;i<p.size();i++){\n        
# Code\n```\nclass Solution {\npublic:\n    int maxProfit(vector<int>& p) {\n        int mn=p[0];\n        int ans=0;\n        for(int i=1;i<p.size();i++){\n          ans=max(ans,p[i]-mn);\n          mn=min(mn,p[i]);\n        }\n        return ans;\n    }\n};\n```\n![upvote (2).jpg](https://assets.leetcode.com/users/images/e73ffd6a-40e6-4d94-948a-a970bd55b51a_1681547184.833364.jpeg)\n
['C++']