fix syntax of data_structures

This commit is contained in:
Doppon 2020-05-14 11:05:14 +09:00
parent 04fd348291
commit 9c1823739c
5 changed files with 54 additions and 55 deletions

View file

@ -76,5 +76,4 @@ class SingleList
def isEmpty()
return (@head==nil)
end
end

View file

@ -1,23 +1,23 @@
# Definition for a binary tree node.
# class TreeNode
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# end
# @param {TreeNode} root
# @return {Integer[]}
def inorder_traversal(root)
ans = []
def traverse(node, ans)
if node != nil
traverse(node.left, ans)
ans.push(node.val)
traverse(node.right,ans)
end
ans = []
def traverse(node, ans)
if node != nil
traverse(node.left, ans)
ans.push(node.val)
traverse(node.right, ans)
end
traverse(root,ans)
return ans
end
traverse(root, ans)
return ans
end

View file

@ -1,20 +1,20 @@
# Definition for a binary tree node.
# class TreeNode
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# end
# @param {TreeNode} root
# @return {TreeNode}
def invert_tree(root)
if root == nil
return nil
end
temp = root.left
root.left = invert_tree(root.right)
root.right = invert_tree(temp)
return root
if root == nil
return nil
end
temp = root.left
root.left = invert_tree(root.right)
root.right = invert_tree(temp)
return root
end

View file

@ -1,23 +1,23 @@
# Definition for a binary tree node.
# class TreeNode
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# end
# @param {TreeNode} root
# @return {Integer[]}
def postorder_traversal(root)
ans = []
def traverse(node, ans)
if node != nil
traverse(node.left, ans)
traverse(node.right,ans)
ans.push(node.val)
end
ans = []
def traverse(node, ans)
if node != nil
traverse(node.left, ans)
traverse(node.right, ans)
ans.push(node.val)
end
traverse(root,ans)
return ans
end
traverse(root, ans)
return ans
end

View file

@ -1,23 +1,23 @@
# Definition for a binary tree node.
# class TreeNode
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# end
# @param {TreeNode} root
# @return {Integer[]}
def preorder_traversal(root)
ans = []
def traverse(node, ans)
if node != nil
ans.push(node.val)
traverse(node.left, ans)
traverse(node.right,ans)
end
ans = []
def traverse(node, ans)
if node != nil
ans.push(node.val)
traverse(node.left, ans)
traverse(node.right, ans)
end
traverse(root,ans)
return ans
end
traverse(root, ans)
return ans
end