Permutation Index II

题目描述

Given a permutation which may contain repeated numbers, find its index in all the permutations of these numbers, which are ordered in lexicographical order. The index begins at 1.

解题方法

像排列组合的去重一样,要除去每个重复数字次数的阶乘,所以对于每一个element i,在数右边比它小的数的个数的时候, 还要用一个hashmap来存每个数字出现过的次数

Solution

Reference