I was asked to write down a Java function sharedStr
that by given 2 sorted arrays of String
s, returns the number of String
s that appea
What does it mean sorted arrays that contains strings? There isn't any special description of the way it has been sorted. what is the basic ordinary sorting of strings?
It means the elements in the array are ordered in a natural sequence. For strings this is alphebetical order with lowercase words place before upper case.
How does one compare between two strings any way?
By invoking the compareTo
method. If it returns 0 they strings are equal, if return < 0 the first string is lower than the second, if return > 0 the firs string is higher than the second.
As for how to count repetitions linearly see this: comparing strings in java