New to LeetCode, not sure how the learning module examples work - basic help

Hi there! I am looking for some basic help around the topic of doing examples in the learning modules. This is the example:


Example:

Input: [1,null,2,3]
   1
    \
     2
    /
   3

Output: [1,2,3]

Follow up: Recursive solution is trivial, could you do it iteratively?

and the code it starts with:

# class TreeNode
#     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)
    
end

I'm unsure if I need to uncomment out the class TreeNode code, and what the actual test case gets passed in, or whether or not the test itself creates an instance variable root of class TreeNode. Lastly, do I have to call the method, or does the internal test do that for me?

Sorry for the beginner question, just trying to understand how the LeetCode system works!

Comments (1)