Skip to content

Commit cc6dc92

Browse files
solves is subsequence in python
1 parent eff67a9 commit cc6dc92

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RansomNote.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/ransom_note.py) |
106106
| 387 | [First Unique Character in String](https://leetcode.com/problems/first-unique-character-in-a-string) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FirstUniqueCharacter.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/first_unique_character_in_string.py) |
107107
| 389 | [Find the Difference](https://leetcode.com/problems/find-the-difference) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/FindTheDifference.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/find_the_difference.py) |
108-
| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsSubsequence.java) |
108+
| 392 | [Is Subsequence](https://leetcode.com/problems/is-subsequence) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/IsSubsequence.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/is_subsequence.py) |
109109
| 401 | [Binary Watch](https://leetcode.com/problems/binary-watch) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/BinaryWatch.java) |
110110
| 404 | [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/SumOfLeftLeaves.java) |
111111
| 405 | [Convert a Number to Hexadecimal](https://leetcode.com/problems/convert-a-number-to-hexadecimal) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ConvertNumberToHexadecimal.java) |

Diff for: python/find_the_difference.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
from typing import Dict
2-
3-
41
class Solution:
5-
def get_character_frequency(self, string: str) -> Dict[str, int]:
6-
frequency = {}
7-
for character in string:
8-
frequency[character] = frequency.get(character, 0) + 1
9-
return frequency
2+
def ascii_sum(self, string: str) -> int:
3+
return sum(ord(character) for character in string)
104

115
def findTheDifference(self, s: str, t: str) -> str:
12-
characters_s = self.get_character_frequency(s)
13-
for character in t:
14-
if characters_s.get(character, 0) == 0:
15-
return character
16-
else:
17-
characters_s[character] -= 1
6+
return chr(self.ascii_sum(t) - self.ascii_sum(s))

Diff for: python/is_subsequence.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def isSubsequence(self, s: str, t: str) -> bool:
3+
i, j = 0, 0
4+
while i < len(s) and j < len(t):
5+
if s[i] == t[j]:
6+
i += 1
7+
j += 1
8+
return i == len(s)

0 commit comments

Comments
 (0)