Compare commits

...
2 Commits
Author SHA1 Message Date
izatwin 33af13cb50 238 Product of Array except itself 2024-08-04 21:02:39 -04:00
izatwin 2d2ccc70bd 53 Maximum Subarray 2024-08-04 21:02:24 -04:00
2 changed files with 34 additions and 0 deletions
@@ -0,0 +1,18 @@
class Solution:
def productExceptSelf(self, nums: list[int]) -> list[int]:
ans = [1] * len(nums)
curr = 1
for i in range(len(nums)):
ans[i] *= curr
curr *= nums[i]
curr = 1
for i in range(len(nums) - 1, -1, -1):
ans[i] *= curr
curr *= nums[i]
return ans
if __name__ == "__main__":
test = Solution()
print(test.productExceptSelf([-1,1,0,-3,3]))
+16
View File
@@ -0,0 +1,16 @@
from math import inf
def maxSubArray(nums):
max_sum = nums[0]
current_sum = nums[0]
for n in nums[1:]:
if current_sum < 0:
current_sum = 0
current_sum += n
if current_sum > max_sum:
max_sum = current_sum
return max_sum
if __name__ == "__main__":
print(maxSubArray([-2,1]))