Skip to content

Commit d66451f

Browse files
committedJan 5, 2023
Add solution #2154
1 parent dc86c06 commit d66451f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@
289289
2099|[Find Subsequence of Length K With the Largest Sum](./2099-find-subsequence-of-length-k-with-the-largest-sum.js)|Medium|
290290
2114|[Maximum Number of Words Found in Sentences](./2114-maximum-number-of-words-found-in-sentences.js)|Easy|
291291
2129|[Capitalize the Title](./2129-capitalize-the-title.js)|Easy|
292+
2154|[Keep Multiplying Found Values by Two](./2154-keep-multiplying-found-values-by-two.js)|Easy|
292293
2244|[Minimum Rounds to Complete All Tasks](./2244-minimum-rounds-to-complete-all-tasks.js)|Medium|
293294
2427|[Number of Common Factors](./2427-number-of-common-factors.js)|Easy|
294295

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* 2154. Keep Multiplying Found Values by Two
3+
* https://leetcode.com/problems/keep-multiplying-found-values-by-two/
4+
* Difficulty: Easy
5+
*
6+
* You are given an array of integers nums. You are also given an integer original which
7+
* is the first number that needs to be searched for in nums.
8+
*
9+
* You then do the following steps:
10+
* If original is found in nums, multiply it by two (i.e., set original = 2 * original).
11+
* Otherwise, stop the process.
12+
* Repeat this process with the new number as long as you keep finding the number.
13+
* Return the final value of original.
14+
*/
15+
16+
/**
17+
* @param {number[]} nums
18+
* @param {number} original
19+
* @return {number}
20+
*/
21+
var findFinalValue = function(nums, original) {
22+
return nums
23+
.sort((a, b) => a - b)
24+
.reduce((result, n) => result *= n === result ? 2 : 1, original);
25+
};

0 commit comments

Comments
 (0)
Please sign in to comment.