nikunjsoni

1813

Apr 4th, 2021
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution:
  2.     def areSentencesSimilar(self, sentence1: str, sentence2: str) -> bool:
  3.         s = sentence1.split(" ")
  4.         t = sentence2.split(" ")
  5.         n, m = len(s), len(t)
  6.         if n > m:
  7.             s, t = t, s
  8.             n, m = m, n
  9.         pre = 0
  10.         while pre < n and s[pre] == t[pre]:
  11.             pre += 1
  12.         suf = 0
  13.         while suf < n and s[-1 - suf] == t[-1 - suf]:
  14.             suf += 1
  15.         return pre + suf >= n
RAW Paste Data