Implement a solution for a standard problem like Two Sum or basic sorting algorithms.
For this task, implement two_sum(nums, target). Return the indices of two distinct elements whose values add up to target. Assume exactly one valid pair exists, and return the indices in ascending order.
Input is an integer list and an integer target. Output is a two-element list of integers.
def two_sum(nums, target):