Skip to content

Commit

Permalink
Create 2337_Move_Pieces_to_Obtain_a_String.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Nothing-avil authored Dec 5, 2024
1 parent e80f6a7 commit c001b6f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions 2337_Move_Pieces_to_Obtain_a_String.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ███████╗ █████╗ ███╗ ██╗ ██████╗ █████╗ ██████╗ ██████╗ ██╗ ██╗
// ██╔════╝ ██╔══██╗ ████╗ ██║ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██╔══██╗ ██║ ██║
// ███████╗ ███████║ ██╔██╗ ██║ ██║ ██║ ███████║ ██████╔╝ ██████╔╝ ███████║
// ╚════██║ ██╔══██║ ██║╚██╗██║ ██║ ██║ ██╔══██║ ██╔═██╗ ██╔══██╗ ██╔══██║
// ███████║ ██║ ██║ ██║ ╚████║ ██████╔╝ ██║ ██║ ██║ ██╗ ██████╔╝ ██║ ██║
// ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
#pragma GCC optimize("Ofast", "inline", "ffast-math", "unroll-loops","no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native", "f16c")
auto init = []() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 'c';
}();
class Solution {
public:
bool canChange(string start, string target) {
int i=0, j=0;
int n1= start.size(), n2= target.size();
while(true){
while (i < n1 && start[i] == '_') ++i;
while (j < n2 && target[j] == '_') ++j;
if(i==n1 && j==n2){
return true;
}
if(i==n1 || j==n2 || start[i] != target[j]){
return false;
}
if(start[i] == 'L' && i < j){
return false;
}
if(start[i]== 'R' && i > j){
return false;
}
i++;
j++;
}
}
};

0 comments on commit c001b6f

Please sign in to comment.