diff --git a/cpp/_11.cpp b/cpp/_11.cpp new file mode 100644 index 0000000000..0452f628fb --- /dev/null +++ b/cpp/_11.cpp @@ -0,0 +1,26 @@ +// container-with-most-water +// Problem Statement: https://leetcode.com/problems/container-with-most-water + +#include +using namespace std; + +class Solution { +public: + int maxArea(vector& height) { + if(height.size() < 1) + return 0; + + int left = 0; + int right = height.size() - 1; + int result = 0; + + while(left < right){ + int area = (height[left] < height[right]) ? (height[left] * (right - left)) : (height[right] * (right -left)); + result = (area > result) ? area : result; + (height[left] < height[right]) ? left++ : right--; + } + + return result; + } +}; + diff --git a/cpp/_322.cpp b/cpp/_322.cpp new file mode 100644 index 0000000000..852a6b5a20 --- /dev/null +++ b/cpp/_322.cpp @@ -0,0 +1,20 @@ +// coin-change +// Problem Statement: https://leetcode.com/problems/coin-change/ + +class Solution{ +public: + int coinChange(vector& coins, int amount){ + + int MAX = amount + 1; + vector cache(amount + 1, MAX); + + cache[0] = 0; + for(auto coin : coins){ + for(int i = coin; i <= amount; i++) + cache[i] = std::min(cache[i], cache[i - coin] + 1); + } + + return cache[amount] == MAX ? -1 : cache[amount]; + } +}; + pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy