cs: add «3042. Count Prefix and Suffix Pairs I»

URL:	https://leetcode.com/problems/count-prefix-and-suffix-pairs-i/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2025-01-08 21:28:05 +01:00
parent 6dfd741e6a
commit 083d7c3da1
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,18 @@
public class Solution {
private bool IsPrefixAndSuffix(string str1, string str2) =>
str1.Length <= str2.Length && str2.StartsWith(str1) && str2.EndsWith(str1);
public int CountPrefixSuffixPairs(string[] words) {
var count = 0;
for (var i = 0; i < words.Length; ++i) {
for (var j = i + 1; j < words.Length; ++j) {
if (IsPrefixAndSuffix(words[i], words[j])) {
++count;
}
}
}
return count;
}
}