Removing alternate elements in a List

后端 未结 8 1110
执笔经年
执笔经年 2021-02-12 18:41

What is the most efficient way to remove alternate (odd indexed or even indexed) elements in an List without using a place holder list variable?

A

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-12 18:52

    Obviously usage dependent, but you could have a wrapper IList that multiplies the index you give it by 2, and reports the length of the list to be 1/2 (details elided). This is O(1).

提交回复
热议问题