C++, o(n) solution, kind of greedy.
int maxProfit(vector<int>& prices) {\n        int size=prices.size();\n        int profit=0;\n        int max=0;\n        for(int i=1;i<size;++i){\n            
    int maxProfit(vector<int>& prices) {\n        int size=prices.size();\n        int profit=0;\n        int max=0;\n        for(int i=1;i<size;++i){\n            profit+=(prices[i]-prices[i-1]);\n            if(profit>max)\n               max=profit;\n            if(profit<0)\n               profit=0;\n        }\n        return max;\n    }
[]