題目
Given a fixed-length integer array arr, duplicate each occurrence of zero, shifting the remaining elements to the right.
Note that elements beyond the length of the original array are not written. Do the above modifications to the input array in place and do not return anything.
複製每個出現的零,將剩餘的值向右移動
不能寫入超出原始陣列長度,對原始陣列修改,不返回任何內容。
Example 1
1 | Input: arr = [1,0,2,3,0,4,5,0] |
Example 2
1 | Input: arr = [1,2,3] |
Constraints:
- 1 <= arr.length <= 104
- 0 <= arr[i] <= 9
我的解題
1 | class Solution { |