Golang | Leetcode Golang题解之第392题判断子序列

题目:

题解:

Go 复制代码
func isSubsequence(s string, t string) bool {
    n, m := len(s), len(t)
    f := make([][26]int, m + 1)
    for i := 0; i < 26; i++ {
        f[m][i] = m
    }
    for i := m - 1; i >= 0; i-- {
        for j := 0; j < 26; j++ {
            if t[i] == byte(j + 'a') {
                f[i][j] = i
            } else {
                f[i][j] = f[i + 1][j]
            }
        }
    }
    add := 0
    for i := 0; i < n; i++ {
        if f[add][int(s[i] - 'a')] == m {
            return false
        }
        add = f[add][int(s[i] - 'a')] + 1
    }
    return true
}
相关推荐
唐梓航-求职中11 小时前
编程大师-技术-算法-leetcode-1472. 设计浏览器历史记录
算法·leetcode
YGGP11 小时前
【Golang】LeetCode 1. 两数之和
leetcode
唐梓航-求职中11 小时前
编程大师-技术-算法-leetcode-355. 设计推特
算法·leetcode·面试
唐梓航-求职中11 小时前
技术-算法-leetcode-1606. 找到处理最多请求的服务器(易懂版)
服务器·算法·leetcode
YGGP13 小时前
【Golang】LeetCode 128. 最长连续序列
leetcode
牛奔14 小时前
Go 如何避免频繁抢占?
开发语言·后端·golang
不老刘17 小时前
LiveKit 本地部署全流程指南(含 HTTPS/WSS)
golang·实时音视频·livekit
月挽清风21 小时前
代码随想录第十五天
数据结构·算法·leetcode
TracyCoder1231 天前
LeetCode Hot100(34/100)——98. 验证二叉搜索树
算法·leetcode
Tony Bai1 天前
再见,丑陋的 container/heap!Go 泛型堆 heap/v2 提案解析
开发语言·后端·golang