ixueaedu 1 năm trước cách đây
mục cha
commit
0033b89ce3
3 tập tin đã thay đổi với 20 bổ sung9 xóa
  1. 11 0
      array/single_Number.py
  2. 4 9
      draft.py
  3. 5 0
      generat_matrix.py

+ 11 - 0
array/single_Number.py

@@ -0,0 +1,11 @@
+from typing import List
+
+# 异或运算有以下三个性质。
+# 任何数和 00 做异或运算,结果仍然是原来的数,即 a ⊕ 0=a。
+# 任何数和其自身做异或运算,结果是 00,即 a ⊕ a = 0。
+# 异或运算满足交换律和结合律
+def singleNumber(self, nums: List[int]) -> int:
+    arr = 0
+    for i in nums:
+        arr ^= i
+    return arr

+ 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
+import numpy as np
+n = 3
+m = np.array(range(1, (n * n) + 1)).reshape(n, n)
+print(m)

+ 5 - 0
generat_matrix.py

@@ -0,0 +1,5 @@
+from typing import List
+import numpy as np
+
+def generateMatrix(self, n: int) -> List[List[int]]:
+    m = np.array(range(1, (n * n) + 1)).reshape(n, n)