Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit82f04fd

Browse files
11.Container with most water.cpp Leetcode solution file added (fishercoder1534#114)
* 11.Container with most water.cpp solution file added* _322.cpp added (Coin change DP solution)Co-authored-by: anushkaGurjar1999 <anushkauj@gmail.com>
1 parent85e2e08 commit82f04fd

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

‎cpp/_11.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// container-with-most-water
2+
// Problem Statement: https://leetcode.com/problems/container-with-most-water
3+
4+
#include<bits/stdc++.h>
5+
usingnamespacestd;
6+
7+
classSolution {
8+
public:
9+
intmaxArea(vector<int>& height) {
10+
if(height.size() <1)
11+
return0;
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+

‎cpp/_322.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// coin-change
2+
// Problem Statement: https://leetcode.com/problems/coin-change/
3+
4+
classSolution{
5+
public:
6+
intcoinChange(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+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp