Can you solve the two-sum problem and explain your reasoning?
Implement two_sum(nums, target) to return the indices of two distinct elements whose values add up to target. Return the indices in ascending order. Each valid input contains exactly one solution.
Input: an integer array and an integer target. Output: a two-element list of indices.
def two_sum(nums, target):