The gray code is a binary numeral system where two successive values differ in only one bit.
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.
For example, given n = 2, return <code>[0,1,3,2]</code>. Its gray code sequence
is:
Note:
For a given n, a gray code sequence is not uniquely defined.
For example, <code>[0,2,3,1]</code> is also a valid gray code sequence according to the above definition.
For now, the judge is able to judge based on one instance of gray code sequence. Sorry about that.
//整數n 的格雷碼是n ^ (n/2)。
vector的reserve()與resize()函數差别:
vector 的reserve增加了vector的capacity,可是它的size沒有改變!
而resize改變了vector的capacity同一時候也增加了它的size!
reserve是容器預留白間。但在空間内不真正建立元素對象,是以在沒有增加新的對象之前,不能引用容器内的元素。增加新的元素時,要調用push_back()/insert()函數。
resize是改變容器的大小,且在建立對象,是以,調用這個函數之後。就能夠引用容器内的對象了,是以當增加新的元素時,用operator[]操作符,或者用疊代器來引用元素對象。此時再調用push_back()函數。是加在這個新的空間後面的。