Increment a Large Integer Represented as an Array - ✅C solution || Easy to understand
Intuition\n\n\n\nWe need to increment a large integer represented as an integer array by 1. One way to approach this problem is to iterate through the array fro
# Intuition\n![iages.jpeg](https://assets.leetcode.com/users/images/886eabe7-02a5-4004-a712-457c4c886152_1680957173.8068066.jpeg)\n\n\n***We need to increment a large integer represented as an integer array by 1. One way to approach this problem is to iterate through the array from right to left and add 1 to each digit until we find a digit that is less than 10. If we reach the leftmost digit and it needs to be set to 0, we need to create a new array with one extra element and set the first element to 1.***\n\n# Approach\n\n***We will implement the approach mentioned in the intuition. We will start iterating through the array from right to left and increment each digit by 1. If the resulting digit is less than 10, we can return the modified array. Otherwise, we will set the current digit to 0 and continue with the next digit.If we reach the leftmost digit and it needs to be set to 0, we will create a new array with one extra element and set the first element to 1. We will return this new array as the result.***\n\n# Complexity\n- Time complexity:\n- \n       O(N)\n\n- Space complexity:\n- \n       O(1)\n       \n\n# Code\n```\nint* plusOne(int* digits, int digitsSize, int* returnSize) {\n    for (int i = digitsSize - 1; i >= 0; i--) {\n        digits[i]++;\n        if (digits[i] < 10) {\n            *returnSize = digitsSize;\n            return digits;\n        }\n        digits[i] = 0;\n    }\n    int* result = (int*)malloc((digitsSize + 1) * sizeof(int));\n    result[0] = 1;\n    for (int i = 1; i <= digitsSize; i++) {\n        result[i] = 0;\n    }\n    *returnSize = digitsSize + 1;\n    return result;\n}\n\n```
['Array', 'Math', 'C']