Skip to content

Commit edba1a4

Browse files
committed
Feb 5
1 parent c63c36d commit edba1a4

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution:
2+
def areAlmostEqual(self, s1: str, s2: str) -> bool:
3+
count = 0
4+
s1_freq, s2_freq = [0] * 26, [0] * 26
5+
for ch1, ch2 in zip(s1, s2):
6+
count += ch1 != ch2
7+
if count > 2:
8+
return False
9+
s1_freq[ord(ch1)-ord('a')] += 1
10+
s2_freq[ord(ch2)-ord('a')] += 1
11+
return s1_freq == s2_freq
12+
13+
14+
def main():
15+
s1 = 'bank'
16+
s2 = 'kanb'
17+
assert Solution().areAlmostEqual(s1, s2) is True
18+
19+
s1 = 'attack'
20+
s2 = 'defend'
21+
assert Solution().areAlmostEqual(s1, s2) is False
22+
23+
s1 = 'kelb'
24+
s2 = 'kelb'
25+
assert Solution().areAlmostEqual(s1, s2) is True
26+
27+
28+
if __name__ == '__main__':
29+
main()

2025-02-February-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
| February 02 | [1752. Check if Array Is Sorted and Rotated](https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/) | Easy | Solved |
99
| February 03 | [3105. Longest Strictly Increasing or Strictly Decreasing Subarray](https://leetcode.com/problems/longest-strictly-increasing-or-strictly-decreasing-subarray/) | Easy | Solved |
1010
| February 04 | [1800. Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum/) | Easy | Solved |
11-
| February 05 | []() | | |
11+
| February 05 | [1790. Check if One String Swap Can Make Strings Equal](https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal/) | Easy | Solved |
1212
| February 06 | []() | | |
1313
| February 07 | []() | | |
1414
| February 08 | []() | | |
@@ -37,6 +37,6 @@
3737
## Summary
3838
| Level | Problems | Solved | Unsolved |
3939
| --- | --- | --- | --- |
40-
| Easy | 4 | 4 | 0 |
40+
| Easy | 5 | 5 | 0 |
4141
| Medium | 0 | 0 | 0 |
4242
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)