Skip to content

Commit

Permalink
Added Validate Anagram
Browse files Browse the repository at this point in the history
  • Loading branch information
puneeter committed Dec 29, 2024
1 parent 417959b commit 781adc1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions LeetCode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
| [Swap nodes in pairs](SwapNodesInPairs.py) | :heavy_check_mark: | `#recursion` `#linked-list` | Python |
| [Two Sum](TwoSum.py) | :heavy_check_mark: | `#array` `#hash-table` | Python |
| [Validate Binary Search Tree](ValidateBinarySearchTree.py) | :heavy_check_mark: | `#recursion` `#tree` | Python |
| [Validate Anagram](ValidateAnagram.py) | :heavy_check_mark: | `#hash-table` `#string` `sorting` | Python |
| [Valid Parantheses](ValidParantheses.py) | :heavy_check_mark: | `#string` `#stack` | Python |
| [ZipZag Conversion](ZigZagConversion.py) | :heavy_check_mark: | `#string` | Python |

Expand Down
19 changes: 19 additions & 0 deletions LeetCode/ValidAnagram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution(object):
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
word_freq = {}
for word in s:
if word in word_freq:
word_freq[word] += 1
else:
word_freq[word] = 1
for word in t:
if word in word_freq:
word_freq[word] -= 1
else:
return False
return True if all(val == 0 for val in word_freq.values()) else False

0 comments on commit 781adc1

Please sign in to comment.