kucheasysa

Algoverse_adesh_9

Jun 5th, 2024
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. class Solution:
  2.     def areAlmostEqual(self, s1: str, s2: str) -> bool:
  3.         c=0
  4.         x={}
  5.         a={}
  6.         for i in range(len(s1)):
  7.             if s1[i] not in x:
  8.                 x[s1[i]]=1
  9.             else:
  10.                 x[s1[i]]+=1
  11.             if s2[i] not in a:
  12.                 a[s2[i]]=1
  13.             else:
  14.                 a[s2[i]]+=1
  15.  
  16.             if s1[i]!=s2[i]:
  17.                 c+=1
  18.         if (c==2 or c==0) and sorted(x.items())==sorted(a.items()):
  19.             return True
  20.         else:
  21.             return False
Advertisement
Add Comment
Please, Sign In to add comment