Browse Source

feat: two sum

Zhang Li 11 months ago
parent
commit
ed63d390a0
3 changed files with 30 additions and 43 deletions
  1. 30 0
      array/twoSum.py
  2. 0 36
      main.py
  3. 0 7
      twoSum.py

+ 30 - 0
array/twoSum.py

@@ -0,0 +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):
+                if nums[i] + nums[j] == target:
+                    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])

+ 0 - 36
main.py

@@ -1,36 +0,0 @@
-# from fastapi import FastAPI
-from minio import Minio
-from minio.error import S3Error
-
-client = Minio('localhost:9000',
-               access_key='nngIIjuqvRa4aZ1jRb3n',
-               secret_key='IO8KYbgesqHxMvDDwCu6I9fBEpTVaKXxGV27itBK',
-               secure=False
-               )
-print("====-=-=-=-=")
-def main():
-    if client.bucket_exists("test"):
-        print("my-bucket exists")
-    else:
-        print("my-bucket does not exist")
-    print("2====-=-=-=-=")
-    res = client.fput_object("test","1.jpg","/Users/xuxiaotong/PycharmProjects/pythonProject/2.jpg")
-    print( res.bucket_name )
-    client.remove_object(
-        "test", "2.jpg",
-        # version_id="dfbd25b3-abec-4184-a4e8-5a35a5c1174d",
-    )
-
-if __name__ == "__main__":
-
-   # try:
-    main()
-    # except S3Error as exc:
-    #     print("error occurred.", exc)
-
-# app = FastAPI()
-#
-#
-# @app.get("/")
-# async def root():
-#     return {"message": "Hello World"}

+ 0 - 7
twoSum.py

@@ -1,7 +0,0 @@
-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):
-                if nums[i] + nums[j] == target:
-                    return [i , j]