forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* No.0777.Swap Adjacent in LR String * No.2337.Move Pieces to Obtain a String
- Loading branch information
Showing
13 changed files
with
478 additions
and
81 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
17 changes: 17 additions & 0 deletions
17
solution/0700-0799/0777.Swap Adjacent in LR String/Solution.cpp
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class Solution { | ||
public: | ||
bool canTransform(string start, string end) { | ||
int n = start.size(); | ||
int i = 0, j = 0; | ||
while (true) { | ||
while (i < n && start[i] == 'X') ++i; | ||
while (j < n && end[j] == 'X') ++j; | ||
if (i == n && j == n) return true; | ||
if (i == n || j == n || start[i] != end[j]) return false; | ||
if (start[i] == 'L' && i < j) return false; | ||
if (start[i] == 'R' && i > j) return false; | ||
++i; | ||
++j; | ||
} | ||
} | ||
}; |
25 changes: 25 additions & 0 deletions
25
solution/0700-0799/0777.Swap Adjacent in LR 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
func canTransform(start string, end string) bool { | ||
n := len(start) | ||
i, j := 0, 0 | ||
for { | ||
for i < n && start[i] == 'X' { | ||
i++ | ||
} | ||
for j < n && end[j] == 'X' { | ||
j++ | ||
} | ||
if i == n && j == n { | ||
return true | ||
} | ||
if i == n || j == n || start[i] != end[j] { | ||
return false | ||
} | ||
if start[i] == 'L' && i < j { | ||
return false | ||
} | ||
if start[i] == 'R' && i > j { | ||
return false | ||
} | ||
i, j = i+1, j+1 | ||
} | ||
} |
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
Oops, something went wrong.