2023. Number of Pairs of Strings With Concatenation Equal to Target Medium
1/**
2 * [2023] Number of Pairs of Strings With Concatenation Equal to Target
3 *
4 * Given an array of digit strings nums and a digit string target, return the number of pairs of indices (i, j) (where i != j) such that the concatenation of nums[i] + nums[j] equals target.
5 *
6 * Example 1:
7 *
8 * Input: nums = ["777","7","77","77"], target = "7777"
9 * Output: 4
10 * Explanation: Valid pairs are:
11 * - (0, 1): "777" + "7"
12 * - (1, 0): "7" + "777"
13 * - (2, 3): "77" + "77"
14 * - (3, 2): "77" + "77"
15 *
16 * Example 2:
17 *
18 * Input: nums = ["123","4","12","34"], target = "1234"
19 * Output: 2
20 * Explanation: Valid pairs are:
21 * - (0, 1): "123" + "4"
22 * - (2, 3): "12" + "34"
23 *
24 * Example 3:
25 *
26 * Input: nums = ["1","1","1"], target = "11"
27 * Output: 6
28 * Explanation: Valid pairs are:
29 * - (0, 1): "1" + "1"
30 * - (1, 0): "1" + "1"
31 * - (0, 2): "1" + "1"
32 * - (2, 0): "1" + "1"
33 * - (1, 2): "1" + "1"
34 * - (2, 1): "1" + "1"
35 *
36 *
37 * Constraints:
38 *
39 * 2 <= nums.length <= 100
40 * 1 <= nums[i].length <= 100
41 * 2 <= target.length <= 100
42 * nums[i] and target consist of digits.
43 * nums[i] and target do not have leading zeros.
44 *
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/number-of-pairs-of-strings-with-concatenation-equal-to-target/
49// discuss: https://leetcode.com/problems/number-of-pairs-of-strings-with-concatenation-equal-to-target/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54 pub fn num_of_pairs(nums: Vec<String>, target: String) -> i32 {
55 0
56 }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_2023() {
67 }
68}
69
Back
© 2025 bowen.ge All Rights Reserved.