Python Programming Practice: LeetCode #283 -- Move Zeroes

preview_player
Показать описание
In this episode of Python Programming Practice: LeetCode #283 -- Move Zeroes

Link to the problem here:

Python Programming Practice is a series focused on teaching practical coding skills by solving exercises on popular coding websites. Note that the solutions seen here may not be the most efficient possible.

I am not going to provide the full code in the video description for this series, since copy and pasting solutions is not in the spirit of doing coding exercises. It is intended that the video will help you think about problems, approaches and how to structure solutions so that you are able to code up a working solution yourself. .

Рекомендации по теме
Комментарии
Автор

class Solution:
def moveZeroes(self, nums: List[int]) -> None:
l=0
for i in range (len(nums)):
if nums[i] != 0:
nums[l], nums[i] = nums[i], nums[l]
l += 1
return(nums)

pralayumale
Автор

Could we expect more such videos (leetcode problems)in future ???

kishankumar-pntj
Автор

Hi sir kindly explain banking domain projects or fraud management or bank crupt projects or retail project

rajm
Автор

def mov_zero(n):
non_zero=list(filter(lambda x:x!=0, n))
zero=list(filter(lambda x:x==0, n))
for i in zero:
non_zero.append(i)
return non_zero

hashishreddy
Автор

I did a variant of your solution. Because I didn't understand how you take care of non-zero elements in earlier position in your solution. They are copied, but don't they still remain old position?

def moveZeroes(self, nums: List[int]) -> None:
non_zero_pos = 0
for num in nums:
if num != 0 :
nums[non_zero_pos] = num
non_zero_pos += 1
for i in range(non_zero_pos, len(nums)):
nums[i] = 0

NitinSatish