Count permutations of a non-negative integer


  • 0

    Count the number of permutations of a non-negative integer:

    Example:

    Input: 112
    Output: 3. The permutations are 112, 121, 211.

    Input: 120
    Output: 4. The permutations are 120, 102, 210, 201. Note that number cannot start with leading 0.

    Input: 1213
    Output: 12.


  • 0

    Can we calculate the permutation in the following way :
    Input 112
    C(3,2) * C(1,1) = 3!/2!*1! = 3

    Input 120
    C(2,1) * C(2,1) * C(1,1) = 2*2 =4

    Input
    1213
    C(4,2) * C(2,1) * c(1,1) = 6*2 = 12

    Input 11001
    c(4,2)*c(3,3) = 4!/2!*2! = 6

    Result :
    1 1 0 0 1
    1 1 0 1 0
    1 1 1 0 0
    1 0 1 1 0
    1 0 1 0 1
    1 0 0 1 1


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.