public int RunnersMeetings(int[] StartPosition, int[] speed) { int ans = -1; for (int i = 0; i < StartPosition.Length; i++) { for (int j = i + 1; j < StartPosition.Length; j++) { TimeOfMeet meetingTimeA = MeetingTime(StartPosition[i], StartPosition[j], speed[i], speed[j]); if (!meetingTimeA.IsMeet) { continue; } int numOfMeet = 2; for (int k = j + 1; k < StartPosition.Length; k++) { TimeOfMeet meetingTimeB = MeetingTime(StartPosition[i], StartPosition[k], speed[i], speed[k]); if (meetingTimeA.Compare(meetingTimeB)) { numOfMeet++; } } ans = Math.Max(ans, numOfMeet); } } return(ans); }
public bool Compare(TimeOfMeet x) { if ((x.Distance == this.Distance) && (x.Speed == this.Speed) && (x.IsMeet == this.IsMeet)) { return(true); } else { return(false); } }
public void TestGetMeetingTime2() { var actual = runnerMeetingsHelper.MeetingTime(1, 4, 27, 18); var expected = new TimeOfMeet { Distance = 1, Speed = 3, IsMeet = true }; Assert.AreEqual(expected.Distance, actual.Distance); Assert.AreEqual(expected.Speed, actual.Speed); Assert.AreEqual(expected.IsMeet, actual.IsMeet); }