Skip to main content

13.1 Data Structure Introduction

As an upgraded version of the (single) linked list, the trees we commonly encounter are typically binary trees, where each node has at most two child nodes. Unless otherwise specified, trees are assumed to have no circular structures. LeetCode's default representation of trees is as follows:

struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

It can be seen that the primary difference compared to a linked list is the addition of a pointer for a second child node.