You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: solution/0000-0099/0066.Plus One/README_EN.md
+6
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,12 @@ Thus, the result should be [1,0].
50
50
51
51
## Solutions
52
52
53
+
**Solution 1: Simulation**
54
+
55
+
We start traversing from the last element of the array, add one to the current element, and then take the modulus by $10$. If the result is not $0$, it means that there is no carry for the current element, and we can directly return the array. Otherwise, the current element is $0$ and needs to be carried over. We continue to traverse the previous element and repeat the above operation. If we still haven't returned after traversing the array, it means that all elements in the array are $0$, and we need to insert a $1$ at the beginning of the array.
56
+
57
+
The time complexity is $O(n)$, where $n$ is the length of the array. Ignoring the space consumption of the answer, the space complexity is $O(1)$.
Copy file name to clipboardExpand all lines: solution/0200-0299/0283.Move Zeroes/README_EN.md
+8
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,14 @@
29
29
30
30
## Solutions
31
31
32
+
**Solution 1: Two Pointers**
33
+
34
+
We use two pointers $i$ and $j$, where pointer $i$ points to the end of the sequence that has been processed, and pointer $j$ points to the head of the sequence to be processed. Initially, $i=-1$.
35
+
36
+
Next, we traverse $j \in [0,n)$, if $nums[j] \neq 0$, then we swap the next number pointed by pointer $i$ with $nums[j]$, and move $i$ forward. Continue to traverse until $j$ reaches the end of the array, all non-zero elements of the array are moved to the front of the array in the original order, and all zero elements are moved to the end of the array.
37
+
38
+
The time complexity is $O(n)$, where $n$ is the length of the array $nums$. The space complexity is $O(1)$.
0 commit comments