How can I find a number which occurs an odd number of times in a SORTED array in O(n) time?

后端 未结 15 2315
梦如初夏
梦如初夏 2021-01-30 10:31

I have a question and I tried to think over it again and again... but got nothing so posting the question here. Maybe I could get some view-point of others, to try and make it w

15条回答
  •  情书的邮戳
    2021-01-30 11:35

    You can create a cummulative array and count how much each number occur and then in the cummulative array find the element which is odd. Example:

    int a[]=new int[]{2,3,4,2,3,1,4,5,6,5,6,7,1};
    int b[]=new int[1000];
    for (int i=0;i

提交回复
热议问题