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/3000-3099/3069.Distribute Elements Into Two Arrays I/README_EN.md
+83-4
Original file line number
Diff line number
Diff line change
@@ -53,24 +53,103 @@ Hence, the array result formed by concatenation is [5,3,4,8].
53
53
54
54
## Solutions
55
55
56
-
### Solution 1
56
+
### Solution 1: Simulation
57
+
58
+
We create two arrays `arr1` and `arr2`, which store the elements in `nums`. Initially, `arr1` only contains `nums[0]`, and `arr2` only contains `nums[1]`.
59
+
60
+
Then we traverse the elements of `nums` starting from index 2. If the last element of `arr1` is greater than the last element of `arr2`, we append the current element to `arr1`, otherwise we append it to `arr2`.
61
+
62
+
Finally, we append the elements in `arr2` to `arr1` and return `arr1`.
63
+
64
+
The time complexity is $O(n)$, and the space complexity is $O(n)$, where $n$ is the length of the array `nums`.
0 commit comments