bits manipulation tricks is cool to solve these kind of questions. On Sun, Dec 26, 2010 at 3:27 PM, Praveen Baskar <praveen200...@gmail.com>wrote:
> Your Second approach is cool :) > > On Wed, Dec 22, 2010 at 1:06 PM, juver++ <avpostni...@gmail.com> wrote: > >> Use bits manipulation tricks. >> 1. There is a way to remove a group of consecutive 1's from the right: A = >> n & (n + 1). Then check if A==0 then OK. >> 2. Second approach: B=n+1, check if B & (B-1) (this checks if B is a power >> of 2, so it contains only 1 set bit) is zero then OK. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > B. Praveen > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- What are we to be? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.