|
@@ -1,7 +1,30 @@
|
|
|
+from typing import List
|
|
|
+import unittest
|
|
|
+
|
|
|
+
|
|
|
class Solution:
|
|
|
def twoSum(self, nums: List[int], target: int) -> List[int]:
|
|
|
n = len(nums)
|
|
|
for i in range(n):
|
|
|
- for j in range(i + 1 , n):
|
|
|
+ for j in range(i + 1, n):
|
|
|
if nums[i] + nums[j] == target:
|
|
|
- return [i , j]
|
|
|
+ return [i, j]
|
|
|
+
|
|
|
+
|
|
|
+class TestTwoSum(unittest.TestCase):
|
|
|
+
|
|
|
+ def test_two_sum1(self):
|
|
|
+ nums = [2, 7, 11, 15]
|
|
|
+ target = 9
|
|
|
+ s = Solution()
|
|
|
+ res = s.twoSum(nums, target)
|
|
|
+
|
|
|
+ self.assertEqual(res, [0, 1])
|
|
|
+
|
|
|
+ def test_two_sum2(self):
|
|
|
+ nums = [3, 3]
|
|
|
+ target = 6
|
|
|
+ s = Solution()
|
|
|
+ res = s.twoSum(nums, target)
|
|
|
+
|
|
|
+ self.assertEqual(res, [0, 1])
|