Code Signal_练习题_extractEachKth

Given array of integers, remove each kth element from it.

Example

For inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and k = 3, the output should be
extractEachKth(inputArray, k) = [1, 2, 4, 5, 7, 8, 10].

我的解答:

def extractEachKth(inputArray, k):
    return [i for i in inputArray if i not in inputArray[k - 1::k]]
def extractEachKth(inputArray, k):
    del inputArray[k-1::k]
    return inputArray
膜拜大佬

猜你喜欢

转载自www.cnblogs.com/YD2018/p/9484481.html
今日推荐