leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2337.cpp (566B)


0 class Solution { 1 public: 2 bool canChange(const string &start, const string &target) const { 3 const int n = size(start); 4 int i = 0, j = 0; 5 6 while (i < n || j < n) { 7 while (i < n && start[i] == '_') 8 i++; 9 while (j < n && target[j] == '_') 10 j++; 11 12 if (i == n || j == n) return i == n && j == n; 13 14 if (start[i] != target[j]) return false; 15 if (start[i] == 'R' ? i > j : i < j) return false; 16 17 i++, j++; 18 } 19 20 return true; 21 } 22 };