题目:输出任意permutation使得List中的相同element的间距要>=minDistance 例1: 输入:[B, E, A, C, D, F, F],2 输出:[B, F, A, C, D, E, F] (两个F之间的间距为4大于2) 例2: 输入:[A, B, B],1 输出:[A, B, B] (两个B之间的间距为1) 例3: 输入:[A, B, B],2 输出:[B, A, B] (两个B之间的间距为2) 解题思路: 和Rerrange String的思路比较像 先按频率排序,然后每次取出频率最高的d个不同的放到result,然后把剩下的再排序,再放。。。。 一开始A3 B3 C1 D1 E1 (A3代表3个A) 找最大的三个:ABC 之后A2 B2 D1 E1 最大的三个加入:ABCABD 之后A1 B1 E1 ABCABDABE
Read full article from minDistance
No comments:
Post a Comment