Permutations of capitalization

前端 未结 8 652
生来不讨喜
生来不讨喜 2020-12-21 01:24

I want to build a list containing every possible permutation of capitalization of a word. so it would be

List permutate(string word)
{
    List         


        
8条回答
  •  抹茶落季
    2020-12-21 02:06

    Use bitwise operations. For a word of length N you need an integer type represented by N bits. If the word is longer - split it. Iterate through values from 0 to 2N-1 and examine each bit from 0 to N-1. If the bit is 1 - upcase ( Char.ToUpper() ) the letter corresponding to that bit.

    This approach is better that a recursive algorithm since it is not prone to stack overflows on long words.

提交回复
热议问题