挑战说明
甲单调序列是数字的序列[a1, a2, ..., an]
,使得
a1 <= a2 <= ... <= an
或a1 >= a2 >= ... >= an
。[1, 3, 3, 7, 9, 13, 13, 100]
是单调(不递减)的子序列,以及[9, 4, 4, 3, 0, -10, -12]
(此不递增),但[1, 3, 6, 9, 8]
不是。给定一个整数列表(以任何合理的格式),输出最小的数字N
,以便可以将这些整数的序列拆分为N
单调序列。
例子
[1, 3, 7, 5, 4, 2] -> [[1, 3, 7], [5, 4, 2]] -> 2
[1, 2, 3, 4, 5, 6] -> [1, 2, 3, 4, 5, 6] -> 1
[3, 1, 5, 5, 6] -> [[3, 1], [5, 5, 6]] -> 2
[4, 6, 8, 9, 1, 6] -> [[4, 6, 8, 9], [1, 6]] -> 2
[3, 3, 3, 3] -> [[3, 3, 3, 3]] -> 1
[7] -> [[7]] -> 1
[] -> [] -> anything (you don't actually have to handle an empty list case)
[1, 3, 2, -1, 6, 9, 10, 2, 1, -12] -> [[1, 3], [2, -1], [6, 9, 10], [2, 1, -12]] -> 4
[4,4,8,8,1,4,5] -> 2
0 / undefined
,听起来应该为0或undefined
以我们的语言表示,但是从您对Jonathan Allan的Jelly答案的评论来看,它的undefined
意思是anything
... ...是哪一个? ?在第二种情况下,我建议写anything
而不是undefined