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

[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
相关推荐
NAGNIP11 小时前
一文搞懂深度学习中的通用逼近定理!
人工智能·算法·面试
AI探索者16 小时前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者16 小时前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh18 小时前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅18 小时前
Python函数入门详解(定义+调用+参数)
python
曲幽19 小时前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama
颜酱19 小时前
单调栈:从模板到实战
javascript·后端·算法
两万五千个小时1 天前
落地实现 Anthropic Multi-Agent Research System
人工智能·python·架构
CoovallyAIHub1 天前
仿生学突破:SILD模型如何让无人机在电力线迷宫中发现“隐形威胁”
深度学习·算法·计算机视觉
CoovallyAIHub1 天前
从春晚机器人到零样本革命:YOLO26-Pose姿态估计实战指南
深度学习·算法·计算机视觉