java.lang.Object
g2101_2200.s2154_keep_multiplying_found_values_by_two.Solution

public class Solution extends Object
2154 - Keep Multiplying Found Values by Two.<p>Easy</p> <p>You are given an array of integers <code>nums</code>. You are also given an integer <code>original</code> which is the first number that needs to be searched for in <code>nums</code>.</p> <p>You then do the following steps:</p> <ol> <li>If <code>original</code> is found in <code>nums</code>, <strong>multiply</strong> it by two (i.e., set <code>original = 2 * original</code>).</li> <li>Otherwise, <strong>stop</strong> the process.</li> <li><strong>Repeat</strong> this process with the new number as long as you keep finding the number.</li> </ol> <p>Return <em>the <strong>final</strong> value of</em> <code>original</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [5,3,6,1,12], original = 3</p> <p><strong>Output:</strong> 24</p> <p><strong>Explanation:</strong></p> <ul> <li> <p>3 is found in nums. 3 is multiplied by 2 to obtain 6.</p> </li> <li> <p>6 is found in nums. 6 is multiplied by 2 to obtain 12.</p> </li> <li> <p>12 is found in nums. 12 is multiplied by 2 to obtain 24.</p> </li> <li> <p>24 is not found in nums. Thus, 24 is returned.</p> </li> </ul> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [2,7,9], original = 4</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong></p> <ul> <li>4 is not found in nums.</li> </ul> <p>Thus, 4 is returned.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 1000</code></li> <li><code>1 <= nums[i], original <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • findFinalValue

      public int findFinalValue(int[] nums, int original)