ixueaedu 2 anos atrás
pai
commit
741cfeeef4
4 arquivos alterados com 26 adições e 15 exclusões
  1. 1 1
      .idea/leetcode.iml
  2. 1 1
      .idea/misc.xml
  3. 1 10
      draft.py
  4. 23 3
      generat_matrix.py

+ 1 - 1
.idea/leetcode.iml

@@ -2,7 +2,7 @@
 <module type="PYTHON_MODULE" version="4">
   <component name="NewModuleRootManager">
     <content url="file://$MODULE_DIR$" />
-    <orderEntry type="jdk" jdkName="Python 3.8 (py38_schoolcert) (2)" jdkType="Python SDK" />
+    <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>
 </module>

+ 1 - 1
.idea/misc.xml

@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
-  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (py38_schoolcert) (2)" project-jdk-type="Python SDK" />
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
 </project>

+ 1 - 10
draft.py

@@ -1,11 +1,2 @@
-<<<<<<< HEAD
-import numpy as np
-n = 3
-m = np.array(range(1, (n * n) + 1)).reshape(n, n)
-print(m)
-=======
-s = "A man, a plan, a canal: Panama".lower()
-b = ''.join(ch for ch in s if ch.isalnum()).lower()
-print(b)
 
->>>>>>> 0ac0c7a7a7ace7b2c81857019fe6ed8ad32cad09
+

+ 23 - 3
generat_matrix.py

@@ -1,5 +1,25 @@
 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)
+def generateMatrix(n: int) -> List[List[int]]:
+    l, r, t, b = 0, n - 1, 0, n - 1
+    mat = [[0 for _ in range(n)] for _ in range(n)]
+    num, tar = 1, n * n
+    while num <= tar:
+        for i in range(l, r + 1):  # left to right
+            mat[t][i] = num
+            num += 1
+        t += 1
+        for i in range(t, b + 1):  # top to bottom
+            mat[i][r] = num
+            num += 1
+        r -= 1
+        for i in range(r, l - 1, -1):  # right to left
+            mat[b][i] = num
+            num += 1
+        b -= 1
+        for i in range(b, t - 1, -1):  # bottom to top
+            mat[i][l] = num
+            num += 1
+        l += 1
+    return mat
+