Skip to content

Commit

Permalink
add 0953
Browse files Browse the repository at this point in the history
  • Loading branch information
MdAbedin committed Jan 1, 2022
1 parent fb189bd commit de7350e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 0953 Swap Characters Once to Minimize Differences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution:
def solve(self, s, t):
matches = sum(a==b for a,b in zip(s,t))
mismatches = defaultdict(set)

for a,b in zip(s,t):
if a != b: mismatches[a].add(b)

if any(b in mismatches and a in mismatches[b] for a in mismatches for b in mismatches[a]):
return len(s) - (matches+2)

if any(char in mismatches for a in mismatches for char in mismatches[a]):
return len(s) - (matches+1)

return len(s) - matches

0 comments on commit de7350e

Please sign in to comment.