class Solution {
public:
int maxProfit(vector<int>& prices) {
int pof=INT_MAX;
int ans=0;
for(int i=0;i<prices.size();i++)
{
if(prices[i]<pof)
{
pof=prices[i];
}else if(prices[i]-pof>ans)
{
ans=prices[i]-pof;
}
}
return ans;
}
};
Code Example |
---|
Cpp :: c++ write to csv file append |
Cpp :: vector iterating in c++ |
Cpp :: c++ pointers and functions |
Cpp :: resize string c++ |
Cpp :: c++ get last element in vector |
Cpp :: cpp template |
Cpp :: c++ client service ros |
Cpp :: long pi in c++ |
Cpp :: grep xargs sed |
Cpp :: is anagram c++ |
Cpp :: vector size |
Cpp :: abstraction in cpp |
Cpp :: oop in cpp |
Cpp :: int max in c++ |
Cpp :: find text in string c++ true false |
Cpp :: pointers and arrays in c++ |
Cpp :: c++ class |
Cpp :: create a vector of size n in c++ |
Cpp :: glfw error: the glfw library is not initialized |
Cpp :: google test assert throw |
Cpp :: cout stack in c++ |
Cpp :: has substr c++ |
Cpp :: c++ - |
Cpp :: string c++ |
Cpp :: c++ linked list |
Cpp :: stack data structure c++ |
Cpp :: c++ unordered_map initialize new value |
Cpp :: c++ custom printf |
Cpp :: c++ overloading by ref-qualifiers |
Cpp :: largest subarray with zero sum |