mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
42 lines
2.0 KiB
HTML
42 lines
2.0 KiB
HTML
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> representing the strength of some heroes. The<b> power</b> of a group of heroes is defined as follows:</p>
|
||
|
||
<ul>
|
||
<li>Let <code>i<sub>0</sub></code>, <code>i<sub>1</sub></code>, ... ,<code>i<sub>k</sub></code> be the indices of the heroes in a group. Then, the power of this group is <code>max(nums[i<sub>0</sub>], nums[i<sub>1</sub>], ... ,nums[i<sub>k</sub>])<sup>2</sup> * min(nums[i<sub>0</sub>], nums[i<sub>1</sub>], ... ,nums[i<sub>k</sub>])</code>.</li>
|
||
</ul>
|
||
|
||
<p>Return <em>the sum of the <strong>power</strong> of all <strong>non-empty</strong> groups of heroes possible.</em> Since the sum could be very large, return it <strong>modulo</strong> <code>10<sup>9 </sup>+ 7</code>.</p>
|
||
|
||
<p> </p>
|
||
<p><strong class="example">Example 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>Input:</strong> nums = [2,1,4]
|
||
<strong>Output:</strong> 141
|
||
<strong>Explanation:</strong>
|
||
1<sup>st</sup> group: [2] has power = 2<sup>2</sup> * 2 = 8.
|
||
2<sup>nd</sup> group: [1] has power = 1<sup>2</sup> * 1 = 1.
|
||
3<sup>rd</sup> group: [4] has power = 4<sup>2</sup> * 4 = 64.
|
||
4<sup>th</sup> group: [2,1] has power = 2<sup>2</sup> * 1 = 4.
|
||
5<sup>th</sup> group: [2,4] has power = 4<sup>2</sup> * 2 = 32.
|
||
6<sup>th</sup> group: [1,4] has power = 4<sup>2</sup> * 1 = 16.
|
||
7<sup>th</sup> group: [2,1,4] has power = 4<sup>2</sup> * 1 = 16.
|
||
The sum of powers of all groups is 8 + 1 + 64 + 4 + 32 + 16 + 16 = 141.
|
||
|
||
</pre>
|
||
|
||
<p><strong class="example">Example 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>Input:</strong> nums = [1,1,1]
|
||
<strong>Output:</strong> 7
|
||
<strong>Explanation:</strong> A total of 7 groups are possible, and the power of each group will be 1. Therefore, the sum of the powers of all groups is 7.
|
||
</pre>
|
||
|
||
<p> </p>
|
||
<p><strong>Constraints:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||
<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
||
</ul>
|