#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param s string字符串
# @param c string字符串
# @return int整型
# 出错位置: 最后统计时候累加的是s_list[i] 的值
class Solution:
def isCongruent(self , s: str, c: str) -> int:
# write code here
s_list=[0]*26
c_list=[0]*26
s_len=len(s)
c_len=len(c)
if s_len!=c_len:
return -1
for i in range(s_len):
s_list[ord(s[i])-ord('a')]+=1
for i in range(c_len):
c_list[ord(c[i])-ord('a')]+=1
if sum(s_list) !=sum(c_list):
return -1
count =0
print(s_list)
print(c_list)
for i in range(len(s_list)):
if s_list[i]==0 and c_list[i]==0:
continue
if s_list[i]!= c_list[i]:
return -1
if s_list[i]==c_list[i] and s_list[i] !=0 and c_list[i]!=0:
count+=s_list[i] # 累加次数 -
return count