# coding = utf-8
'''
Created on 2015年11月6日
@author: SphinxW
'''
# 删除元素
#
# 给定一个数组和一个值,在原地删除与值相同的数字,返回新数组的长度。
#
# 元素的顺序可以改变,并且对新的数组不会有影响。
# 您在真实的面试中是否遇到过这个题?
# 样例
#
# 给出一个数组 [0,4,4,0,0,2,4,4],和值 4
#
# 返回 4 并且4个元素的新数组为[0,0,0,2]
class Solution:
"""
@param A: A list of integers
@param elem: An integer
@return: The new length after remove
"""
def removeElement(self, A, elem):
# write your code here
while elem in A:
A.remove(elem)
return A
LintCode_chapter2_section1_remove-element
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- LeetCode 26. Remove Duplicates from Sorted Array Given a ...
- Problem Do not allocate extra space for another array, yo...