|
@@ -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)
|