yan chuanli 2 سال پیش
والد
کامیت
c9cbe57507

BIN
.DS_Store


+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 19 - 0
.idea/inspectionProfiles/Project_Default.xml

@@ -0,0 +1,19 @@
+<component name="InspectionProjectProfileManager">
+  <profile version="1.0">
+    <option name="myName" value="Project Default" />
+    <inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
+      <option name="ignoredPackages">
+        <value>
+          <list size="6">
+            <item index="0" class="java.lang.String" itemvalue="tensorboard" />
+            <item index="1" class="java.lang.String" itemvalue="seaborn" />
+            <item index="2" class="java.lang.String" itemvalue="thop" />
+            <item index="3" class="java.lang.String" itemvalue="torch" />
+            <item index="4" class="java.lang.String" itemvalue="torchvision" />
+            <item index="5" class="java.lang.String" itemvalue="pycocotools" />
+          </list>
+        </value>
+      </option>
+    </inspection_tool>
+  </profile>
+</component>

+ 6 - 0
.idea/inspectionProfiles/profiles_settings.xml

@@ -0,0 +1,6 @@
+<component name="InspectionProjectProfileManager">
+  <settings>
+    <option name="USE_PROJECT_PROFILE" value="false" />
+    <version value="1.0" />
+  </settings>
+</component>

+ 8 - 0
.idea/leetcode.iml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 4 - 0
.idea/misc.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/leetcode.iml" filepath="$PROJECT_DIR$/.idea/leetcode.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 0 - 0
.gitignore → .ignore


BIN
__pycache__/draft.cpython-310-pytest-7.1.2.pyc


BIN
__pycache__/get_markdown.cpython-38-pytest-7.1.2.pyc


BIN
__pycache__/is_valid.cpython-38-pytest-7.1.2.pyc


BIN
__pycache__/merge_two_lists.cpython-310-pytest-7.1.2.pyc


BIN
__pycache__/merge_two_lists.cpython-38-pytest-7.1.2.pyc


BIN
__pycache__/remove_element.cpython-310-pytest-7.1.2.pyc


BIN
__pycache__/roman_to_int.cpython-38-pytest-7.1.2.pyc


BIN
__pycache__/search_insert.cpython-310-pytest-7.1.2.pyc


BIN
__pycache__/two_sum.cpython-38-pytest-7.1.2.pyc


BIN
__pycache__/utils.cpython-310.pyc


BIN
__pycache__/utils.cpython-38-pytest-7.1.2.pyc


BIN
__pycache__/utils.cpython-38.pyc


BIN
array/__pycache__/search_insert.cpython-310-pytest-7.1.2.pyc


+ 7 - 0
array/add_binary.py

@@ -0,0 +1,7 @@
+def addBinary(a: str, b: str) -> str:
+    a_num = int(a, 2)
+    b_num = int(b, 2)
+    result = a_num + b_num
+    return (bin(result)[2:])
+
+print(addBinary('1010', '1011'))

+ 4 - 9
draft.py

@@ -1,9 +1,4 @@
-import pytest
-@pytest.mark.parametrize(
-    "list1, list2, expect",
-    [
-        ([1, 2, 4], [1, 3, 4], [1, 1, 2, 3, 4, 4])
-    ]
-)
-def test_cases(list1, list2, expect):
-    assert mergeTwoLists(list1, list2) == expect
+
+num = [1,2,1,4,5]
+print(list(set(num)))
+

+ 2 - 1
mySqrt.py

@@ -14,11 +14,12 @@ def mySqrt(x: int) -> int:
 
     l, r, ans = 0, x, -1
     while l <= r:
-        mid = (l + r) // 2
+        mid = l + (r - l) // 2
         if mid * mid <= x:
             ans = mid
             l = mid + 1
         else:
             r = mid - 1
     return ans
+
 print(mySqrt(10))

+ 56 - 6
tree/whole_arrang.py

@@ -1,7 +1,57 @@
-def addBinary(a: str, b: str) -> str:
-    a_num = int(a, 2)
-    b_num = int(b, 2)
-    result = a_num + b_num
-    return (bin(result)[2:])
+from typing import List
+class Solution:
+    def permute(self, nums: List[int]) -> List[List[int]]:
 
-print(addBinary('1010', '1011'))
+
+        def dfs(nums, size, depth, path, used, res):
+            if depth == size:
+                res.append(path[:])
+
+                return
+
+            for i in range(size):
+                # used[i] 为 false时
+                if not used[i]:
+                    used[i] = True
+                    path.append(nums[i])
+
+                    def dfs(nums, size, depth, path, used, res):
+                        if depth == size:
+                            res.append(path[:])
+
+                            return
+
+                        for i in range(size):
+                            # used[i] 为 false时
+                            if not used[i]:
+                                used[i] = True
+                                path.append(nums[i])
+
+                                dfs(nums, size, depth + 1, path, used, res)
+
+                                used[i] = False
+                                path.pop()
+
+                    used[i] = False
+                    path.pop()
+
+        size = len(nums)
+        if len(nums) == 0:
+            return []
+
+        # 一维数组赋值
+        used = [False for _ in range(size)]
+        # 二维数组赋值
+        # [[False for _ in range(size)] for _ in range(size)]
+        res = []
+        dfs(nums, size, 0, [], used, res)
+
+
+        return res
+
+
+if __name__ == '__main__':
+    nums = [1, 2, 3]
+    solution = Solution()
+    res = solution.permute(nums)
+    print(res)

+ 38 - 0
tree/whole_arrang_two.py

@@ -0,0 +1,38 @@
+from typing import List
+
+
+class Solution:
+    def permuteUnique(self, nums: List[int]) -> List[List[int]]:
+        def dfs(nums, size, depth, path, res, used):
+            if depth == size:
+                if path not in res:
+                    res.append(path[:])
+                return
+
+            for i in range(size):
+                if not used[i]:
+                    used[i] = True
+                    path.append(nums[i])
+
+                    dfs(nums, size, depth + 1, path, res, used)
+
+                    used[i] = False
+                    path.pop()
+
+        size = len(nums)
+        if len(nums) == 0:
+            return []
+
+        used = [False for _ in range(size)]
+        res = []
+
+        dfs(nums, size, 0, [], res, used)
+
+        return res
+
+if __name__ == "__main__":
+    nums = [1, 1, 3]
+    solution = Solution()
+    res = solution.permuteUnique(nums)
+    print(res)
+