Minimum Insertion Steps to Make a String Palindrome LeetCode solution in C++
1class Solution {2public:3int t[501][501];4int MinInsertion(string x, int m) {5string y = x;6reverse(y.begin(), y.end());7for (int i = 0; i < m + 1; i++) {8for (int j = 0; j < m + 1; j++) {9if (i == 0 || j == 0) t[i][j] = 0;10}11}12for (int i = 1; i < m + 1; i++) {13for (int j = 1; j < m + 1; j++) {14if (x[i - 1] == y[j - 1])15t[i][j] = 1 + t[i - 1][j - 1];16else17t[i][j] = max(t[i - 1][j], t[i][j - 1]);18}19}20return m - t[m][m];21}22int minInsertions(string s) {23return MinInsertion(s, s.length());24}25};