T******n 发帖数: 11 | 1 Implement a function that will find the most recent common ancestor of any
two commits from a given commit graph. The commit graph is represented as a
String[] called commits containing all commit IDs in sorted date order (most
recent first) and a String[][] called parents. The parent IDs for the
commit ID at index i can be found at parents[i]. The last item in the
parents array is always null since this represents the parent of the root
commit. For example, the following commit graph:
E - F
/ \
A -B - C - D - G
will be represented using:
String[] commits = {"G", "F", "E", "D", "C", "B", "A"};
String[][] parents ={{"F","D"},{"E"}, {"B"}, {"C"}, {"B"}, {"A"}, null};
If one commit is an ancestor of the other, return the commit that is the
ancestor | T******n 发帖数: 11 | |
|