Concise solution O(n)
1 to record the changes from yesterday \n2 find the max sum of consecutive subarray(if sum<0 sum==0)\n\n\n    class Solution {\n    public:\n        int maxProf
1 to record the changes from yesterday \n2 find the max sum of consecutive subarray(if sum<0 sum==0)\n\n\n    class Solution {\n    public:\n        int maxProfit(vector<int> &prices) {\n            \n            int max=0;\n            int current=0;\n            for(int i=1;i<prices.size();i++){\n                current+=prices[i]-prices[i-1];\n                if(current<0) current=0;\n                else if(current>max) max=current;\n            }\n        return max;\n    }  \n    };
[]