about | help | code help+videos | done | prefs |
apcsaListCompletePairs
Given an ArrayList of Integers, find out for each element whether there are any later elements with the same value. Then "complete" those pairs by moving the second element with that matched value to be after the first in the list. Any elements that cannot be completed are to be removed. Return the modified ArrayList. If you are thinking, "I could just sort this and return it," you have good instincts but think it through - there are several problems. WARNING: Integer objects should not be compared using == to other Integer objects, as doing so will evaluate a reference comparison rather than a value comparison. Perhaps you want to use the equals() method, or the Integer method intValue() instead?apcsaListCompletePairs([3, 5, 3]) → [3, 3] apcsaListCompletePairs([1, 4, 14, 4, 1, 14]) → [1, 1, 4, 4, 14, 14] apcsaListCompletePairs([3, 9, 9, 3, 4, 3]) → [3, 3, 9, 9] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 320
Copyright Nick Parlante 2017 - privacy