From 2a01a0f5461a1d65ebbaba79ca4bfd19e898ebfe Mon Sep 17 00:00:00 2001 From: Aditya Bhargava Date: Wed, 2 Mar 2016 15:11:32 -0800 Subject: [PATCH] code for chapter 9 --- .../python/01_longest_common_subsequence.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 09_dynamic_programming/python/01_longest_common_subsequence.py diff --git a/09_dynamic_programming/python/01_longest_common_subsequence.py b/09_dynamic_programming/python/01_longest_common_subsequence.py new file mode 100644 index 0000000..9f74f93 --- /dev/null +++ b/09_dynamic_programming/python/01_longest_common_subsequence.py @@ -0,0 +1,6 @@ +if word_a[i] == word_b[j]: + # The letters match. + cell[i][j] = cell[i-1][j-1] + 1 +else: + # The letters don't match. + cell[i][j] = max(cell[i-1][j], cell[i][j-1])