2012. Sum of Beauty in the Array Medium
1/**
2 * [2012] Sum of Beauty in the Array
3 *
4 * You are given a 0-indexed integer array nums. For each index i (1 <= i <= nums.length - 2) the beauty of nums[i] equals:
5 *
6 * 2, if nums[j] < nums[i] < nums[k], for all 0 <= j < i and for all i < k <= nums.length - 1.
7 * 1, if nums[i - 1] < nums[i] < nums[i + 1], and the previous condition is not satisfied.
8 * 0, if none of the previous conditions holds.
9 *
10 * Return the sum of beauty of all nums[i] where 1 <= i <= nums.length - 2.
11 *
12 * Example 1:
13 *
14 * Input: nums = [1,2,3]
15 * Output: 2
16 * Explanation: For each index i in the range 1 <= i <= 1:
17 * - The beauty of nums[1] equals 2.
18 *
19 * Example 2:
20 *
21 * Input: nums = [2,4,6,4]
22 * Output: 1
23 * Explanation: For each index i in the range 1 <= i <= 2:
24 * - The beauty of nums[1] equals 1.
25 * - The beauty of nums[2] equals 0.
26 *
27 * Example 3:
28 *
29 * Input: nums = [3,2,1]
30 * Output: 0
31 * Explanation: For each index i in the range 1 <= i <= 1:
32 * - The beauty of nums[1] equals 0.
33 *
34 *
35 * Constraints:
36 *
37 * 3 <= nums.length <= 10^5
38 * 1 <= nums[i] <= 10^5
39 *
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/sum-of-beauty-in-the-array/
44// discuss: https://leetcode.com/problems/sum-of-beauty-in-the-array/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49 pub fn sum_of_beauties(nums: Vec<i32>) -> i32 {
50 0
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_2012() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.