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

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
相关推荐
金銀銅鐵5 小时前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup119 小时前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi0011 小时前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵13 小时前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf14 小时前
Agent 流程编排
后端·python·agent
copyer_xyf15 小时前
Agent RAG
后端·python·agent
copyer_xyf15 小时前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf15 小时前
Agent 记忆管理
后端·python·agent
JieE2121 天前
LeetCode 56. 合并区间|超清晰 JS 图解思路,面试高频区间题
javascript·算法·面试