Leetcode—1055. 形成字符串的最短路径【中等】Plus

2025每日刷题(208)

Leetcode---1055. 形成字符串的最短路径

实现代码

cpp 复制代码
class Solution {
public:
    int shortestWay(string source, string target) {
        int ans = 0;
        for(int i = 0; i < target.length();) {
            int prevIdx = i;
            for(int j = 0; j < source.length(); j++) {
                if(source[j] == target[i]) {
                    i++;
                }
            }
            if(prevIdx == i) {
                return -1;
            }
            ans++;
        }
        return ans;
    }
};

运行结果

之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!

相关推荐
June`3 分钟前
动态规划之背包问题(分割等和子集问题)
算法·动态规划
Felven6 分钟前
C. Vlad and a Sum of Sum of Digits
算法
潇-xiao6 分钟前
Qt 验证自动释放 + 乱码问题(6)
c++·笔记·qt
Flower#1 小时前
D. Apple Tree Traversing 【Codeforces Round 1023 (Div. 2)】
c++·算法·图论·dfs
zhangfeng11332 小时前
Matlab 遗传算法的库 gads
算法·数据分析
chennalC#c.h.JA Ptho2 小时前
archlinux 详解系统层面
linux·经验分享·笔记·系统架构·系统安全
忘梓.2 小时前
从父类到子类:C++ 继承的奇妙旅程(2)
java·开发语言·c++
究极无敌暴龙战神X2 小时前
hot100-子串-JS
javascript·数据结构·算法
_Jyuan_6 小时前
镜头内常见的马达类型(私人笔记)
经验分享·笔记·数码相机
岂是尔等觊觎8 小时前
软件设计师教程——第一章 计算机系统知识(下)
经验分享·笔记·其他