15 lines
493 B
Dart
15 lines
493 B
Dart
extension StringExtensions on String {
|
|
/// Returns true if given word contains atleast all the characters in [targetChars], and `false` otherwise
|
|
///
|
|
/// Very efficient `O(n)` instead of naive `O(n*m)`
|
|
bool containsAllCharacters({required String targetChars}) {
|
|
final Set<String> characterSet = Set.from(targetChars.split(''));
|
|
for (final testChar in split('')) {
|
|
characterSet.remove(testChar);
|
|
if (characterSet.isEmpty) return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|