ARTS Week 22


This week’s LeetCode problem is 297. Serialize and Deserialize Binary Tree

Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work. You just need to ensure that a binary tree can be serialized to a string and this string can be deserialized to the original tree structure.

Clarification: The input/output format is the same as how LeetCode serializes a binary tree. You do not necessarily need to follow this format, so please be creative and come up with different approaches yourself.

The serialized result of the binary tree adopts the way of preorder traversal.

  • When serializing, first determine whether the current node is empty. If it is empty, record null. If it is not empty, add the value of the root and the separator (',') first, and then recursively process the current node. The left subtree and right subtree of the node.
  • When deserializing, first determine whether the current value is null, if it is null, return null, if it is not null, first construct the root node with the current value, remove the first element, and then build the left subtree and right subtree of the node in turn.


This week’s Review is for the following article: How to squash and rebase in git

The English article of this week’s Review is: How to use squash and rebase in git

The author details the process of using squash and rebase, first you need to backup a branch to try:

Then check the log to find the id of the latest commit that doesn’t belong to you, don’t forget to copy it

Then start the rebase operation, replacing the content after -i with the commit id you just found

Mark commits to squash (squash) by preceding all but the first commit with an "s" instead of "pick". Then save and close, and wait for a new text editor prompt to pop up to enter your commit information.

Use git status to check for any problems.

Next, the author merges all commits into the main branch, making sure that the local main branch is up to date

Next, perform the rebase operation, first switch the branch and then rebase

After fixing the git conflicts that occurred, stage the following files:

Then continue to complete the rebase:

Finally submit commit, please check that the branch is your branch first!

If something goes wrong along the way, you also have a backup branch you can restore from, or use git rebase --abort to abort an ongoing rebase.

Why squash before rebase? rebase needs to resolve conflicts at most once after squashing commits with squash, and when your company/organization/project requires you not to squash, then don't use squash.


Notes on using the macro definition, the macro definition is a direct replacement, not the result of the calculation. The sample code is as follows:

The result of running the program is as follows:


In the next few weeks, I plan to take the time to seriously and systematically review the basic data structures and algorithms to prepare for the next LeetCode topic.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store



A programmer. Share knowledge of programming, operating system, Linux kernel, and reading, thinking etc. Let us maintain a beginner mend and grow together!