From 3066465cef8119dc2dfeb822f8e30b5daa99d20c Mon Sep 17 00:00:00 2001 From: geeky-hypertext629 <107639960+geeky-hypertext629@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:11:50 +0530 Subject: [PATCH] Added Leetcode C++ Trapping Rain Water Problem --- README.md | 1 + codes/cpp/TrappingRainWater.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 codes/cpp/TrappingRainWater.cpp diff --git a/README.md b/README.md index 953596d..4417740 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ | Serialize and Deserialize BST | [Leetcode](https://leetcode.com/problems/serialize-and-deserialize-bst/) | [YouTube](https://www.youtube.com/watch?v=-YbXySKJsX8&t=613s)|[C++](https://github.com/ShreemoyeeMukherjee/ProjectAlgorithms/blob/ShreemoyeeMukherjee-patch-2/Serialize%20and%20Deserialize%20BST) | | Construct Binary Search Tree from Preorder Traversal | [LeetCode](https://leetcode.com/problems/construct-binary-search-tree-from-preorder-traversal/) | [YouTube](https://www.youtube.com/watch?v=UmJT3j26t1I&t=692s) | [C++](https://github.com/ShreemoyeeMukherjee/ProjectAlgorithms/blob/ShreemoyeeMukherjee-patch-2/codes/cpp/Construct%20Binary%20Search%20Tree%20from%20Preorder%20Traversal) | | First Unique Character in a String | [LeetCode](https://leetcode.com/problems/first-unique-character-in-a-string/) | [YouTube](https://www.youtube.com/watch?v=St47WCbQa9M) | [Java](./codes/java/FirstUniqueCharacterinaString.java) | +| Trapping Rain Water | [LeetCode](https://leetcode.com/problems/trapping-rain-water/description/) | [YouTube](https://www.youtube.com/watch?v=m18Hntz4go8) | [C++](./codes/cpp/TrappingRainWater.cpp) | | Interleaving Strings | [LeetCode](https://leetcode.com/problems/interleaving-string/) | [YouTube](https://www.youtube.com/watch?v=3Rw3p9LrgvE) | [Python](./codes/python/InterleavingStringsProg.py) | | Group Anagrams | [LeetCode](https://leetcode.com/problems/group-anagrams/) | [YouTube](https://www.youtube.com/watch?v=ptgykfAEax8) | [Java](./codes/java/GroupAnagramsProg.java) | | Binary Tree Right Side View | [LeetCode](https://leetcode.com/problems/binary-tree-right-side-view/) | [YouTube](https://www.youtube.com/watch?v=jCqIr_tBLKs&t=390s) | [C++](./codes/cpp/BinaryTreeRightSideViewProg.cpp) | diff --git a/codes/cpp/TrappingRainWater.cpp b/codes/cpp/TrappingRainWater.cpp new file mode 100644 index 0000000..185bbc9 --- /dev/null +++ b/codes/cpp/TrappingRainWater.cpp @@ -0,0 +1,25 @@ +#include +class Solution { +public: + int trap(vector& height) { + vector lmax(height.size(),0); + vector rmax(height.size(),0); + int i; + lmax[0]=height[0]; + for(i=1;i=0;i--) + { + rmax[i]=max(rmax[i+1],height[i]); + } + int res=0; + for(i=0;i