Skip to content

Commit 7e90df3

Browse files
authored
Create check-if-strings-can-be-made-equal-with-operations-ii.cpp
1 parent 3e8fd57 commit 7e90df3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Time: O(1)
2+
// Space: O(1)
3+
4+
// freq table
5+
class Solution {
6+
public:
7+
bool checkStrings(string s1, string s2) {
8+
vector<vector<int>> lookup1(2, vector<int>(26)), lookup2(2, vector<int>(26));
9+
for (int i = 0; i < 2; ++i) {
10+
for (int j = i; j < size(s1); j += 2) {
11+
++lookup1[i][s1[j] - 'a'];
12+
}
13+
for (int j = i; j < size(s1); j += 2) {
14+
++lookup2[i][s2[j] - 'a'];
15+
}
16+
}
17+
return lookup1 == lookup2;
18+
}
19+
};

0 commit comments

Comments
 (0)