Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- rrf
- visual instruction tuning
- deep learning
- anomaly detection
- rag-fusion
- 파인튜닝
- Time Series
- LLM 패러다임
- 데이터 파싱
- 이상탐지
- 딥러닝
- pdf parsing
- Nested Learning
- rag parsing
- fp16
- LLaVA
- 합성곱 신경망
- 활성화 함수
- 오차역전파
- gemma3
- fine tuning
- Cross Entropy Error
- Mean squared error
- multi-query
- Non-Maximum Suppression
- qlora
- LLM
- fp32
- 활성화함수
- bf16
Archives
- Today
- Total
Attention, Please!!!
[LeetCode] Two Sum 본문
문제

풀이
Brute Force 방식과는 달리 HashMap를 사용하게 된다면, 한번의 Iteration으로 결과 값 도출이 가능합니다.
nums = [2,1,5,3] 배열과 target = 4 값이 주어졌다고 가정해보겠습니다.
| Value | Index | Difference | Hashmap |
| 2 | 0 | 4 - 2 = 2 | (2,0) |
| 1 | 1 | 4 - 1 = 3 | (1,1) |
| 5 | 2 | 4 - 5 = -1 | (5,2) |
처음으로 Target 값에서 각 배열의 element 차이를 구합니다. 이를 통해 도출되는 Difference 값이 중복되지 않았다면 Hashmap에 포함시켜주고, 중복 되어있다면 포함시키지 않습니다.
Class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
prevMap = {}
for i,n in enumerate(nums):
diff = target - n
if diff in prevMap:
return[prevMap[diff],i]
prevMap[n] = i'Algorithm > Leetcode' 카테고리의 다른 글
| [LeetCode] Valid Anagram (0) | 2024.02.16 |
|---|---|
| [LeetCode] Product of Array Except Self (0) | 2023.12.14 |
| [LeetCode] SQL 50문제 (진행중) (0) | 2023.10.24 |
| [LeetCode] Valid Sudoku (0) | 2023.10.12 |
| [LeetCode] Contains Duplicate (0) | 2023.10.10 |