Class Solution
java.lang.Object
g2001_2100.s2012_sum_of_beauty_in_the_array.Solution
2012 - Sum of Beauty in the Array.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. For each index <code>i</code> (<code>1 <= i <= nums.length - 2</code>) the <strong>beauty</strong> of <code>nums[i]</code> equals:</p>
<ul>
<li><code>2</code>, if <code>nums[j] < nums[i] < nums[k]</code>, for <strong>all</strong> <code>0 <= j < i</code> and for <strong>all</strong> <code>i < k <= nums.length - 1</code>.</li>
<li><code>1</code>, if <code>nums[i - 1] < nums[i] < nums[i + 1]</code>, and the previous condition is not satisfied.</li>
<li><code>0</code>, if none of the previous conditions holds.</li>
</ul>
<p>Return <em>the <strong>sum of beauty</strong> of all</em> <code>nums[i]</code> <em>where</em> <code>1 <= i <= nums.length - 2</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,2,3]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> For each index i in the range 1 <= i <= 1: - The beauty of nums[1] equals 2.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [2,4,6,4]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> For each index i in the range 1 <= i <= 2:</p>
<ul>
<li>
<p>The beauty of nums[1] equals 1.</p>
</li>
<li>
<p>The beauty of nums[2] equals 0.</p>
</li>
</ul>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> nums = [3,2,1]</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> For each index i in the range 1 <= i <= 1: - The beauty of nums[1] equals 0.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>3 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
sumOfBeauties
public int sumOfBeauties(int[] nums)
-