Skip to content

Commit 8a9544c

Browse files
chore: add LeetCode daily solution
1 parent 2d7d377 commit 8a9544c

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Keep Multiplying Found Values by Two (Easy)
2+
3+
**Problem ID:** 2154
4+
**Date:** 2025-11-19
5+
**Link:** https://leetcode.com/problems/keep-multiplying-found-values-by-two/
6+
7+
## Approach
8+
9+
To solve the problem "Keep Multiplying Found Values by Two," we will adopt a straightforward iterative approach that utilizes a set for efficient lookups.
10+
11+
### Main Idea:
12+
The core idea is to repeatedly check if the current value of `original` exists in the given array `nums`. If it does, we multiply `original` by two and continue checking. If it does not exist, we stop the process and return the current value of `original`.
13+
14+
### Steps:
15+
1. **Convert `nums` to a Set**: Since we need to perform multiple membership checks, converting the list `nums` to a set will allow for O(1) average time complexity for lookups.
16+
17+
2. **Iterate Until Not Found**: Initialize a loop that continues as long as `original` is found in the set of `nums`. Inside the loop, if `original` is found, multiply it by two.
18+
19+
3. **Return Result**: Once `original` is no longer found in `nums`, exit the loop and return the final value of `original`.
20+
21+
### Data Structures:
22+
- **Set**: We will use a set to store the elements of `nums` for efficient membership testing.
23+
24+
### Complexity:
25+
- **Time Complexity**: O(n) for converting the list to a set, where n is the length of `nums`. The while loop will run at most log(1000) times (since `original` can double until it exceeds 1000), resulting in an overall time complexity of O(n).
26+
- **Space Complexity**: O(n) for storing the elements of `nums` in a set.
27+
28+
This approach is efficient given the constraints and ensures that we can quickly determine whether to continue multiplying `original`.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int findFinalValue(int[] nums, int original) {
3+
Set<Integer> numSet = new HashSet<>();
4+
for (int num : nums) {
5+
numSet.add(num);
6+
}
7+
8+
while (numSet.contains(original)) {
9+
original *= 2;
10+
}
11+
12+
return original;
13+
}
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var findFinalValue = function(nums, original) {
2+
const numSet = new Set(nums);
3+
while (numSet.has(original)) {
4+
original *= 2;
5+
}
6+
return original;
7+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution:
2+
def findFinalValue(self, nums: List[int], original: int) -> int:
3+
num_set = set(nums)
4+
while original in num_set:
5+
original *= 2
6+
return original

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,4 @@ Through completing the Blind 75 and NeetCode 150, you will have mastered:
283283
- 2025-11-16 — [Number of Substrings With Only 1s](https://leetcode.com/problems/number-of-substrings-with-only-1s/) (Medium) → `Medium/2025-11-16-1513-Number-of-Substrings-With-Only-1s`
284284
- 2025-11-17 — [Check If All 1's Are at Least Length K Places Away](https://leetcode.com/problems/check-if-all-1s-are-at-least-length-k-places-away/) (Easy) → `Easy/2025-11-17-1437-Check-If-All-1-s-Are-at-Least-Length-K-Places-Away`
285285
- 2025-11-18 — [1-bit and 2-bit Characters](https://leetcode.com/problems/1-bit-and-2-bit-characters/) (Easy) → `Easy/2025-11-18-717-1-bit-and-2-bit-Characters`
286+
- 2025-11-19 — [Keep Multiplying Found Values by Two](https://leetcode.com/problems/keep-multiplying-found-values-by-two/) (Easy) → `Easy/2025-11-19-2154-Keep-Multiplying-Found-Values-by-Two`

0 commit comments

Comments
 (0)