You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1.`splitter` is a way to distinguish the nodes in a string. To illustrate its importance, consider the following encoded string "banana". How did the tree structure look like before encoding? Without the `splitter`, you can't tell.
76
+
1.`separator` is a way to distinguish the nodes in a string. To illustrate its importance, consider the following encoded string "banana". How did the tree structure look like before encoding? Without the `separator`, you can't tell.
77
77
78
78
2.`encodedString` is the result of the encoding process. Returns a string representation of the tree. For example: "ba,nana,nil" represents a tree with two nodes - "ba" and "nana" - in pre-order format.
79
79
@@ -96,34 +96,36 @@ The implementation also added a few important details:
96
96
These details will shape your `decode` operation. Here's a possible implementation:
1. Takes a `String`, and uses `split` to partition the contents of `string` into an array based on the `","` character.
126
-
2. Takes any `Sequence` type and recursively creates a binary tree based on the rules declared in the encoding operation.
124
+
1. Takes a `String`, and uses `split` to partition the contents of `string` into an array based on the `separator` defined in the encoding step. The result is first `reversed`, and then mapped to a `String`. The `reverse` step is an optimization for the next function, allowing us to use `array.removeLast()` instead of `array.removeFirst()`.
125
+
126
+
2. Using an array as a stack, you recursively decode each node. The array keeps track of sequence of nodes and progress.
0 commit comments