首页
学习
活动
专区
圈层
工具
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

数据结构算法操作试题(C++/Python)——移除元素

1. 题目

leetcode 链接:https://leetcode-cn.com/problems/remove-element/

2. 解答

python: 28MS, 10.7MB

代码语言:javascript
复制
class Solution(object):
    def removeElement(self, nums, val):
        """
        :type nums: List[int]
        :type val: int
        :rtype: int
        """
        tmp_index = 0
        if not nums: return 
        for i in range(len(nums)):
            if nums[i] !=  val:
                nums[tmp_index] = nums[i]
                tmp_index += 1
        return tmp_index

其他方法看 leetcode 链接 评论区~

下一篇
举报
领券