Posts

Showing posts with the label Others

Serialized Tree Representation

A common approach to use a vector to represent a binary tree is serialized representation. All LeetCode OJ use this kind of representation: the serialization of a binary tree follows a level order traversal, where '#' signifies a path terminator where no node exists below. Here's an example:    1   / \  2   3     /    4     \      5 The above binary tree is serialized as "{1,2,3,#,#,4,#,#,5}". For testing propose, I tried to write transform functions between serialized tree and binary tree. Essentially we could use level order traversal. The following class provides several methods to implement this.

How to copy from vim to system clipboard?

Today I spent more than one hour to figure out this problem. Following steps might be helpful if you have similar problem. 1. Use :reg to check whether there is "+ register in your vim. If not, you need to update your vim. This happens if you got your vim from apt-get and did not install useful dependencies. See  this  for more details. 2. Once you have "+ register, you should be able to use  +"y instead of y when you are copying. 3. You can map a short key for this: for example, I use vmap <c-c> "+y (Ctrl+C for copy). Add this to .vimrc file. 4. Also, use set go+=a and set mouse+= a such that you could select the text using mouse and then click Ctrl+C to copy. Here  set go+=a  is used for avoiding the line number.