3031. Minimum Time to Revert Word to Initial State II

3031. Minimum Time to Revert Word to Initial State II

python 复制代码
class Solution:
    def minimumTimeToInitialState(self, word: str, k: int) -> int:
        for i in range(k,len(word),k):
            if word.startswith(word[i:]):return int(i/k)
        return ceil(len(word)/k)

其实如果找到前缀任务就完成了

思维题

相关推荐
夏鹏今天学习了吗1 天前
【LeetCode热题100(59/100)】分割回文串
算法·leetcode·深度优先
还是码字踏实1 天前
基础数据结构之数组的双指针技巧之对撞指针(两端向中间):三数之和(LeetCode 15 中等题)
数据结构·算法·leetcode·双指针·对撞指针
轮到我狗叫了1 天前
力扣.84柱状图中最大矩形 力扣.134加油站牛客.abb(hard 动态规划+哈希表)牛客.哈夫曼编码
算法·leetcode·职场和发展
熬了夜的程序员1 天前
【LeetCode】99. 恢复二叉搜索树
算法·leetcode·职场和发展
Kent_J_Truman1 天前
LeetCode Hot100 自用
算法·leetcode·职场和发展
还是码字踏实1 天前
算法题种类与解题思路全面指南:基于LeetCode Hot 100与牛客Top 101
算法·leetcode
熬了夜的程序员1 天前
【LeetCode】101. 对称二叉树
算法·leetcode·链表·职场和发展·矩阵
Kuo-Teng1 天前
LeetCode 73: Set Matrix Zeroes
java·算法·leetcode·职场和发展
葵续浅笑1 天前
LeetCode - 杨辉三角 / 二叉树的最大深度
java·数据结构·算法·leetcode