Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9f0110d

Browse files
committed
Add solution #2023
1 parent 9e5a6bf commit 9f0110d

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,692 LeetCode solutions in JavaScript
1+
# 1,693 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1551,6 +1551,7 @@
15511551
2018|[Check if Word Can Be Placed In Crossword](./solutions/2018-check-if-word-can-be-placed-in-crossword.js)|Medium|
15521552
2019|[The Score of Students Solving Math Expression](./solutions/2019-the-score-of-students-solving-math-expression.js)|Hard|
15531553
2022|[Convert 1D Array Into 2D Array](./solutions/2022-convert-1d-array-into-2d-array.js)|Easy|
1554+
2023|[Number of Pairs of Strings With Concatenation Equal to Target](./solutions/2023-number-of-pairs-of-strings-with-concatenation-equal-to-target.js)|Medium|
15541555
2027|[Minimum Moves to Convert String](./solutions/2027-minimum-moves-to-convert-string.js)|Easy|
15551556
2033|[Minimum Operations to Make a Uni-Value Grid](./solutions/2033-minimum-operations-to-make-a-uni-value-grid.js)|Medium|
15561557
2037|[Minimum Number of Moves to Seat Everyone](./solutions/2037-minimum-number-of-moves-to-seat-everyone.js)|Easy|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* 2023. Number of Pairs of Strings With Concatenation Equal to Target
3+
* https://leetcode.com/problems/number-of-pairs-of-strings-with-concatenation-equal-to-target/
4+
* Difficulty: Medium
5+
*
6+
* Given an array of digit strings nums and a digit string target, return the number of pairs of
7+
* indices (i, j) (where i != j) such that the concatenation of nums[i] + nums[j] equals target.
8+
*/
9+
10+
/**
11+
* @param {string[]} nums
12+
* @param {string} target
13+
* @return {number}
14+
*/
15+
var numOfPairs = function(nums, target) {
16+
const map = new Map();
17+
let result = 0;
18+
19+
for (const num of nums) {
20+
if (target.startsWith(num)) {
21+
const suffix = target.slice(num.length);
22+
result += map.get(suffix) || 0;
23+
}
24+
if (target.endsWith(num)) {
25+
const prefix = target.slice(0, target.length - num.length);
26+
result += map.get(prefix) || 0;
27+
}
28+
map.set(num, (map.get(num) || 0) + 1);
29+
}
30+
31+
return result;
32+
};

0 commit comments

Comments
 (0)