private LocationPair FindMinDistancePair(List <int> arr1, List <int> arr2) { if (arr1 == null || arr2 == null || arr1.Count == 0 || arr2.Count == 0) { return(null); } int index1 = 0; int index2 = 0; LocationPair best = new LocationPair(arr1[0], arr2[0]); LocationPair current = new LocationPair(arr1[0], arr2[0]); while (index1 < arr1.Count && index2 < arr2.Count) { current.SetLocations(arr1[index1], arr2[index2]); best.UpdateWithMin(current); if (current.Location1 < current.Location2) { index1++; } else { index2++; } } return(best); }
public LocationPair FindClosest(string[] words, string word1, string word2) { LocationPair best = new LocationPair(-1, -1); LocationPair current = new LocationPair(-1, -1); for (int i = 0; i < words.Length; i++) { string word = words[i]; if (word == word1) { current.Location1 = i; best.UpdateWithMin(current); } else if (word == word2) { current.Location2 = i; best.UpdateWithMin(current); } } return(best); }