腾讯面试题--生成格雷码

vector<string> getGray(int n)
{
	vector<string> arr(int(pow(2,n)));

	if (n == 1)
	{
		arr[0] = "0";
		arr[1] = "1";
		return arr;
	}

	vector<string> last = getGray(n - 1);

	for (int i = 0; i < last.size();++i)
	{
		arr[i] = "0" + last[i];
		arr[arr.size() - i - 1] = "1" + last[i];
	}
	
	return arr;
}

你可能感兴趣的:(腾讯面试题--生成格雷码)