From c5c4964733e013f08dcca0abfc5da86540fb445a Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 21 Oct 2025 16:12:32 -0500 Subject: [PATCH] Array-3 completed --- h_index_1.py | 10 ++++++++++ rotate_array_k.py | 23 +++++++++++++++++++++++ trapping_water.py | 21 +++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 h_index_1.py create mode 100644 rotate_array_k.py create mode 100644 trapping_water.py diff --git a/h_index_1.py b/h_index_1.py new file mode 100644 index 00000000..f253cfff --- /dev/null +++ b/h_index_1.py @@ -0,0 +1,10 @@ +class Solution: + def hIndex(self, citations: List[int]) -> int: + citations.sort() + n=len(citations) + + for i in range(n): + diff=n-i + if diff<=citations[i]: + return diff + return 0 diff --git a/rotate_array_k.py b/rotate_array_k.py new file mode 100644 index 00000000..9c407f9c --- /dev/null +++ b/rotate_array_k.py @@ -0,0 +1,23 @@ + +class Solution: + def rotate(self, nums: List[int], k: int) -> None: + """ + Do not return anything, modify nums in-place instead. + """ + n=len(nums) + k=k%n + + self.reverse(nums,0,n-1) + self.reverse(nums,0,k-1) + self.reverse(nums,k,n-1) + + def reverse(self,nums,left,right): + while left int: + n=len(height) + lw,l=0,0 + rw,r=n-1,n-1 + result=0 + + while l<=r: + if height[rw]>height[lw]: + if height[lw]>height[l]: + result+=height[lw]-height[l] + else: + lw=l + l+=1 + else: + if height[rw]>height[r]: + result+=height[rw]-height[r] + else: + rw=r + r-=1 + return result