"aba","aa"
-1
第一个字符串与第二个字符串a出现的次数相同,而b出现的次数不同,不符合每个字符出现的次数都相同。故输出-1
"a","a"
1
第一个字符串与第二个字符串每个字符出现的次数都相同,故输出相同的长度为1
class Solution: def isCongruent(self , s: str, c: str) -> int: # write code here return len(s) if sorted(s) == sorted(c) else -1
from collections import Counter class Solution: def isCongruent(self , s: str, c: str) -> int: # write code here d1 = Counter(s) d2 = Counter(c) if d1==d2: return len(s) return -1
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题