two sum python

class Solution:
    def twoSum(self, nums: list[int], target: int) -> list[int]:
        required = {}
        for i in range(len(nums)):
            if target - nums[i] in required:
                return [required[target - nums[i]], i]
            else:
                required[nums[i]] = i

Here is what the above code is Doing:
1. We create a dictionary called required.
2. We iterate through the nums list.
3. For each element in the list, we check if the target – element is in the required dictionary.
4. If it is, we return the indices of the required element and the current element.
5. If it is not, we add the current element to the required dictionary.