算法:最长子序列1143. Longest Common Subsequence

算法:最长子序列1143. Longest Common Subsequence

Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.

A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

For example, “ace” is a subsequence of “abcde”.
A common subsequence of two strings is a subsequence that is common to both strings.

Example 1:

Input: text1 = "abcde", text2 = "ace" 
Output: 3  
Explanation: The longest common subsequence is "ace" and its length is 3.

Example 2:

Input: text1 = "abc", text2 = "abc"
Output: 3
Explanation: The longest common subsequence is "abc" and its length is 3.

Example 3:

Input: text1 = "abc", text2 = "def"
Output: 0
Explanation: There is no such common subsequence, so the result is 0.

Constraints:

1 <= text1.length, text2.length <= 1000
text1 and text2 consist of only lowercase English characters.

解法:升级为二维表格,动态规划解决

-a(1)c(2)e(3)
a(1)1 (1, 1)1 (1, 2)1
b(2)1 (2, 1)11
c(3)122
d(4)122
e (5)123
class Solution {
    public int longestCommonSubsequence(String text1, String text2) {
        int rowLen = text1.length();
        int colLen = text2.length();
        char[] chars1 = text1.toCharArray();
        char[] chars2 = text2.toCharArray();
        
        int[][] dp = new int[rowLen + 1][colLen + 1];
        for (int r = 0; r < rowLen; r++) {
            for (int c = 0; c < colLen; c++) {
                if (chars1[r] == chars2[c]) {
                    dp[r + 1][c + 1] = 1 + dp[r][c];
                } else {
                    dp[r + 1][c + 1] = Math.max(dp[r + 1][c], dp[r][c + 1]);
                }
            }
        }
        
        return dp[rowLen][colLen];
    }
}

Read more

LibreChat 集成 Stripe 支付的奶妈级教程

LibreChat 集成 Stripe 支付的奶妈级教程

我们假设你已经熟悉基本的 React 和 Node.js 开发,并且正在使用 LibreChat 的默认技术栈(React 前端、Node.js 后端、Vite 构建工具,可能还有 Electron 桌面应用)。教程会特别考虑 Electron 环境下的适配问题(例如 macOS 中文路径或路由错误)。“奶妈级”带你从零开始实现支付功能(包括一次性支付和添加高级会员订阅) 教程目标 * 在 LibreChat 中添加支付页面,支持用户通过信用卡付款。 * 实现 Stripe 的一次性支付功能。 * (可选)扩展到订阅功能,管理高级会员状态。 * 解决 Electron 环境下的常见问题(如路由和路径解析)。 * 生成可公开推送的 Markdown 教程,方便社区参考。 前提条件 在开始之前,请确保你已准备好以下内容:

By Ne0inhk
超棒的雅思资源!

超棒的雅思资源!

雅思真题材料地址: https://github.com/zeeklog/IETLS 感谢所有人。材料来自:@shah0150 & @kbtxwer * 超棒的雅思资源 * 雅思简介 * 听力 * 阅读 * 写作 * 口语 * 词汇 * 其他 * YouTube 频道 * [播客] (#podcasts) 雅思简介 * 什么是雅思 - 了解什么是雅思 听力 * 高级听力 * 雅思官方网站 * 考试英语 * 英国广播公司节目 * 乔治梅森大学口音学习网站 - 学习不同的口音 * 英国广播公司播客 * 英国文化协会听力练习 阅读 * 雅思提升阅读 写作 * 雅思提升写作 * 雅思从 6 分到 9 分 * 迷你雅思 口语 * Verbling 提供在线英语家教服务

By Ne0inhk