-
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 #1052 from 0xff-dev/2337
Add solution and test-cases for problem 2337
- Loading branch information
Showing
3 changed files
with
76 additions
and
26 deletions.
There are no files selected for viewing
39 changes: 26 additions & 13 deletions
39
leetcode/2301-2400/2337.Move-Pieces-to-Obtain-a-String/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
41 changes: 39 additions & 2 deletions
41
leetcode/2301-2400/2337.Move-Pieces-to-Obtain-a-String/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,42 @@ | ||
package Solution | ||
|
||
func Solution(x bool) bool { | ||
return x | ||
type pair2337 struct { | ||
c byte | ||
i int | ||
} | ||
|
||
func Solution(start string, target string) bool { | ||
a, b := make([]pair2337, 0), make([]pair2337, 0) | ||
for i, c := range []byte(start) { | ||
if c == '_' { | ||
continue | ||
} | ||
a = append(a, pair2337{c, i}) | ||
} | ||
for i, c := range []byte(target) { | ||
if c == '_' { | ||
continue | ||
} | ||
b = append(b, pair2337{c, i}) | ||
} | ||
if len(a) != len(b) { | ||
// _ 不相等,无法转换 | ||
return false | ||
} | ||
|
||
for i := range len(a) { | ||
ac := a[i] | ||
bc := b[i] | ||
if ac.c != bc.c { | ||
return false | ||
} | ||
// 如果我此时是L | ||
if ac.c == 'L' && ac.i < bc.i { | ||
return false | ||
} | ||
if ac.c == 'R' && ac.i > bc.i { | ||
return false | ||
} | ||
} | ||
return true | ||
} |
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