Package g0301_0400.s0396_rotate_function
Class Solution
java.lang.Object
g0301_0400.s0396_rotate_function.Solution
396 - Rotate Function.<p>Medium</p>
<p>You are given an integer array <code>nums</code> of length <code>n</code>.</p>
<p>Assume <code>arr<sub>k</sub></code> to be an array obtained by rotating <code>nums</code> by <code>k</code> positions clock-wise. We define the <strong>rotation function</strong> <code>F</code> on <code>nums</code> as follow:</p>
<ul>
<li><code>F(k) = 0 * arr<sub>k</sub>[0] + 1 * arr<sub>k</sub>[1] + … + (n - 1) * arr<sub>k</sub>[n - 1].</code></li>
</ul>
<p>Return <em>the maximum value of</em> <code>F(0), F(1), ..., F(n-1)</code>.</p>
<p>The test cases are generated so that the answer fits in a <strong>32-bit</strong> integer.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [4,3,2,6]</p>
<p><strong>Output:</strong> 26</p>
<p><strong>Explanation:</strong></p>
<p>F(0) = (0 * 4) + (1 * 3) + (2 * 2) + (3 * 6) = 0 + 3 + 4 + 18 = 25</p>
<p>F(1) = (0 * 6) + (1 * 4) + (2 * 3) + (3 * 2) = 0 + 4 + 6 + 6 = 16</p>
<p>F(2) = (0 * 2) + (1 * 6) + (2 * 4) + (3 * 3) = 0 + 6 + 8 + 9 = 23</p>
<p>F(3) = (0 * 3) + (1 * 2) + (2 * 6) + (3 * 4) = 0 + 2 + 12 + 12 = 26</p>
<p>So the maximum value of F(0), F(1), F(2), F(3) is F(3) = 26.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [100]</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>1 <= n <= 10<sup>5</sup></code></li>
<li><code>-100 <= nums[i] <= 100</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxRotateFunction
public int maxRotateFunction(int[] nums)
-