Thema ( Link )
Methode 1: Hash-Tabelle: die Verwendung von Counter()
import collections
class Solution:
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
if len(ransomNote)>len(magazine):
return False
return not collections.Counter(ransomNote)-collections.Counter(magazine)
Methode 1: Wie oben, die Verwendung von Counter()
import collections
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
if(len(s)!=len(t)):return False
return not collections.Counter(s)-collections.Counter(t)