五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網 會員登陸 & 注冊

LCS/LIS

2022-03-25 21:59 作者:劍離我離  | 我要投稿

class Solution {

? ? public int longestCommonSubsequence(String s1, String s2) {

? ? ? ? int n = s1.length(), m = s2.length();

? ? ? ? s1 = " " + s1; s2 = " " + s2;

? ? ? ? char[] cs1 = s1.toCharArray(), cs2 = s2.toCharArray();

? ? ? ? int[][] f = new int[n + 1][m + 1];?


? ? ? ? // 因為有了追加的空格,我們有了顯然的初始化值(以下兩種初始化方式均可)

? ? ? ? // for (int i = 0; i <= n; i++) Arrays.fill(f[i], 1);

? ? ? ? for (int i = 0; i <= n; i++) f[i][0] = 1;

? ? ? ? for (int j = 0; j <= m; j++) f[0][j] = 1;


? ? ? ? for (int i = 1; i <= n; i++) {

? ? ? ? ? ? for (int j = 1; j <= m; j++) {

? ? ? ? ? ? ? ? if (cs1[i] == cs2[j]) {

? ? ? ? ? ? ? ? ? ? f[i][j] = f[i -1][j - 1] + 1;

? ? ? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? ? ? f[i][j] = Math.max(f[i - 1][j], f[i][j - 1]);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }


? ? ? ? // 減去最開始追加的空格

? ? ? ? return f[n][m] - 1;

? ? }

}



? ?public boolean increasingTriplet(int[] nums) {

? ? ? ? int n = nums.length, ans = 1;

? ? ? ? int[] f = new int[n + 1];

? ? ? ? Arrays.fill(f, 0x3f3f3f3f);

? ? ? ? for (int i = 0; i < n; i++) {

? ? ? ? ? ? int t = nums[i];

? ? ? ? ? ? int l = 1, r = i + 1;

? ? ? ? ? ? while (l < r) { // 二分找

? ? ? ? ? ? ? ? int mid = l + r >> 1;

? ? ? ? ? ? ? ? if (f[mid] >= t) r = mid;

? ? ? ? ? ? ? ? else l = mid + 1;

? ? ? ? ? ? }

? ? ? ? ? ? f[r] = t;

? ? ? ? ? ? ans = Math.max(ans, r);

? ? ? ? }

? ? ? ? return ans >= 3;

? ? }



LCS/LIS的評論 (共 條)

分享到微博請遵守國家法律
洛浦县| 岳池县| 顺平县| 江城| 甘德县| 河西区| 孟村| 黄平县| 衡阳县| 伊吾县| 丰宁| 和顺县| 台中市| 芦溪县| 洛宁县| 大英县| 巩留县| 海口市| 青海省| 龙川县| 科尔| 云龙县| 攀枝花市| 兴安盟| 澄迈县| 河西区| 盈江县| 江都市| 黔江区| 桃江县| 巴南区| 双辽市| 邹平县| 炎陵县| 镇沅| 随州市| 吴旗县| 旅游| 澄城县| 文昌市| 鹿泉市|