diff --git a/Problem1.java b/Problem1.java deleted file mode 100644 index e69de29b..00000000 diff --git a/Problem1.py b/Problem1.py new file mode 100644 index 00000000..d1bf77c5 --- /dev/null +++ b/Problem1.py @@ -0,0 +1,14 @@ +#Time Complexity : O(n) +#Space Complexity : O(n) +#Did this code successfully run on Leetcode :Yes + +class Solution: + def twoSum(self, nums, target): + n = len(nums) + + for i in range(n): + for j in range(i + 1, n): + if nums[i] + nums[j] == target: + return [i, j] + + return [-1, -1] diff --git a/Problem2.java b/Problem2.java deleted file mode 100644 index e69de29b..00000000 diff --git a/Problem2.py b/Problem2.py new file mode 100644 index 00000000..9e375448 --- /dev/null +++ b/Problem2.py @@ -0,0 +1,14 @@ +#Time Complexity : O(n*m) +#Space Complexity : O(n) +class Solution: + @staticmethod + def findMax(weights, profit, totalCapacity): + n = totalCapacity + m = len(weights) + dp = [0] * (n + 1) + + for i in range(m): + for j in range(n, weights[i] - 1, -1): + dp[j] = max(dp[j], profit[i] + dp[j - weights[i]]) + + return dp[n]