[LeetCode]#27. Remove Element

Given nums = [3,2,2,3], val = 3,Your function should return length = 2, with the first two elements of nums being 2.It doesn't matter what you leave beyond the returned length.
Given nums = [0,1,2,2,3,0,4,2], val = 2,Your function should return length = 5, with the first five elements of nums containing 0, 1, 3, 0, and 4.Note that the order of those five elements can be arbitrary.It doesn't matter what values are set beyond the returned length.
  1. get list number
  2. use while loop, if n=>0, keep search val in list.
  3. If nums[n]==val, delete it.
class Solution:
def removeElement(self, nums, val):
n= len(nums)-1
while n >=0:
if nums[n] == val:
del nums[n]
return len(nums)




Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Convert laptop to a router for Telekom.de network

Free and Open Source Software Noise Cancelling for Working from Home

How Do I Make Mocking a Lot Easier?

Handling CUAD dataset for legal entity extraction — The BERT way

Test infrastructure in Robotics —What, Why, and How?

Same case positive.

i love kovai ..

Go With AWS SDK — STS Token Generate

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.

More from Medium

[LeetCode]#2114. Maximum Number of Words Found in Sentences

Hackerrank — Reverse Doubly Linked List walkthrough #Python #Hackerrank

Sorting Algorithms Explained Using Python: Heap Sort

Glass Cube and Dots