classSolution{public:intkthGrammar(intn,intk){if(n==1)return0;if(k%2==1)returnkthGrammar(n-1,(k+1)/2)!=0;// the left nodereturnkthGrammar(n-1,k/2)==0;// the right node}};
123456789
classSolution{publicintkthGrammar(intn,intk){if(n==1)return0;if(k%2==1)returnkthGrammar(n-1,(k+1)/2)==0?0:1;// the left nodereturnkthGrammar(n-1,k/2)==0?1:0;// the right node}}