# 66.Plus One

**66.Plus One**

难度:Easy

> 给定一个由整数组成的非空数组所表示的非负整数，在该数的基础上加一。 最高位数字存放在数组的首位， 数组中每个元素只存储一个数字。 你可以假设除了整数 0 之外，这个整数不会以零开头。

```
示例 1:

输入: [1,2,3]
输出: [1,2,4]
解释: 输入数组表示数字 123。
示例 2:

输入: [4,3,2,1]
输出: [4,3,2,2]
解释: 输入数组表示数字 4321。
```

代码如下：

```
class Solution {
public:
    vector<int> plusOne(vector<int>& digits) {
        int flag=1;
        int set=0;
        int len=digits.size();
        while(flag)
        {
            --len;
            if(digits[len]!=9)
            {
                digits[len]+=1;
                flag=0;
            }
            else 
            {
                digits[len]=0;
                if(len==0)
                {
                    set=1;
                    break;
                }
            }
        }
        cout<<set<<endl;
        if(set)
        {
            len=digits.size();
            vector<int>tmp(len+1,0);
            tmp[0]=1;
            for(int i=1;i<=len;i++)
                tmp[i]=digits[i-1];
            return tmp;
        }
        return digits;
    }
};
```


---

# 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://dfine.gitbook.io/leetcode/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.
