要解决这个问题,可以使用编程语言来实现。以下是使用 Python 语言的示例代码: ```python def count_unique_numbers(arr): unique_nums = set() increasing = True for num in arr: if increasing and (len(unique_nums) == 0 or num > list(unique_nums)[-1]): unique_nums.add(num) elif not increasing and (len(unique_nums) == 0 or num < list(unique_nums)[-1]): unique_nums.add(num) if len(unique_nums) > 1 and num < list(unique_nums)[-1]: increasing = False return len(unique_nums) # 测试示例 arr = [1, 2, 3, 4, 4, 3, 2, 1] print(count_unique_numbers(arr)) ``` 这个函数首先创建一个空的集合来存储唯一的数字。然后遍历数组,根据递增或递减的趋势添加数字到集合中。如果数字的趋势发生改变,更新标志。最后返回集合的大小,即不重复数字的个数。 [2024-08-28 00:42:55 | AI写代码神器 | 258点数解答]