Ad
  • Custom User Avatar

    OP solved it, closing

  • Custom User Avatar

    Yes, this was the first solution. I didn't like it either. Then I corrected it to the flag. Thanks for the detailed comment! ๐Ÿ‘

  • Custom User Avatar

    The "a[i] = 99999999;" line is avoidable by using a flag like "boolean present = true"
    but even then, the loop keeps going until the end.
    Is fixable by doing something like "if ((a[i] == b[j]) && !present)" but it is so unreadable.
    The best way, I think, is to just put the inner loop into a new function isPresent() which takes a[i] and b as parameters, instead of "a[i] = 9999999" the function would return true, and would return false instead if the loop ends.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution