LeetCode 1번 Two Sum 문제풀이
Given an array of integers nums
and an integer target
, return indices of the two numbers such that they add up to target
.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
You can return the answer in any order.
(예시 생략)
요약하자면 합해서 target
이 되는 nums
Array의 두 수를 찾고,
그 수들의 index를 찾아서 리턴하라는 것이다.
코드스쿼드 알고리즘 2주차 문제로 주어진 건데 사실 이 문제는 2달 전 Swift를 거의 처음 배울 때 시도한 적이 있었다.
그땐 하다가 안돼서 포기했더랬다🥲 지금 보니 이게 왜 안됐지 싶다
하지만 이번엔 20분 내외로 성공! (와!)
그간 실력이 늘었다는 사실에 소소하게 기뻐하며 이제 진짜 풀이를 정리해보겠다.