本文主要是介绍Java | Leetcode Java题解之第391题完美矩形,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
题解:
class Solution {public boolean isSubsequence(String s, String t) {int n = s.length(), m = t.length();int[][] f = new int[m + 1][26];for (int i = 0; i < 26; i++) {f[m][i] = m;}for (int i = m - 1; i >= 0; i--) {for (int j = 0; j < 26; j++) {if (t.charAt(i) == j + 'a')f[i][j] = i;elsef[i][j] = f[i + 1][j];}}int add = 0;for (int i = 0; i < n; i++) {if (f[add][s.charAt(i) - 'a'] == m) {return false;}add = f[add][s.charAt(i) - 'a'] + 1;}return true;}
}
这篇关于Java | Leetcode Java题解之第391题完美矩形的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!