1 | One sentence is composed of a single space between some words and them,And there is no excess space at the beginning and end of the sentence。for example,"Hello World" ,"HELLO" ,"hello world hello world" All sentences。Each word Only Including uppercase and lowercase English letters。 |
My solution:
What I think is to make up the judgment of the character on the left or the right, and then delete it,
但是做的过程middle耐心没了,Feeling is a proper footing。
1 | class Solution: |
Official solution:
According to the meaning,Two sentences sentence1 and sentence2,if是similar,那么这Two sentences按空格分割get的字符串数组 words1
and words2,一定能通过往其middle一个字符串数组middle插入某个字符串数组(Can be empty),get另一个字符串数组。这个验证可以通过Double pointer完成。
i Indicates that the two string array starts from left,At most i The string of the string is the same。
j It means that the remaining string array starts from right,At most j The string of the string is the same。
if i+j It happens to be the length of a string array,那么原字符串就是similar。
1 | class Solution: |