Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

简单的git diff功能实现 #21

Open
callumyang opened this issue Jan 6, 2021 · 0 comments
Open

简单的git diff功能实现 #21

callumyang opened this issue Jan 6, 2021 · 0 comments

Comments

@callumyang
Copy link
Collaborator

目前只实现了比较两个文件a和b的diff
通过path[i][j]记录路径 1表示增加一行 -1表示删除一行 0表示不变
dp[i][j]表示a的前i行和b的前j行需要的修改次数则有
如果a的第i行等于b的第j行
dp[i][j] = min(dp[i-1][j-1],dp[i-1][j],dp[i][j-1])
否则
dp[i][j] = min(dp[i-1][j],dp[i][j-1])
为了使得加号和减号尽量聚集,每次先比较dp[i-1][j]和dp[i][j-1]相等时取dp[i][j-1]
然后通过滚动数组优化成一维数组
通过递归输出路径
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant