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
- meshgraphnet
- GNN
- 데이터
- mysql
- CS
- 컴퓨터사이언스
- 오블완
- 데베
- 개발자
- SQL
- Mesh
- 자료구조
- Python
- Data_Structure
- coding
- sort
- db
- adaptive remeshing
- 대학생
- 컴퓨터공학
- 티스토리챌린지
- 데이터베이스
- code
- Database
- DS
- LeetCode
- CNN
- Leet Code
- 코딩테스트
- 코테
Archives
- Today
- Total
sy1214ei 님의 블로그
[Leet Code] 1. Two Sum - Python 본문
https://leetcode.com/problems/two-sum/description/
Level: Easy
Topics: Array | Hash Table
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
"""
1. for i, num in enumerate(nums) : 뭔가 순회를 해야 찾든말든 할것임
2. 우리가 찾는 것 find = target - num
3. 만약 hash_table에 find가 있다면 return
4. hash_table[num] = i
"""
hash_table = {}
for i, num in enumerate(nums):
find = target - num
if find in hash_table:
return [hash_table[find], i]
hash_table[num] = i
# Time Complexity : O(n)
# Space Complexity : O(n)

'[Coding]' 카테고리의 다른 글
| [Leet Code] 41. First Missing Positive - Python (1) | 2024.12.16 |
|---|---|
| [Leet Code] 409. Longest Palindrome - Python (2) | 2024.12.04 |
| [Leet Code] 9. Palindrome Number - Python (0) | 2024.11.30 |
| [Leet Code] 21. Merge Two Sorted Lists - Python (7) | 2024.11.29 |
| [Leet Code] 645. Set Mismatch - Python (0) | 2024.11.28 |