#1. Two Sum [LeetCode Grind 75 in Java]

[Problem Link] https://leetcode.com/problems/two-sum/

class Solution {
    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer , Integer> map = new HashMap<>();
        int n = nums.length;
        int[] ans = new int[2];

        for(int i = 0 ; i < n ; i ++){
            int check = target - nums[i];
            if(map.containsKey(check)){
                ans[0] = i;
                ans[1] = map.get(check);
                break;
            }else{
                map.put(nums[i] , i);
            }
        }

        return ans;
    }
}