Leetcode—1165. 单行键盘【简单】Plus

2025每日刷题(211)

Leetcode---1165. 单行键盘

实现代码

cpp 复制代码
class Solution {
public:
    int calculateTime(string keyboard, string word) {
        int ans = 0;
        int cur = 0;
        int pre = 0;
        for(auto& w: word) {
            auto it = find(keyboard.begin(), keyboard.end(), w);
            cur = distance(keyboard.begin(), it);
            ans += abs(pre - cur);
            pre = cur;
        }
        return ans;
    }
};

运行结果

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

相关推荐
ShineWinsu2 小时前
对于C++:IO流状态的详细解析
c++·面试·io·cin·io流状态·goodbit·failbit
数模竞赛Paid answer3 小时前
2026年中青杯数学建模A题数学建模论文智能评估系统与多智能体优化方法求解全过程论文及程序
算法·数学建模·中青杯
银-豆豆3 小时前
数据结构与算法-动态规划、回溯与贪心
算法·动态规划
tianxuanjg3 小时前
0.005mm 高精度 CNC 加工:机器人薄壁复杂零件变形控制与全维度品控方案
经验分享·机器人·无人机·制造·材质
Lzg_na3 小时前
constexpr的优势
c++
想吃火锅10055 小时前
【leetcode】200. 岛屿数量
算法·leetcode·职场和发展
王维同学5 小时前
进程模块枚举、映像身份与线程启动地址关联
c++·windows·安全
hold?fish:palm5 小时前
24 回文链表
数据结构·c++·链表
举手5 小时前
Dispatcher模块剖析
linux·c++
Nil2085 小时前
leetcode 54螺旋矩阵
算法·leetcode·矩阵