101. Symmetric Tree

Leetcode

https://leetcode.com/problems/symmetric-tree/arrow-up-right

題目

Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).

Example 1:

Input: root = [1,2,2,3,4,4,3]
Output: true

Example 2:

Input: root = [1,2,2,null,3,null,3]
Output: false

解答

  • 方法一

Recursion

Runtime: 72 ms, faster than 90.41% of JavaScript online submissions for Symmetric Tree.

Memory Usage: 45.1 MB, less than 13.46% of JavaScript online submissions for Symmetric Tree.

  • 方法二

Iteration

Runtime: 85 ms, faster than 71.63% of JavaScript online submissions for Symmetric Tree.

Memory Usage: 44.8 MB, less than 32.01% of JavaScript online submissions for Symmetric Tree.

Last updated