From 174c8351f38021695ff4ce25f3b945a6671fca80 Mon Sep 17 00:00:00 2001 From: Shreya Rathore Date: Mon, 24 Nov 2025 09:23:41 -0500 Subject: [PATCH] Completed Exercise 1 --- Problem1.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Problem1.java b/Problem1.java index e69de29b..88664c54 100644 --- a/Problem1.java +++ b/Problem1.java @@ -0,0 +1,24 @@ +// TC: O(n) +// SC: O(n) + +// 1: We use a HashMap with a key:value pair of the number from the input array: the index at which it is present +// 2: For each element in the array, we determine whether the difference from the target is present in the array +// 3: If the difference does not exist, we insert the current number into the array along with its index +class Solution { + public int[] twoSum(int[] nums, int target) { + + HashMap map = new HashMap<>(); + + for(int i = 0; i