Efficient algorithm to find first available name

前端 未结 7 1346
野性不改
野性不改 2021-01-19 03:26

I have an array containing names of items. I want to give the user the option to create items without specifying their name, so my program will have to supply a unique defau

7条回答
  •  终归单人心
    2021-01-19 03:55

    If there will be only one user accessing this array, why not use the number of nanoseconds? This, of course, assumes that the user is much slower than a computer, which seems to be a safe assumption.

    That way, you have a O(1) cost for determining a unique name.

提交回复
热议问题