3105. Longest Strictly Increasing or Strictly Decreasing Subarray Easy
1/**
2 * [3105] Longest Strictly Increasing or Strictly Decreasing Subarray
3 *
4 * You are given an array of integers nums. Return the length of the longest <span data-keyword="subarray-nonempty">subarray</span> of nums which is either <span data-keyword="strictly-increasing-array">strictly increasing</span> or <span data-keyword="strictly-decreasing-array">strictly decreasing</span>.
5 *
6 * <strong class="example">Example 1:
7 * <div class="example-block">
8 * Input: <span class="example-io">nums = [1,4,3,3,2]</span>
9 * Output: <span class="example-io">2</span>
10 * Explanation:
11 * The strictly increasing subarrays of nums are [1], [2], [3], [3], [4], and [1,4].
12 * The strictly decreasing subarrays of nums are [1], [2], [3], [3], [4], [3,2], and [4,3].
13 * Hence, we return 2.
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">nums = [3,3,3,3]</span>
18 * Output: <span class="example-io">1</span>
19 * Explanation:
20 * The strictly increasing subarrays of nums are [3], [3], [3], and [3].
21 * The strictly decreasing subarrays of nums are [3], [3], [3], and [3].
22 * Hence, we return 1.
23 * </div>
24 * <strong class="example">Example 3:
25 * <div class="example-block">
26 * Input: <span class="example-io">nums = [3,2,1]</span>
27 * Output: <span class="example-io">3</span>
28 * Explanation:
29 * The strictly increasing subarrays of nums are [3], [2], and [1].
30 * The strictly decreasing subarrays of nums are [3], [2], [1], [3,2], [2,1], and [3,2,1].
31 * Hence, we return 3.
32 * </div>
33 *
34 * Constraints:
35 *
36 * 1 <= nums.length <= 50
37 * 1 <= nums[i] <= 50
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray/
43// discuss: https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn longest_monotonic_subarray(nums: Vec<i32>) -> i32 {
49 0
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_3105() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.