上一页 1 2 3 4 5 6 7 8 ··· 21 下一页
摘要: https://leetcode.cn/problems/daily-temperatures/ class Solution { public int[] dailyTemperatures(int[] temperatures) { // 经典单调栈 // 核心思想就是及时去除无用数据,保证栈中 阅读全文
posted @ 2024-09-14 00:02 风乐 阅读(25) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/longest-palindromic-subsequence/description/ class Solution { public int longestPalindromeSubseq(String s) { // f[i][j]表示 阅读全文
posted @ 2024-09-11 03:48 风乐 阅读(25) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/palindromic-substrings/ 经典题,本题有双指针和dp两种做法,dp的定义是f[i][j]表示s[i:j]是回文串容易联想到递推方程f[i][j]=f[i+1][j-1] && s[i]==s[j]又因为1个字符或者两个相 阅读全文
posted @ 2024-09-11 02:23 风乐 阅读(30) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/edit-distance/ class Solution { public int minDistance(String word1, String word2) { // 经典题编辑距离 // f[i][j]表示word1前i个字符中选择 阅读全文
posted @ 2024-09-10 22:18 风乐 阅读(40) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/delete-operation-for-two-strings/solutions/ 两种做法,1.直接dp 2.转换题意,思考成LCS class Solution { public int minDistance(String word 阅读全文
posted @ 2024-09-10 21:43 风乐 阅读(20) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/distinct-subsequences/submissions/563375885/ 这题比较有难度,具体不太好想到,需要以是否选择s[i]来划分子集这位描述的很清楚,不做过多赘述 class Solution { public int 阅读全文
posted @ 2024-09-10 16:21 风乐 阅读(14) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/is-subsequence/description/ class Solution { public boolean isSubsequence(String s, String t) { // 依据题意,可以判断是求最长公共子序列的特殊情 阅读全文
posted @ 2024-09-08 14:08 风乐 阅读(16) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/maximum-subarray/description/ class Solution { public int maxSubArray(int[] nums) { // f[i]表示以第i个数为结尾的最大连续子数组和 // 以是否选择第i 阅读全文
posted @ 2024-09-08 02:22 风乐 阅读(21) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/uncrossed-lines/ class Solution { public int maxUncrossedLines(int[] nums1, int[] nums2) { // 依据题意,稍加思考可知,是求最长公共子序列 // f[ 阅读全文
posted @ 2024-09-08 02:08 风乐 阅读(21) 评论(0) 推荐(0)
摘要: https://leetcode.cn/problems/longest-common-subsequence/description/经典题,老题回顾 class Solution { public int longestCommonSubsequence(String text1, String 阅读全文
posted @ 2024-09-07 15:29 风乐 阅读(29) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 ··· 21 下一页