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 |
Tags
- 딥러닝
- rag parsing
- nlp
- 이상탐지
- visual instruction tuning
- anomaly detection
- LLM
- LLaVA
- Time Series
- qlora
- 데이터 파싱
- 시계열
- 합성곱 신경망
- 활성화함수
- multi-query
- fine tuning
- Mean squared error
- gemma3
- Cross Entropy Error
- rag-fusion
- deep learning
- Non-Maximum Suppression
- 오차역전파
- 파인튜닝
- leetcode
- pdf parsing
- 활성화 함수
- rrf
- 손실함수
- 퍼셉트론
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 |