From 9418c2185e3a7b08f67a6ada58ce91d3de6d7eb0 Mon Sep 17 00:00:00 2001 From: anushkaGurjar1999 Date: Fri, 16 Oct 2020 13:50:28 +0530 Subject: [PATCH 1/2] 11.Container with most water.cpp solution file added --- cpp/_11.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 cpp/_11.cpp 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; + } +}; + From 821cd6f5eb395c8d241af0f631ffaf503e7831eb Mon Sep 17 00:00:00 2001 From: anushkaGurjar1999 Date: Fri, 16 Oct 2020 13:59:05 +0530 Subject: [PATCH 2/2] _322.cpp added (Coin change DP solution) --- cpp/_322.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 cpp/_322.cpp 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