diff --git a/Submission/AyushSingh/Best Time to Buy and Sell Stock II/screenshot.png b/Submission/AyushSingh/Best Time to Buy and Sell Stock II/screenshot.png new file mode 100644 index 0000000..4055cd7 Binary files /dev/null and b/Submission/AyushSingh/Best Time to Buy and Sell Stock II/screenshot.png differ diff --git a/Submission/AyushSingh/Best Time to Buy and Sell Stock II/solution.py b/Submission/AyushSingh/Best Time to Buy and Sell Stock II/solution.py new file mode 100644 index 0000000..e403232 --- /dev/null +++ b/Submission/AyushSingh/Best Time to Buy and Sell Stock II/solution.py @@ -0,0 +1,8 @@ +class Solution: + def maxProfit(self, prices: List[int]) -> int: + profit = 0 + for i in range(1, len(prices)): + if prices[i] > prices[i - 1]: + profit += prices[i] - prices[i - 1] + return profit + \ No newline at end of file diff --git a/Submission/AyushSingh/Merge Sorted Array/screenshot.png b/Submission/AyushSingh/Merge Sorted Array/screenshot.png new file mode 100644 index 0000000..f0da788 Binary files /dev/null and b/Submission/AyushSingh/Merge Sorted Array/screenshot.png differ diff --git a/Submission/AyushSingh/Merge Sorted Array/solution.py b/Submission/AyushSingh/Merge Sorted Array/solution.py new file mode 100644 index 0000000..d0562fb --- /dev/null +++ b/Submission/AyushSingh/Merge Sorted Array/solution.py @@ -0,0 +1,20 @@ +class Solution: + def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: + i = m - 1 + j = n - 1 + k = m + n - 1 + + while i >= 0 and j >= 0: + if nums1[i] > nums2[j]: + nums1[k] = nums1[i] + i -= 1 + else: + nums1[k] = nums2[j] + j -= 1 + k -= 1 + + while j >= 0: + nums1[k] = nums2[j] + j -= 1 + k -= 1 + \ No newline at end of file diff --git a/Submission/AyushSingh/Move Zeroes/screenshot.png b/Submission/AyushSingh/Move Zeroes/screenshot.png new file mode 100644 index 0000000..af47291 Binary files /dev/null and b/Submission/AyushSingh/Move Zeroes/screenshot.png differ diff --git a/Submission/AyushSingh/Move Zeroes/solution.py b/Submission/AyushSingh/Move Zeroes/solution.py new file mode 100644 index 0000000..b6f6648 --- /dev/null +++ b/Submission/AyushSingh/Move Zeroes/solution.py @@ -0,0 +1,13 @@ +class Solution: + def moveZeroes(self, nums: List[int]) -> None: + """ + Do not return anything, modify nums in-place instead. + """ + j = 0 + for i in range(len(nums)): + if nums[i] != 0: + nums[j] = nums[i] + j += 1 + for k in range(j, len(nums)): + nums[k] = 0 + \ No newline at end of file diff --git a/Submission/AyushSingh/Two Sum/screenshot.png b/Submission/AyushSingh/Two Sum/screenshot.png new file mode 100644 index 0000000..acb048a Binary files /dev/null and b/Submission/AyushSingh/Two Sum/screenshot.png differ diff --git a/Submission/AyushSingh/Two Sum/solution.py b/Submission/AyushSingh/Two Sum/solution.py new file mode 100644 index 0000000..b21f759 --- /dev/null +++ b/Submission/AyushSingh/Two Sum/solution.py @@ -0,0 +1,10 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + num_to_index = {} + for i, num in enumerate(nums): + complement = target - num + if complement in num_to_index: + return [num_to_index[complement], i] + num_to_index[num] = i + return [] + \ No newline at end of file