Data Structure & Algorithm: Level-1 Problem #64. Permutation and Combination -2

Given a list of N (6 < N < 10) positive integers. Using one integer as the lead number and times 10N-1 to get a threshhold value. Find out how many integers K we can form so that K is more than the threshold value.

For example, for a list of [3, 3, 4, 5, 5, 6, 6], the length of this list is 7 so N is 7. Using 5 as lead number then the threshold value will be 5 * 10N-1 = 5,000,000.

Sample Input:

list = [4, 5, 5, 6, 6, 7, 7], threshold = 6,000,000

Sample Ouput:

320

Using the seven numbers 4, 5, 5, 6, 6, 7, 7 we can form 320 numbers which is more than 6,000,000.


数据结构和算法:初级练习题 #64 排列和组合 (二)


给定一组长度为N的数列,5 <= N <= 10, 数列里面都是正整数。使用其中的一个数值作为最高位,后面添加 N-1 个零得到一个限定值。计算用数列里的数字来排列,可以组成多少个大于限定值的数字。

譬如数列是 [3, 3, 4, 5, 5, 6, 6],用5作为最高位,后面加六个零得到限定值 5,000,000。

输入样例:

list = [4, 5, 5, 6, 6, 7, 7], threshold = 6,000,000

输出样例:

320

使用 4, 5, 5, 6, 6, 7, 7 这七个数字我们可以组成 320 个大于6,000,000的数字。


Python Solution

Number Threshold