Arrays of Int arrays. Storing duplicates in order only

后端 未结 6 1424
灰色年华
灰色年华 2021-01-11 18:37

I need to store an array of Int array for ordered duplicates (which are in a Array).

Example:

  • Given array:
    mainArray = [7, 7, 3, 2, 2, 2, 1,
6条回答
  •  有刺的猬
    2021-01-11 18:45

    This is a programming logic problem problem. Your current code is totally wrong.

    Here's one way you could solve it:

    Start out by sorting your starting array. call that inputArray.

    Create new, empty output "outerArray" and "innerArray" variables. Then loop through the entries in inputArray, testing for changes in value. If the value is the same as the last value, add that value to "innerArray". If the value has changed, save the previous innerArray to the outerArray and create a new, empty array and save it to innerArray.

提交回复
热议问题