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)

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

思维题

相关推荐
Tim_109 分钟前
【LeetCode】338、比特位计数
c++·算法·leetcode
mmmmath_32 小时前
LeetCode.028.找出字符串中第一个匹配项的
数据结构·算法·leetcode
Navigator_Z2 小时前
LeetCode //C - 1255. Maximum Score Words Formed by Letters
c语言·算法·leetcode
All for pursuit.2 小时前
【栈-4】739.每日温度
数据结构·c++·算法·leetcode
开开心心就好2 小时前
安卓手写文字生成工具,多种纸张一直免费
网络·网络协议·tcp/ip·leetcode·智能手机·电脑·模拟退火算法
All for pursuit.2 小时前
【栈-5】84.柱状图中最大的矩形
数据结构·c++·算法·leetcode
圣保罗的大教堂3 小时前
leetcode 1665. 完成所有任务的最少初始能量 中等
leetcode
Tisfy18 小时前
LeetCode 3498.字符串的反转度:一次遍历
leetcode·字符串·题解·遍历
a1879272183118 小时前
【算法】树(二):队列与祖先——BFS 骨架三配件、短路透传与合流
算法·leetcode·二叉树··bfs·算法讲解·树遍历
Navigator_Z1 天前
LeetCode //C - 1254. Number of Closed Islands
c语言·算法·leetcode