freedom.9
Senior Member
Bài này sao AC thấp thế nhỉ? constrain cũng thấp nữa
Python:
class Solution:
def areSentencesSimilar(self, sentence1: str, sentence2: str) -> bool:
if len(sentence1) == len(sentence2):
return sentence1 == sentence2
if len(sentence1) > len(sentence2):
return self.areSentencesSimilar(sentence2, sentence1)
s1 = sentence1.split(" ")
s2 = sentence2.split(" ")
left, right = 0, len(s1) - 1
pLeft, pRight = 0, len(s2) - 1
while left < len(s1) and s1[left] == s2[pLeft]:
left += 1
pLeft += 1
while right >= left and s1[right] == s2[pRight]:
right -= 1
pRight-=1
return right < left

