Skip to content

Commit f51c978

Browse files
authored
Update number-of-pairs-of-strings-with-concatenation-equal-to-target.py
1 parent 05c3bee commit f51c978

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

Python/number-of-pairs-of-strings-with-concatenation-equal-to-target.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ def numOfPairs(self, nums, target):
1414
lookup = collections.Counter()
1515
result = 0
1616
for num in nums:
17+
cnt1, cnt2 = lookup[-(len(target)-len(num))], lookup[len(target)-len(num)]
1718
if target.startswith(num):
18-
result += lookup[-(len(target)-len(num))]
19-
if target.endswith(num):
20-
result += lookup[len(target)-len(num)]
21-
if target.startswith(num):
19+
result += cnt1
2220
lookup[len(num)] += 1
2321
if target.endswith(num):
22+
result += cnt2
2423
lookup[-len(num)] += 1
2524
return result
2625

0 commit comments

Comments
 (0)