File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 1+ # Valid Anagram
2+ # https://leetcode.com/problems/valid-anagram/
3+
4+ class Solution (object ):
5+ def putInHash (self , s ):
6+ hashTable = {}
7+ for char in s :
8+ if (char not in hashTable ):
9+ hashTable [char ] = 0
10+ hashTable [char ] = hashTable [char ] + 1
11+ return hashTable
12+
13+ def searchInHash (self , t , hashTable ):
14+ # find the char in hash table.
15+ for char in t :
16+ if (char not in hashTable ):
17+ return False
18+ hashTable [char ] = hashTable [char ] - 1
19+ # Make sure all count is zero in hash table
20+ for key in hashTable :
21+ if (hashTable [key ] != 0 ):
22+ return False
23+ return True
24+
25+ def isAnagram (self , s , t ):
26+ hashTable = self .putInHash (s )
27+ return self .searchInHash (t , hashTable )
28+ """
29+ :type s: str
30+ :type t: str
31+ :rtype: bool
32+ """
33+
Original file line number Diff line number Diff line change 230230 </p>
231231 </li>
232232 <li>Minimum Window Substring</li>
233- <li>Valid Anagram</li>
233+ <li><a href="Programs/Valid Anagram.py">Valid Anagram</a>
234+ <p><b>Approach</b>: Used hash table.
235+ </p>
236+ </li>
234237 <li>Group Anagrams</li>
235238 <li>Valid Parentheses</li>
236239 <li>Valid Palindrome</li>
You can’t perform that action at this time.
0 commit comments