Skip to content

Instantly share code, notes, and snippets.

@ucarion
Created September 20, 2015 01:35
Show Gist options
  • Save ucarion/849b5731978192b3fbec to your computer and use it in GitHub Desktop.
Save ucarion/849b5731978192b3fbec to your computer and use it in GitHub Desktop.
fn backtrack<'a, T>(&self, a: &'a [T], b: &'a [T], i: usize, j: usize) -> Vec<&'a T>
where T: Eq {
if i == 0 || j == 0 {
vec![]
} else if a[i] == b[j] {
let mut prefix_lcs = self.backtrack(a, b, i - 1, j - 1);
prefix_lcs.push(&a[i]);
prefix_lcs
} else {
if self.lengths[i][j - 1] > self.lengths[i - 1][j] {
self.backtrack(a, b, i, j - 1)
} else {
self.backtrack(a, b, i - 1, j)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment