We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2e0fdcf commit d70fe72Copy full SHA for d70fe72
1 file changed
Algorithms/LeetCode.Algorithms/LeetCode.Algorithms/P/Plus One.cs
@@ -0,0 +1,42 @@
1
+using System.Numerics;
2
+
3
+namespace LeetCode.Algorithms;
4
5
+public class Plus_One
6
+{
7
8
+ public int[] PlusOne(int[] digits)
9
+ {
10
+ if (digits.Length == 0)
11
+ return new int[0];
12
13
+ List<int> rDigits = digits.Reverse().ToList();
14
15
+ var hand = 1;
16
+ for (var i = 0; i < rDigits.Count; i++)
17
18
+ rDigits[i] = hand + rDigits[i];
19
+ hand = 0;
20
+ if (rDigits[i] >= 10)
21
22
+ hand = rDigits[i] / 10;
23
+ rDigits[i] = rDigits[i] % 10;
24
+ }
25
+ else
26
+ break;
27
28
+ if (hand > 0)
29
+ rDigits.Add(hand);
30
31
+ int[] arr = new int[rDigits.Count];
32
33
+ var j = 0;
34
+ for (var i = rDigits.Count - 1; i >= 0; i--)
35
36
+ arr[j] = rDigits[i];
37
+ j++;
38
39
40
+ return arr;
41
42
+}
0 commit comments