Easy C++ Solution | O(n) Time Complexity | Just using one for loop
Intuition\n Describe your first thoughts on how to solve this problem. \nWe will see the last element as we have to add 1 to it.\n\n# Approach\n Describe your a
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe will see the last element as we have to add 1 to it.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Start traversing through end.\n2. If last element is not 9, just add 1 to it and return the vector.\n3. If last element is 9, make it zero, move ahead (reverse order).\n4. Now if this element is not 9, add 1 to it and return vector, otherwise if it is also 9, make it zero and repeat the 3rd and 4th steps.\n5. Now, if the number is 999, then we have to make it 1000 (999 + 1 = 1000). So, push 0 to the last of our vector (0,0,0) so that it becomes (0,0,0,0) and make first element \'1\' => 1000.\n6. This is how we add 1 to the number!\n7. Thank You, Don\'t forget to upvote :)\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> plusOne(vector<int>& v) {\n        int n = v.size();\n\n        for(int i=n-1; i>=0; i--){\n            if(v[i]<9){\n                ++v[i];\n                return v;\n            }else{\n                v[i] = 0;\n            }\n        }\n\n        v.push_back(0);      // to handle \'999\' => 999 + 1 = 1000\n        v[0] = 1;\n        return v;\n    }\n};\n```
['C++']