Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3d51101

Browse files
Duplicate Zeros
1 parent 13d54d2 commit 3d51101

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

‎coding_solutions/Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ This repository contains my answers to all Leetcode/HackerRank algorithm questio
1313
| 6 | [Climbing Stairs](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/)| [python3](https://github.com/sushant097/Data-Structure-Algorithms-Collections-Python/blob/master/coding_solutions/interview_related/[DP]ClimbingStairs.py) |
1414
| 7 | [Best Time to buy and sell](https://leetcode.com/problems/maximum-subarray/)| [python3](https://github.com/sushant097/Data-Structure-Algorithms-Collections-Python/blob/master/coding_solutions/interview_related/[DP]BestTimeToBuySell.py) |
1515
| 8 | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)| [python3](https://github.com/sushant097/Data-Structure-Algorithms-Collections-Python/blob/master/coding_solutions/interview_related/LetterCombinationOfPhoneNumber.py) |
16+
| 8 | [Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)| [python3](https://github.com/sushant097/Data-Structure-Algorithms-Collections-Python/blob/master/coding_solutions/interview_related/LetterCombinationOfPhoneNumber.py) |
1617

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def duplicateZeros(self, arr: List[int]) -> None:
3+
"""
4+
Do not return anything, modify arr in-place instead.
5+
"""
6+
7+
i = 0
8+
j = 0
9+
while j < len(arr):
10+
if arr[j] == 0:
11+
i = j
12+
j += 1
13+
arr.insert(i, 0)
14+
arr.pop()
15+
j += 1
16+
17+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /