Skip to content

Commit 5235fda

Browse files
committedJun 17, 2019
add 1089
1 parent b9d2a80 commit 5235fda

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed
 

Diff for: ‎README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,5 @@ LeetCode
419419
|1081|[Smallest Subsequence of Distinct Characters](https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/) | c | [c++](./src/1081-Smallest-Subsequence-of-Distinct-Characters/1081.cpp) |[python](./src/1081-Smallest-Subsequence-of-Distinct-Characters/1081.py)|||Medium|
420420
|1085|[Sum of Digits in the Minimum Number](https://leetcode.com/contest/biweekly-contest-2/problems/sum-of-digits-in-the-minimum-number/) | c | [c++](./src/1085-Sum-of-Digits-in-the-Minimum-Number/1085.cpp) |[python](./src/1085-Sum-of-Digits-in-the-Minimum-Number/1085.py)|||Easy|
421421
|1086|[High Five](https://leetcode.com/contest/biweekly-contest-2/problems/high-five/) | c | [c++](./src/1086-High-Five/1086.cpp) |[python](./src/1086-High-Five/1086.py)|||Easy|
422-
|1087|[Brace Expansion](https://leetcode.com/contest/biweekly-contest-2/problems/brace-expansion/) | c | [c++](./src/1087-Brace-Expansion/1087.cpp) |[python](./src/1087-Brace-Expansion/1087.py)|||Medium|
422+
|1087|[Brace Expansion](https://leetcode.com/contest/biweekly-contest-2/problems/brace-expansion/) | c | [c++](./src/1087-Brace-Expansion/1087.cpp) |[python](./src/1087-Brace-Expansion/1087.py)|||Medium|
423+
|1089|[Duplicate Zeros](https://leetcode.com/problems/duplicate-zeros/) | c | [c++](./src/1089-Duplicate-Zeros/1089.cpp) |[python](./src/1089-Duplicate-Zeros/1089.py)|||Easy|

Diff for: ‎src/1089-Duplicate-Zeros/1089.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution
2+
{
3+
public:
4+
void duplicateZeros(vector<int>& arr)
5+
{
6+
int n = arr.size(), j = n + count(arr.begin(), arr.end(), 0);
7+
for (int i = n - 1; i >= 0; --i)
8+
{
9+
if (--j < n) arr[j] = arr[i];
10+
if (arr[i] == 0 and --j < n) arr[j] = 0;
11+
}
12+
}
13+
};

Diff for: ‎src/1089-Duplicate-Zeros/1089.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def duplicateZeros(self, arr: List[int]) -> None:
3+
"""
4+
Do not return anything, modify arr in-place instead.
5+
"""
6+
n, j = len(arr), arr.count(0) + len(arr)
7+
for i in range(n-1, -1, -1):
8+
j -= 1
9+
if j < n:
10+
arr[j] = arr[i]
11+
if arr[i] == 0:
12+
j -= 1
13+
if j < n:
14+
arr[j] = 0

0 commit comments

Comments
 (0)
Please sign in to comment.