-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1001 from 0xff-dev/1813
Add solution and test-cases for problem 1813
- Loading branch information
Showing
3 changed files
with
85 additions
and
25 deletions.
There are no files selected for viewing
48 changes: 36 additions & 12 deletions
48
leetcode/1801-1900/1813.Sentence-Similarity-III/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 38 additions & 2 deletions
40
leetcode/1801-1900/1813.Sentence-Similarity-III/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,41 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
import "strings" | ||
|
||
// Eating, Eating right now | ||
func match1813(s, t []string) bool { | ||
l1, r1 := 0, len(s)-1 | ||
l2, r2 := 0, len(t)-1 | ||
for ; l1 <= r1 && s[l1] == t[l2]; l1, l2 = l1+1, l2+1 { | ||
|
||
} | ||
// 前缀 | ||
if l1 > r1 { | ||
return true | ||
} | ||
|
||
for ; r1 >= l1 && s[r1] == t[r2]; r1, r2 = r1-1, r2-1 { | ||
} | ||
if r1 < l1 { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func Solution(sentence1 string, sentence2 string) bool { | ||
// 相等只需要插入空的数据即可 | ||
if sentence1 == sentence2 { | ||
return true | ||
} | ||
l1, l2 := len(sentence1), len(sentence2) | ||
// 如果长度相等,但是字符串并不相等,说明无法插入 | ||
if l1 == l2 { | ||
return false | ||
} | ||
s1, s2 := strings.Split(sentence1, " "), strings.Split(sentence2, " ") | ||
if l1 < l2 { | ||
return match1813(s1, s2) | ||
} | ||
return match1813(s2, s1) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters