题目浅析

  • 想查看原题可以点击题目链接

  • 简单地说,就是给一个数组,现在可以用数组的开始的一个的数字作为起点(这个是定值,不是位置),对后续比该数字大的进行“解锁”,求将所有数字解锁的排列方案。

思路分享

代码解答(强烈建议自行解答后再看)

  • 参考题解
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution:
def countPermutations(self, complexity: List[int]) -> int:
root = complexity[0]
complexity.sort()
MOD = 1_000_000_007
# print(root, complexity)
# print(root > complexity[0])
# print(root == complexity[1])
if root > complexity[0] or root == complexity[1]:
return 0
ans = 1
for i in range(1, len(complexity)):
# print(ans)
ans = (ans * i) % MOD
return ans