446. Arithmetic Slices II - Subsequence Hard
1/**
2 * [446] Arithmetic Slices II - Subsequence
3 *
4 * Given an integer array nums, return the number of all the arithmetic subsequences of nums.
5 * A sequence of numbers is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.
6 *
7 * For example, [1, 3, 5, 7, 9], [7, 7, 7, 7], and [3, -1, -5, -9] are arithmetic sequences.
8 * For example, [1, 1, 2, 5, 7] is not an arithmetic sequence.
9 *
10 * A subsequence of an array is a sequence that can be formed by removing some elements (possibly none) of the array.
11 *
12 * For example, [2,5,10] is a subsequence of [1,2,1,<u>2</u>,4,1,<u>5</u>,<u>10</u>].
13 *
14 * The test cases are generated so that the answer fits in 32-bit integer.
15 *
16 * Example 1:
17 *
18 * Input: nums = [2,4,6,8,10]
19 * Output: 7
20 * Explanation: All arithmetic subsequence slices are:
21 * [2,4,6]
22 * [4,6,8]
23 * [6,8,10]
24 * [2,4,6,8]
25 * [4,6,8,10]
26 * [2,4,6,8,10]
27 * [2,6,10]
28 *
29 * Example 2:
30 *
31 * Input: nums = [7,7,7,7,7]
32 * Output: 16
33 * Explanation: Any subsequence of this array is arithmetic.
34 *
35 *
36 * Constraints:
37 *
38 * 1 <= nums.length <= 1000
39 * -2^31 <= nums[i] <= 2^31 - 1
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/arithmetic-slices-ii-subsequence/
45// discuss: https://leetcode.com/problems/arithmetic-slices-ii-subsequence/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn number_of_arithmetic_slices(nums: Vec<i32>) -> i32 {
51 0
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_446() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.