Skip to content

Commit

Permalink
1312
Browse files Browse the repository at this point in the history
  • Loading branch information
luanshiyinyang committed Nov 1, 2021
1 parent a9401f7 commit 22a33a8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 1312-Minimum Insertion Steps to Make a String Palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
def minInsertions(self, s: str) -> int:
n = len(s)
dp = [0] * n
for i in range(n-2, -1, -1):
pre = 0
for j in range(i+1, n):
tmp = dp[j]
dp[j] = pre if s[i] == s[j] else 1 + min(dp[j], dp[j - 1])
pre = tmp
return dp[n-1]

0 comments on commit 22a33a8

Please sign in to comment.