2154. Keep Multiplying Found Values by Two Easy

@problem@discussion
#Array#Hash Table#Sorting#Simulation



1/**
2 * [2154] Keep Multiplying Found Values by Two
3 *
4 * You are given an array of integers nums. You are also given an integer original which is the first number that needs to be searched for in nums.
5 * You then do the following steps:
6 * <ol>
7 * 	If original is found in nums, multiply it by two (i.e., set original = 2 * original).
8 * 	Otherwise, stop the process.
9 * 	Repeat this process with the new number as long as you keep finding the number.
10 * </ol>
11 * Return the final value of original.
12 *  
13 * Example 1:
14 * 
15 * Input: nums = [5,3,6,1,12], original = 3
16 * Output: 24
17 * Explanation: 
18 * - 3 is found in nums. 3 is multiplied by 2 to obtain 6.
19 * - 6 is found in nums. 6 is multiplied by 2 to obtain 12.
20 * - 12 is found in nums. 12 is multiplied by 2 to obtain 24.
21 * - 24 is not found in nums. Thus, 24 is returned.
22 * 
23 * Example 2:
24 * 
25 * Input: nums = [2,7,9], original = 4
26 * Output: 4
27 * Explanation:
28 * - 4 is not found in nums. Thus, 4 is returned.
29 * 
30 *  
31 * Constraints:
32 * 
33 * 	1 <= nums.length <= 1000
34 * 	1 <= nums[i], original <= 1000
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/keep-multiplying-found-values-by-two/
40// discuss: https://leetcode.com/problems/keep-multiplying-found-values-by-two/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn find_final_value(nums: Vec<i32>, original: i32) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_2154() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.