Download 10-week-algorithm-excercise-master/OneQuestionPerDay/1/two_sum.py from Dorothydu/gitrepo_20: direct link, hf CLI and curl.
- Browser
- Download file 295 Bytes
-
https://huggingface.co/datasets/Dorothydu/gitrepo_20/resolve/main/10-week-algorithm-excercise-master/OneQuestionPerDay/1/two_sum.py
- Command line
-
hf download hf://datasets/Dorothydu/gitrepo_20/10-week-algorithm-excercise-master/OneQuestionPerDay/1/two_sum.py
-
curl -L -o two_sum.py https://huggingface.co/datasets/Dorothydu/gitrepo_20/resolve/main/10-week-algorithm-excercise-master/OneQuestionPerDay/1/two_sum.py
295 Bytes
| from typing import List | |
| class Solution: | |
| def twoSum(self, nums: List[int], target: int) -> List[int]: | |
| cache = {} | |
| for i, n in enumerate(nums): | |
| m = target - n | |
| if m in cache: | |
| return [cache[m], i] | |
| cache[n] = i | |
| return [] |