# Leetcode 27. Remove Element 刪除List中給定目標值,並回傳剩餘長度。 ## 想法 ### 暴力解 直接使用count拿到目標值有幾個,再將它刪除回傳List長度。 程式碼: ``` class Solution: def removeElement(self, nums: List[int], val: int) -> int: nums.sort() tag = nums.count(val) for i in range(tag): nums.remove(val) return len(nums) ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up