Find first available serial based on list of strings?

后端 未结 4 1149
挽巷
挽巷 2021-01-26 02:34

Given a list of strings such as: apple01, apple02, and apple04, banana02, cherry01, how would you come up with t

4条回答
  •  無奈伤痛
    2021-01-26 03:02

    The naive and straight-forward solution would be based on pre-generating a list of syntax valid names.

    Query names that are already in use and store the results into a collection.

    Iterate the used names collection and remove those from the pre-generated collection.

    Sort the pre-generated collection.

    Now you got a collection that contains unused names in sorted order. Pick any number of desired names for further usage.

提交回复
热议问题