Question: Provide and explain the Time Complexity function (T(n)) and the Time Complexity Order of the following code: class plusOne { public: vector plusOne(vector&
Provide and explain the Time Complexity function (T(n)) and the Time Complexity Order of the following code:
class plusOne {
public:
vector plusOne(vector& digits) {
int n = digits.size();
if(digits[n-1] != 9) {
digits[n-1] += 1;
} else {
for(int i=n-1; i>=0; i--) {
if(digits[i] == 9 && i != 0) {
digits[i] = 0;
}else if(digits[i] == 9 && i == 0) {
digits[i] = 0;
digits.insert(digits.begin(), 1);
}else{
digits[i] += 1;
break;
}
}
}
return digits;
}
};
Step by Step Solution
3.42 Rating (158 Votes )
There are 3 Steps involved in it
To analyze the time complexity of the provided code lets break it down step by step and determine th... View full answer
Get step-by-step solutions from verified subject matter experts
