LeetcodeArray
1. Two Sum
class Solution:
def twoSum(self, A: List[int], target: int) -> List[int]:
seen = {}
for i, v in enumerate(A):
need = target - v
if need in seen:
return [seen[need], i]
seen[v] = i
return []| Metric | Complexity | Reason |
|---|---|---|
| Time Complexity | Single pass through the list | |
| Space Complexity | Dictionary to store seen elements |