Skip to content

Commit e762400

Browse files
committed
2012. Sum of Beauty in the Array: RETRY
1 parent 4185249 commit e762400

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,3 +1516,4 @@ mod s2007_find_original_array_from_doubled_array;
15161516
mod s2008_maximum_earnings_from_taxi;
15171517
mod s2009_minimum_number_of_operations_to_make_array_continuous;
15181518
mod s2011_final_value_of_variable_after_performing_operations;
1519+
mod s2012_sum_of_beauty_in_the_array;
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
*/
41+
pub 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+
48+
impl Solution {
49+
pub fn sum_of_beauties(nums: Vec<i32>) -> i32 {
50+
0
51+
}
52+
}
53+
54+
// submission codes end
55+
56+
#[cfg(test)]
57+
mod tests {
58+
use super::*;
59+
60+
#[test]
61+
#[ignore]
62+
fn test_2012_example_1() {
63+
let nums = vec![1, 2, 3];
64+
65+
let result = 2;
66+
67+
assert_eq!(Solution::sum_of_beauties(nums), result);
68+
}
69+
70+
#[test]
71+
#[ignore]
72+
fn test_2012_example_2() {
73+
let nums = vec![2, 4, 6, 4];
74+
75+
let result = 1;
76+
77+
assert_eq!(Solution::sum_of_beauties(nums), result);
78+
}
79+
80+
#[test]
81+
#[ignore]
82+
fn test_2012_example_3() {
83+
let nums = vec![3, 2, 1];
84+
85+
let result = 0;
86+
87+
assert_eq!(Solution::sum_of_beauties(nums), result);
88+
}
89+
}

0 commit comments

Comments
 (0)