Skip to content

Commit e1d66a7

Browse files
authored
Create keep-multiplying-found-values-by-two.cpp
1 parent e48746c commit e1d66a7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Time: O(n)
2+
// Space: O(n)
3+
4+
// hash table
5+
class Solution {
6+
public:
7+
int findFinalValue(vector<int>& nums, int original) {
8+
unordered_set<int> lookup(cbegin(nums), cend(nums));
9+
for (; lookup.count(original); original *= 2);
10+
return original;
11+
}
12+
};

0 commit comments

Comments
 (0)