Approach
# 先排序再找original可能的值
Sort first, then determine the possible values of the original.
Time Complexity
# n = length of nums
O(nlogn)
Space Complexity
O(1)
Code
class Solution {
public:
int findFinalValue(vector<int>& nums, int original) {
sort(nums.begin(), nums.end());
for (int i = 0 ; i < nums.size() ; i++) {
if (nums[i] == original) {
original *= 2;
}
else if (nums[i] >= original) {
break;
}
}
return original;
}
};