Leetcode题925、长键输入(Python题解)双指针、每日一题

it2024-02-23  59

问题:

题目来源:力扣(LeetCode)

leetcode925.长键输入

难度:简单

分析: 双指针题目,快慢指针类型,注意边界条件的处理。

解决方法: 1:双指针

class Solution: def isLongPressedName(self, name: str, typed: str) -> bool: l1, l2 = len(name), len(typed) i, j = 0, 0 while j < l2: if i < l1 and name[i] == typed[j]: i += 1 j += 1 elif j > 0 and typed[j] == typed[j - 1]: j += 1 else: return False return i == l1
最新回复(0)