瀏覽代碼

add 中序遍历

ixueaedu 2 年之前
父節點
當前提交
904ad4e46b
共有 5 個文件被更改,包括 21 次插入2 次删除
  1. 4 0
      .idea/leetcode.iml
  2. 1 1
      .idea/misc.xml
  3. 1 1
      spiral_matrix.py
  4. 13 0
      tree/inorder_transversal.py
  5. 2 0
      tree/same_tree.py

+ 4 - 0
.idea/leetcode.iml

@@ -2,7 +2,11 @@
 <module type="PYTHON_MODULE" version="4">
   <component name="NewModuleRootManager">
     <content url="file://$MODULE_DIR$" />
+<<<<<<< Updated upstream
     <orderEntry type="jdk" jdkName="Python 3.8 (py38) (3)" jdkType="Python SDK" />
+=======
+    <orderEntry type="jdk" jdkName="Python 3.9" jdkType="Python SDK" />
+>>>>>>> Stashed changes
     <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) (3)" project-jdk-type="Python SDK" />
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
 </project>

+ 1 - 1
spiral_matrix.py

@@ -1,6 +1,5 @@
 from typing import List
 
-
 class Solution:
     def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
         m, n = len(matrix), len(matrix[0])
@@ -37,4 +36,5 @@ class Solution:
 if __name__ == "__main__":
     s = Solution()
     a = s.spiralOrder([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
+
     print(a)

+ 13 - 0
tree/inorder_transversal.py

@@ -0,0 +1,13 @@
+class TreeNode:
+    def __init__(self, val=0, left=None, right=None):
+        self.val = val
+        self.left = left
+        self.right = right
+
+class Solution:
+    def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
+        if root == None:
+            return []
+        left = self.inorderTraversal(root.left)
+        right = self.inorderTraversal(root.right)
+        return left + [root.val] + right

+ 2 - 0
tree/same_tree.py

@@ -0,0 +1,2 @@
+class Solution:
+    def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool: