力扣刷题-字符串-左旋转字符串

LCR 182.动态口令-同剑指Offer58-II

某公司门禁密码使用动态口令技术。初始密码为字符串 password,密码更新均遵循以下步骤:

设定一个正整数目标值 target

将 password 前 target 个字符按原顺序移动至字符串末尾

请返回更新后的密码字符串。

示例 1:

输入: password = "s3cur1tyC0d3", target = 4

输出: "r1tyC0d3s3cu"

示例 2:

输入: password = "lrloseumgh", target = 6

输出: "umghlrlose"

思路

直接使用字符串的切片操作

python 复制代码
class Solution(object):
    def dynamicPassword(self, password, target):
        """
        :type password: str
        :type target: int
        :rtype: str
        """
        # 很简单的做法 直接使用切片操作
        result = ''
        tmp_str1 = password[:target] # 前target个字符
        tmp_str2 = password[target:] # 后面的字符
        result += tmp_str2
        result += tmp_str1
        return result
相关推荐
锋行天下1 小时前
langgraph 后端发自定义数据,前端接收方法概括
人工智能·python
benchmark_cc3 小时前
用 QuantDash 读取单只股票五档盘口:抽样、缺失值检查与复现记录
python·数据分析·pandas·量化交易·股票数据·quantdash
曲径海盗3 小时前
【Python 学习第 55 天】列表基础
python·学习笔记·编程入门
专注仿真4 小时前
知识问答模型用到的算法集详解及代码实例
python·算法·代码·大模型训练·控制算法
jyOverQ4 小时前
我写了一个 CSDN Markdown 图片助手:告别本地图片逐张上传
python·工具·csdn
罗西的思考5 小时前
【轻量化复刻大模型 / KIMI K3】AttnRes 模块交互式演示
人工智能·算法·机器学习
刘马想放假7 小时前
CANviz 使用指南|Linux 安装、DBC 解码、实时曲线与 J1939 实战
linux·python·websocket
2601_967987378 小时前
python判断变量名不要调用任何函数实现
python·函数·语法·判断·变量名
好悬给我拽开线8 小时前
ZILOT 论文解析
算法
卷无止境9 小时前
SALib敏感性分析的python库学习笔记
后端·python