Class Solution

java.lang.Object
g0001_0100.s0066_plus_one.Solution

public class Solution extends Object
66 - Plus One.<p>Easy</p> <p>You are given a <strong>large integer</strong> represented as an integer array <code>digits</code>, where each <code>digits[i]</code> is the <code>ith</code> digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading <code>0</code>&rsquo;s.</p> <p>Increment the large integer by one and return <em>the resulting array of digits</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> digits = [1,2,3]</p> <p><strong>Output:</strong> [1,2,4]</p> <p><strong>Explanation:</strong> The array represents the integer 123. Incrementing by one gives 123 + 1 = 124. Thus, the result should be [1,2,4].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> digits = [4,3,2,1]</p> <p><strong>Output:</strong> [4,3,2,2]</p> <p><strong>Explanation:</strong> The array represents the integer 4321. Incrementing by one gives 4321 + 1 = 4322. Thus, the result should be [4,3,2,2].</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> digits = [0]</p> <p><strong>Output:</strong> [1]</p> <p><strong>Explanation:</strong> The array represents the integer 0. Incrementing by one gives 0 + 1 = 1. Thus, the result should be [1].</p> <p><strong>Example 4:</strong></p> <p><strong>Input:</strong> digits = [9]</p> <p><strong>Output:</strong> [1,0]</p> <p><strong>Explanation:</strong> The array represents the integer 9. Incrementing by one gives 9 + 1 = 10. Thus, the result should be [1,0].</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= digits.length <= 100</code></li> <li><code>0 <= digits[i] <= 9</code></li> <li><code>digits</code> does not contain any leading <code>0</code>&rsquo;s.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • plusOne

      public int[] plusOne(int[] digits)