0

Can you please advise I have the below array for which I want to remove duplicates but without using any collection api , please advise how to achieve this...

  int[][] test = new int[][]{
            {1, 1, 2, 2, 3, 4, 5},
            {1, 1, 1, 1, 1, 1, 1},
            {1, 2, 3, 4, 5, 6, 7},
            {1, 2, 1, 1, 1, 1, 1},};

1 Answers1

2

Since you are dealing with int array and values are relatively small I'd suggest you to create temporary boolean array where the numbers from the source array are used as indexes. Then you just have to iterate over the source array, put true to appropriate cell of your temporary array. At the next iteration go over the temporary array and indexes of elements that are true.

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • Thanks a lot can you please post the code also that will help me to grasp more , request you to take input array as I have mentioned above while explaning – user3270422 Mar 17 '14 at 12:32
  • @user3270422 This absolutely sounds like you are asking us to do your homework. The guiding principle for this is: "Make a good faith attempt to solve the problem yourself first. If we can't see enough work on your part your question will likely be booed off the stage; it will be voted down and closed." See: http://meta.stackexchange.com/questions/10811/how-do-i-ask-and-answer-homework-questions – Erwin Bolwidt Mar 17 '14 at 12:35