We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fa2e731 commit 7195871Copy full SHA for 7195871
src/easy/symmetric_tree.rs
@@ -55,6 +55,22 @@ pub fn is_symmetric(root: Option<Rc<RefCell<TreeNode>>>) -> bool {
55
56
}
57
58
+/*
59
+ Algorithm - BFS
60
+
61
+ 1. Push root node twice into queue
62
+ 2. Pop two nodes from queue
63
+ 3. If both nodes are None, continue
64
+ 4. If one of the nodes is None, return false
65
+ 5. If both nodes are not None, check if their values are equal
66
+ 6. Push left child of first node and right child of second node into queue
67
+ 7. Push right child of first node and left child of second node into queue
68
+ 8. Repeat steps 2-7 until queue is empty
69
70
+ Time: O(n)
71
+ Space: O(n)
72
73
+ */
74
75
#[cfg(test)]
76
mod tests {
0 commit comments