From c0c5e935b7e0b1bc24e990ec11a501f30ff6cc40 Mon Sep 17 00:00:00 2001 From: Arya_barenya <87018655+HatimTai1@users.noreply.github.com> Date: Sun, 3 Oct 2021 10:46:45 +0530 Subject: [PATCH 1/2] Create trappingRainwater.py Trapping rainwater problem (python) --- trappingRainwater.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 trappingRainwater.py diff --git a/trappingRainwater.py b/trappingRainwater.py new file mode 100644 index 0000000..20086ea --- /dev/null +++ b/trappingRainwater.py @@ -0,0 +1,21 @@ +class Solution(object): + def trap(self, height): + """ + :type height: List[int] + :rtype: int + """ + n=len(height) + left=[0]*n + right=[0]*n + maxi=-876543 + for i in range(0,n): + left[i]=max(maxi,height[i]) + maxi=left[i] + maxi=-876543 + for i in range(n-1,-1,-1): + right[i]=max(maxi,height[i]) + maxi=right[i] + ans=0 + for i in range(0,n): + ans+=min(left[i],right[i])-height[i] + return ans From 30569775e99da03575ab7c1d331b6f5a38537bc3 Mon Sep 17 00:00:00 2001 From: Arya_barenya <87018655+HatimTai1@users.noreply.github.com> Date: Sun, 3 Oct 2021 10:59:01 +0530 Subject: [PATCH 2/2] Create problem.CPP Longest substring without repeating elements --- problem.CPP | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 problem.CPP diff --git a/problem.CPP b/problem.CPP new file mode 100644 index 0000000..55f1989 --- /dev/null +++ b/problem.CPP @@ -0,0 +1,26 @@ +class Solution { +public: + int lengthOfLongestSubstring(string s) { + int ans = 0; + int n = s.size(); + int temp = 0; + int h[128] = {0}; + for(int i = 0;i 0) + { + if(h[int(s[i])] >= 2) + for(int j = h[int(s[i])] - 2 ;j >= (i - temp);j--){ + h[int(s[j])] = 0; + } + ans = max(ans,temp); + temp = i - h[int(s[i])] + 1; + h[int(s[i])] = i + 1; + } + else{ + temp++; + h[int(s[i])] = i + 1; + } + } + return max(ans,temp); + } +};