-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy path0777-SwapAdjacentInLRString.cs
32 lines (28 loc) · 1.09 KB
/
0777-SwapAdjacentInLRString.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//-----------------------------------------------------------------------------
// Runtime: 72ms
// Memory Usage:
// Link:
//-----------------------------------------------------------------------------
namespace LeetCode
{
public class _0777_SwapAdjacentInLRString
{
public bool CanTransform(string start, string end)
{
var N = start.Length;
var startIndex = -1;
var endIndex = -1;
while (++startIndex < N && ++endIndex < N)
{
while (startIndex < N && start[startIndex] == 'X') startIndex++;
while (endIndex < N && end[endIndex] == 'X') endIndex++;
if ((startIndex == N && endIndex < N) || (startIndex < N && endIndex == N))
return false;
if (startIndex < N && endIndex < N)
if (start[startIndex] != end[endIndex] || (start[startIndex] == 'L' && startIndex < endIndex) || (start[startIndex] == 'R' && startIndex > endIndex))
return false;
}
return true;
}
}
}