Skip to content

Commit 9cd69c8

Browse files
committed
D. J.:
- Added the leetcode problem and solution for 389
1 parent 8831152 commit 9cd69c8

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
- [377 Combination Sum IV](https://leetcode.com/problems/combination-sum-iv/description/)
230230
- [380 Insert Delete GetRandom O(1)](https://leetcode.com/problems/insert-delete-getrandom-o1/description/)
231231
- [383 Ransom Note](https://leetcode.com/problems/ransom-note/description/)
232+
- [389 Find the Difference](https://leetcode.com/problems/find-the-difference/description/)
232233
- [392 Is Subsequence](https://leetcode.com/problems/is-subsequence/description/)
233234
- [394 Decode String](https://leetcode.com/problems/decode-string/description/)
234235
- [399 Evaluate Division](https://leetcode.com/problems/evaluate-division/description/)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
"""Base class for all LeetCode Problems."""
3+
4+
def findTheDifference(self, s: str, t: str) -> str:
5+
"""
6+
You are given two strings s and t.
7+
8+
String t is generated by random shuffling string s and then add one more letter
9+
at a random position.
10+
11+
Return the letter that was added to t.
12+
"""
13+
result = 0
14+
for c in s + t:
15+
result ^= ord(c)
16+
return chr(result)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
from awesome_python_leetcode._389_find_the_difference import Solution
4+
5+
6+
@pytest.mark.parametrize(
7+
argnames=["s", "t", "expected"],
8+
argvalues=[
9+
("abcd", "abcde", "e"),
10+
("", "y", "y"),
11+
],
12+
)
13+
def test_func(s: str, t: str, expected: str):
14+
"""Tests the solution of a LeetCode problem."""
15+
difference = Solution().findTheDifference(s, t)
16+
assert difference == expected

0 commit comments

Comments
 (0)