Algorithm to find a duplicate entry in constant space and O(n) time

后端 未结 8 2031
我在风中等你
我在风中等你 2020-12-16 04:30

Given an array of N integer such that only one integer is repeated. Find the repeated integer in O(n) time and constant space. There is no range for the value of integers or

8条回答
  •  [愿得一人]
    2020-12-16 04:58

    We can do in linear time o(n) here as well

    public class DuplicateInOnePass {
    
        public static  void duplicate()
    
       {
            int [] ar={6,7,8,8,7,9,9,10};
            Arrays.sort(ar);
            for (int i =0 ; i 

提交回复
热议问题