Skip to content

Commit 0a5c4d9

Browse files
solves valid anagram in python
1 parent bd64387 commit 0a5c4d9

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
| 234 | [Palindrome Linked Lists](https://leetcode.com/problems/palindrome-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/PalindromeLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/palindrome_linked_list.py) |
7373
| 235 | [Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/LowestCommonAncestorOfBinarySearchTree.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/lowest_common_ancestor_of_bst.py) |
7474
| 237 | [Delete a Node In A Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/DeleteANodeInLinkedList.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) |
75-
| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidAnagram.java) |
75+
| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](src/ValidAnagram.java) [![Python](https://img.icons8.com/color/35/000000/python.png)](python/delete_node_in_linked_list.py) |
7676
| 243 | [Shortest Word Distance](https://leetcode.com/problems/shortest-word-distance) | Easy | |
7777
| 246 | [Strobogramatic Number](https://leetcode.com/problems/strobogrammatic-number) | Easy | |
7878
| 252 | [Meeting Rooms](https://leetcode.com/problems/meeting-rooms) | Easy | |

python/lowest_common_ancestor_of_bst.py

-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ def __init__(self, x):
88
self.left = None
99
self.right = None
1010

11-
def __repr__(self):
12-
return str(self.val)
13-
14-
def __str__(self):
15-
return str(self.val)
16-
1711

1812
class Solution:
1913
def get_path_to(self, root: TreeNode, node: TreeNode) -> deque:

python/valid_anagram.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from typing import Dict
2+
3+
4+
class Solution:
5+
def character_frequency(self, string: str) -> Dict[str, int]:
6+
frequencies = {}
7+
for character in string:
8+
frequencies[character] = frequencies.get(character, 0) + 1
9+
return frequencies
10+
11+
def isAnagram(self, s: str, t: str) -> bool:
12+
if len(s) != len(t):
13+
return False
14+
char_freq_s = self.character_frequency(s)
15+
char_freq_t = self.character_frequency(t)
16+
return char_freq_s == char_freq_t

0 commit comments

Comments
 (0)