File tree Expand file tree Collapse file tree 1 file changed +22
-10
lines changed Expand file tree Collapse file tree 1 file changed +22
-10
lines changed Original file line number Diff line number Diff line change 1- class Solution {
1+ /*
2+ written by Pankaj Kumar.
3+ country:-INDIA
4+ */
5+ typedef long long ll ;
6+ const ll INF=1e18 ;
7+ const ll mod1=1e9 +7 ;
8+ const ll mod2=998244353 ;
9+ // Add main code here
10+
11+ class Solution
12+ {
213public:
3- int maxProfit (vector<int >& prices) {
4- if (prices.size ()<2 )
14+ int maxProfit (vector<int > &prices)
15+ {
16+ if (prices.size () < 2 )
517 return 0 ;
6- int mini= prices[0 ];
7- int n= prices.size ();
8- int maxo= 0 ;
9- for (int i= 0 ;i<n; i++)
18+ int mini = prices[0 ];
19+ int n = prices.size ();
20+ int maxo = 0 ;
21+ for (int i = 1 ; i < n; i++)
1022 {
11- mini= min (mini, prices[i]) ;
12- int diff=prices[i]-mini ;
13- maxo= max (diff,maxo );
23+ int diff = prices[i] - mini ;
24+ maxo = max (diff, maxo) ;
25+ mini = min (mini, prices[i] );
1426 }
1527 return maxo;
1628 }
You can’t perform that action at this time.
0 commit comments