Skip to content

Commit ec33ae9

Browse files
authored
Update number-of-pairs-of-strings-with-concatenation-equal-to-target.cpp
1 parent f51c978 commit ec33ae9

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

C++/number-of-pairs-of-strings-with-concatenation-equal-to-target.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@ class Solution {
1010
if (size(num) > size(target)) {
1111
continue;
1212
}
13+
const int cnt1 = lookup[-(size(target) - size(num))], cnt2 = lookup[size(target) - size(num)];
1314
if (!target.compare(0, size(num), num)) { // in c++ 20, we can directly use starts_with, see https://en.cppreference.com/w/cpp/string/basic_string/starts_with
14-
result += lookup[-(size(target) - size(num))];
15-
}
16-
if (!target.compare(size(target) - size(num), size(num), num)) {
17-
result += lookup[size(target) - size(num)];
18-
}
19-
if (!target.compare(0, size(num), num)) { // in c++ 20, we can directly use ends_with, see https://en.cppreference.com/w/cpp/string/basic_string/ends_with
15+
result += cnt1;
2016
++lookup[size(num)];
2117
}
2218
if (!target.compare(size(target) - size(num), size(num), num)) {
19+
result += cnt2;
2320
++lookup[-size(num)];
2421
}
2522
}

0 commit comments

Comments
 (0)