-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path066-PlusOne.cs
32 lines (27 loc) · 851 Bytes
/
066-PlusOne.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//-----------------------------------------------------------------------------
// Runtime: 228ms
// Memory Usage: 30.1 MB
// Link: https://leetcode.com/submissions/detail/352820219/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
namespace LeetCode
{
public class _066_PlusOne
{
public int[] PlusOne(int[] digits)
{
var result = new List<int>();
var carry = 1;
var value = 0;
for (int i = digits.Length - 1; i >= 0; i--)
{
value = digits[i] + carry;
carry = value == 10 ? 1 : 0;
result.Insert(0, value % 10);
}
if (carry >= 1)
result.Insert(0, carry);
return result.ToArray();
}
}
}