commit c39ae0d3e1547b0fe3a4c98d332510b90b5c9229 Author: rain-bus Date: Wed Apr 29 11:36:37 2026 +0800 init: hot100 algo project with .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8480e8a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +__pycache__/ +*.pyc +*.pyo +*.pyd +.Python +*.so +*.egg +*.egg-info/ +dist/ +build/ +.eggs/ +*.whl + +.env +.venv +env/ +venv/ +ENV/ + +.idea/ +.vscode/ +*.swp +*.swo +*~ + +.DS_Store +Thumbs.db + +.pytest_cache/ +.mypy_cache/ +.ruff_cache/ +htmlcov/ +.coverage diff --git a/01-two-sum/solution.py b/01-two-sum/solution.py new file mode 100644 index 0000000..2c4e4e6 --- /dev/null +++ b/01-two-sum/solution.py @@ -0,0 +1,15 @@ +from typing import List + +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + hash = {} + for i, num in enumerate(nums): + another = target - num + if another in hash: + return [hash[another], i] + hash[num] = i + + +if __name__ == "__main__": + res = Solution().twoSum([2,7,11,15], 9) + print(res)