给定一个正整数列表,编写代码,查找最长的连续子列表的长度,该子列表正在增加(不是严格的)。这是最长的子列表,因此每个元素都大于或等于最后一个元素。
例如,如果输入是:
增加时间最长的子列表将是[1,1,4,5],因此您将输出4。
您的答案将通过将其源作为字节列表,然后找到该列表中最长的增长子列表的长度来得分。一个较低的分数是目标。连接被打破,有利于程序的整体字节更少。
发布于 2018-10-07 15:42:36
d0< ~Y'w)X>sQ投入可以是:
MATL使用ASCII编码。以上代码的编码点如下
100, 48, 60, 32, 126, 89, 39, 119, 41, 88, 62, 115, 81d % Implicit input. Consecutive differences (of code points)
0< % Less than 0? Element-wise. Gives true or false
% Space. This does nothing; but it breaks an increasing substring
~ % Negate
Y' % Run-length encoding. Gives array of true/false and array of lengths
w % Swap
) % Index. This keeps only lenghts of runs of true values
X> % Maximum. Gives empty array if input is empty
s % Sum. This turns empty array into 0
Q % Add 1. Implicit display发布于 2018-10-07 16:33:48
-h,6字节,得分2不要认为1的分数是可能的。也应该使用字符串和字符数组。
ò>¹mÊn包含试试看的测试用例是解决方案的特征代码。
ò :Partition after each integer
> : That's greater than the integer that follows it
¹ :End partition
m :Map
Ê : Length
n :Sort
:Implicitly output last elementhttps://codegolf.stackexchange.com/questions/173586
复制相似问题