public String findMergeNode(List<String> aList, List<String> bList) {
List<String> longList;
List<String> shortList;
int offset = 0;
String mergeNode = null;
if (aList.size() > bList.size()) {
longList = aList;
shortList = bList;
offset = aList.size() - bList.size();
} else {
longList = bList;
shortList = aList;
offset = bList.size() - aList.size();
}
for (int i = 0; i < longList.size() - offset; i++) {
String a = shortList.get(i);
String b = longList.get(i + offset);
if (a == b) {
if (mergeNode == null) {
mergeNode = a;
}
} else {
mergeNode = null;
}
}
return mergeNode;
}
评论