I am trying to compare two lines and identify duplicate words. For instance:
String1 = "Hello, my name is John." String2 = "Can you tell me your name please?"
Comparing String1 and String2 will return the word; "Name".
I know that you can break these two lines into an array of words, and then iterate over each word of each line in a two-dimensional array. However, it is computationally expensive in O (n ^ 2), and I was wondering if there is a faster way to do this?
Thanks.
EDIT: modified the example for clarity.
source share