---
# System prepended metadata

title: info2021-homework1
tags: [資訊科技產業專案設計]

---

# info2021-homework1
###### tags: `資訊科技產業專案設計`
## Test 1.
### Leetcode #1 Two sum

👨🏽‍💻Given an array of integers numbers and an integer target, return indices of the two numbers such that they add up to target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

You can return the answer in any order.


👨‍💼
```
class Solution:
    def twoSum(self, numbers: List[int], target: int) -> List[int]:
        for i in range(len(numbers)):            
            for j in range(i+1, len(numbers)):
                if (numbers[i] + numbers[j] == target):
                    return [i,j]
```
👨‍💼In the first loop, 

👨🏽‍💻Too slow, can you come up with a faster solution?

```
class Solution:
    def twoSum(self, numbers: List[int], target: int) -> List[int]:
        seen = {}
        for i, value in enumerate(numbers):
            remaining = target - value
            if remaining in seen:
                return [seen[remaining], i]
            seen[value] = i
        return []
```
       