Given an array of integers nums and an integer target,
return indices of the two numbers such that they add up to target.
Input:
nums = [2,7,11,15]
target = 9Output:
[0,1]Uses a HashMap (dictionary) to store visited numbers.
- Time: O(n)
- Space: O(n)
Dado um array de números inteiros nums e um número inteiro target,
retorne os índices dos dois números cuja soma resulte no valor do target.
Entrada:
nums = [2,7,11,15]
target = 9Saída:
[0,1]Utiliza um HashMap (dicionário) para armazenar os números já visitados.
- Tempo: O(n)
- Espaço: O(n)