S01. 릿코드(리트코드) - Two Sum
유투브 강의 : https://www.youtube.com/watch?v=-hGsPMq5wMw&t=557s 소스 코드 : https://leetcode.com/problems/two-sum/discuss/1003158/Java-solution 첫번째 문제 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. Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. 정수배열인 nums와 정수 target이 주어졌을때 정수배열의 값들 중 두 수의 합이 target이 되는 해당하는 두 수의 배열의 인덱스 값을 리턴하는 문제입니다. 우선 배열이 위의 예시처럼 2,7,11,15가 있다면요, 배열 인덱스는 0부터 시작해서 0,1,2,3이 되겠네요. 0번째 배열 인덱스의 값은 2고, 4번째 배열 인덱스의 값은 15가 되겠습니다. 그럼 두수의 합이 target 예시에서는 9겠네요. 9가 되는 두수는 어떻게 찾을 수 있을까요? 가장 쉬운 방법은 완전 탐색을 이용해 찾는 방법입니다. 완전 탐색이란 모든 경우의 수를 찾는 다는 의미이죠. 첫번째 수는 배열 인덱스 0부터 탐색을 합니다. 그리고 배열의 길이...