File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution {
2+ public:
3+ int maxProfit(vector<int>& prices) {
4+
5+ int n=prices.size();
6+ int max_profit=0;
7+ int profit=0;
8+ int min=INT_MAX;
9+
10+
11+ for(int i=0;i<n;i++)
12+ {
13+ //for finding the minimum value
14+
15+ if(min>prices[i])
16+ {
17+ min=prices[i];
18+
19+ }
20+ //check profit
21+ profit=prices[i]-min;
22+
23+ //check if profit is greater then maximum profit or not
24+ if(max_profit<profit)
25+ {
26+ max_profit=profit;
27+ }
28+ }
29+ return max_profit;
30+ }
31+ };
Original file line number Diff line number Diff line change 1+ class Solution
2+ {
3+ public:
4+ vector<int> twoSum(vector<int>& nums, int target)
5+ {
6+ vector<int> ans;
7+ int n=nums.size();
8+
9+ for(int i=0;i<n-1;i++)
10+ {
11+
12+ for(int j=i+1;j<n;j++)
13+ {
14+ if(target==nums[i]+nums[j])
15+
16+ {
17+
18+ ans.push_back(i);
19+ ans.push_back(j);
20+
21+ }
22+ }
23+
24+ }
25+
26+ return ans;
27+
28+ }
29+
30+
31+ };
You can’t perform that action at this time.
0 commit comments