413. Arithmetic Slices Medium

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [413] Arithmetic Slices
3 *
4 * An integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.
5 * 
6 * 	For example, [1,3,5,7,9], [7,7,7,7], and [3,-1,-5,-9] are arithmetic sequences.
7 * 
8 * Given an integer array nums, return the number of arithmetic subarrays of nums.
9 * A subarray is a contiguous subsequence of the array.
10 *  
11 * Example 1:
12 * 
13 * Input: nums = [1,2,3,4]
14 * Output: 3
15 * Explanation: We have 3 arithmetic slices in nums: [1, 2, 3], [2, 3, 4] and [1,2,3,4] itself.
16 * 
17 * Example 2:
18 * 
19 * Input: nums = [1]
20 * Output: 0
21 * 
22 *  
23 * Constraints:
24 * 
25 * 	1 <= nums.length <= 5000
26 * 	-1000 <= nums[i] <= 1000
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/arithmetic-slices/
32// discuss: https://leetcode.com/problems/arithmetic-slices/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn number_of_arithmetic_slices(nums: Vec<i32>) -> i32 {
38        0
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_413() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.