Class Solution

java.lang.Object
g2201_2300.s2293_min_max_game.Solution

public class Solution extends Object
2293 - Min Max Game.<p>Easy</p> <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> whose length is a power of <code>2</code>.</p> <p>Apply the following algorithm on <code>nums</code>:</p> <ol> <li>Let <code>n</code> be the length of <code>nums</code>. If <code>n == 1</code>, <strong>end</strong> the process. Otherwise, <strong>create</strong> a new <strong>0-indexed</strong> integer array <code>newNums</code> of length <code>n / 2</code>.</li> <li>For every <strong>even</strong> index <code>i</code> where <code>0 <= i < n / 2</code>, <strong>assign</strong> the value of <code>newNums[i]</code> as <code>min(nums[2 * i], nums[2 * i + 1])</code>.</li> <li>For every <strong>odd</strong> index <code>i</code> where <code>0 <= i < n / 2</code>, <strong>assign</strong> the value of <code>newNums[i]</code> as <code>max(nums[2 * i], nums[2 * i + 1])</code>.</li> <li><strong>Replace</strong> the array <code>nums</code> with <code>newNums</code>.</li> <li><strong>Repeat</strong> the entire process starting from step 1.</li> </ol> <p>Return <em>the last number that remains in</em> <code>nums</code> <em>after applying the algorithm.</em></p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2022/04/13/example1drawio-1.png" alt="" /></p> <p><strong>Input:</strong> nums = [1,3,5,2,4,8,2,2]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> The following arrays are the results of applying the algorithm repeatedly.</p> <p>First: nums = [1,5,4,2]</p> <p>Second: nums = [1,4]</p> <p>Third: nums = [1]</p> <p>1 is the last remaining number, so we return 1.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [3]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> 3 is already the last remaining number, so we return 3.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 1024</code></li> <li><code>1 <= nums[i] <= 10<sup>9</sup></code></li> <li><code>nums.length</code> is a power of <code>2</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minMaxGame

      public int minMaxGame(int[] nums)