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;
    }
};

运行结果

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

相关推荐
旖旎夜光1 小时前
【C++ 基础入门】C++ 多态(中):虚函数表、多态原理与动静绑定
开发语言·c++·笔记·学习
Rain的Java大神之路2 小时前
LeetCode 37 解数独面试攻略:回溯 + 位掩码 + MRV,从暴力到毫秒级求解
java·后端·leetcode
NEFU_Jyj2 小时前
贝尔数(组合数学)
算法
希和20272 小时前
C语言程序设计题|有序数组插入数字冒泡排序
c语言·数据结构·算法
旖旎夜光2 小时前
【C++ 基础入门】C++多态(下):单/多继承虚表、多态补充与 21 道高频题
开发语言·c++·笔记·学习
Pniubi3 小时前
力扣73 矩阵置零
算法·leetcode·矩阵
ppo_wu11 小时前
解决夸克网盘自动修改PDF打开方式的方法
经验分享·安全·网络安全
apcipot_rain13 小时前
C++转Java日记(03)
java·开发语言·c++
布莱克60513 小时前
C++ 中 map 的 insert 与 emplace:key 已存在时会覆盖吗?
开发语言·数据结构·c++·算法·map
xys_67813 小时前
深挖C++:类和对象(中)
开发语言·c++