File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ // container-with-most-water
2+ // Problem Statement: https://leetcode.com/problems/container-with-most-water
3+
4+ #include < bits/stdc++.h>
5+ using namespace std ;
6+
7+ class Solution {
8+ public:
9+ int maxArea (vector<int >& height) {
10+ if (height.size () < 1 )
11+ return 0 ;
12+
13+ int left = 0 ;
14+ int right = height.size () - 1 ;
15+ int result = 0 ;
16+
17+ while (left < right){
18+ int area = (height[left] < height[right]) ? (height[left] * (right - left)) : (height[right] * (right -left));
19+ result = (area > result) ? area : result;
20+ (height[left] < height[right]) ? left++ : right--;
21+ }
22+
23+ return result;
24+ }
25+ };
26+
Original file line number Diff line number Diff line change 1+ // coin-change
2+ // Problem Statement: https://leetcode.com/problems/coin-change/
3+
4+ class Solution {
5+ public:
6+ int coinChange (vector<int >& coins, int amount){
7+
8+ int MAX = amount + 1 ;
9+ vector<int > cache (amount + 1 , MAX);
10+
11+ cache[0 ] = 0 ;
12+ for (auto coin : coins){
13+ for (int i = coin; i <= amount; i++)
14+ cache[i] = std::min (cache[i], cache[i - coin] + 1 );
15+ }
16+
17+ return cache[amount] == MAX ? -1 : cache[amount];
18+ }
19+ };
20+
You can’t perform that action at this time.
0 commit comments