1540. 能否转换

中文English

给两个字符串 S 和 T, 判断 S 能不能通过删除一些字母(包括0个)变成 T.

样例

样例1

输入: S = "lintcode" 和 T = "lint"
输出: true

样例2

输入: S = "lintcode" 和 T = "ide"
输出: true

单指针
class Solution:
    """
    @param s: string S
    @param t: string T
    @return: whether S can convert to T
    """
    def canConvert(self, s, t):
        # Write your code here
        #单指针
        left = 0
        length = len(s)
        
        for val in t:
            while left < length:
                left += 1
                if val == s[left - 1]:
                    break
            else:
                return False 
        
        return True
 

相关文章:

  • 2022-02-04
  • 2021-11-26
  • 2022-12-23
  • 2021-12-18
  • 2021-07-10
  • 2021-07-12
  • 2021-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-08
  • 2021-09-25
  • 2022-12-23
  • 2021-09-09
  • 2021-10-02
相关资源
相似解决方案