Implement a solution for the 2Sum problem.
Define def two_sum(nums, target):, where nums is a list of integers and target is an integer. Return the two distinct zero-based indices whose values sum to target; assume exactly one solution exists, with 2 <= len(nums) <= 10^4 and values between -10^9 and 10^9.
For example, nums = [2, 7, 11, 15], target = 9 returns [0, 1], while nums = [3, 2, 4], target = 6 returns [1, 2]. Aim for better than quadratic time.
def two_sum(nums, target):