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/3300-3399/3379.Transformed Array/README_EN.md
+25-11Lines changed: 25 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,11 @@ For each index <code>i</code> (where <code>0 <= i < nums.length</code>), p
80
80
81
81
<!-- solution:start -->
82
82
83
-
### Solution 1
83
+
### Solution 1: Simulation
84
+
85
+
We create a result array $\textit{ans}$. For each index, we move right or left $|nums[i]|$ steps based on whether $nums[i]$ is positive or negative, calculate the landing index, and assign the value at that index to $\textit{ans}[i]$.
86
+
87
+
The time complexity is $O(n)$ and the space complexity is $O(n)$, where $n$ is the length of the array $nums$.
84
88
85
89
<!-- tabs:start -->
86
90
@@ -89,11 +93,8 @@ For each index <code>i</code> (where <code>0 <= i < nums.length</code>), p
0 commit comments