# 66. Plus One

{% hint style="info" %}
Only the last digit matter.

Judge the last digit can improve efficiency in some extend.
{% endhint %}

```python
class Solution:
    def plusOne(self, digits: List[int]) -> List[int]:
        digits[-1] += 1
        
        if digits[-1] != 10:
            return digits
        
        # if last digit is 10
        result = [0]
        result.extend(digits)
        for i in reversed(range(1, len(result))):
            if result[i] == 10:
                result[i] = 0
                result[i-1] += 1
        if result[0] == 0:
            return result[1:]
        else:
            return result
```

Time complexity = $$O(n)$$ , Space complexity = $$O(n)$$&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://r24zeng.gitbook.io/leetcode-notebook/bu-chong-2140-dao/66.-plus-one.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
