Puzzle : finding out repeated element in an Array

后端 未结 9 1057
面向向阳花
面向向阳花 2021-02-10 17:39

Size of an array is n.All elements in the array are distinct in the range of [0 , n-1] except two elements.Find out repeated element without using extra temporary array with con

9条回答
  •  说谎
    说谎 (楼主)
    2021-02-10 17:59

    Lazy solution: Put the elements to java.util.Set one by one by add(E) until getting add(E)==false.

    Sorry no constant-time. HashMap:O(N), TreeSet:O(lgN * N).

提交回复
热议问题