Skip to content

Commit

Permalink
chlng 11
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriSpiridonov committed Feb 11, 2021
1 parent 751529b commit 7abccbb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions Challenges/2021/January-LeetCoding-Challenge.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ None
|987.|[Vertical Order Traversal of a Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree/)|[Python](/Medium/987.VerticalOrderTraversalofaBinaryTree.py)|Medium|
|1675.|[Minimize Deviation in Array](https://leetcode.com/problems/minimize-deviation-in-array/)|~~Python~~|Hard|
|31.|[Next Permutation](https://leetcode.com/problems/next-permutation/)|~~Python~~|Medium|
|242.|[Valid Anagram](https://leetcode.com/problems/valid-anagram/)|[Python](/Easy/242.ValidAnagram.py)|Easy|

## License
The code is open-source and licensed under the [MIT License](/LICENSE).
42 changes: 42 additions & 0 deletions Easy/242.ValidAnagram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'''
Given two strings s and t , write a function to determine
if t is an anagram of s.
Example:
Input: s = "anagram", t = "nagaram"
Output: true
Example:
Input: s = "rat", t = "car"
Output: false
Note:
You may assume the string contains only lowercase alphabets.
Follow up:
What if the inputs contain unicode characters? How would
you adapt your solution to such case?
'''
#Dfficulty: Easy
#34 / 34 test cases passed.
#Runtime: 32 ms
#Memory Usage: 14.5 MB

#Runtime: 32 ms, faster than 98.22% of Python3 online submissions for Valid Anagram.
#Memory Usage: 14.5 MB, less than 48.96% of Python3 online submissions for Valid Anagram.

class Solution:
def isAnagram(self, s: str, t: str) -> bool:
if not s and not t: return True
if not s or not t or len(s) != len(t): return False
i = 0
c = set(s+t)
result = False
for l in c:
if l in s and l in t and s.count(l) == t.count(l):
result = True
continue
else:
result = False
break
return result
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ In this repository provided my Python solutions of LeetCode problems.

2021:
- [January LeetCoding Challenge](/Challenges/2021/January-LeetCoding-Challenge.md) - 27/31
- [February LeetCoding Challenge](/Challenges/2021/February-LeetCoding-Challenge.md) - 9/28
- [February LeetCoding Challenge](/Challenges/2021/February-LeetCoding-Challenge.md) - 10/28
<br><br>
## Solutions
*P.S. If you like this, please leave me a star.*
Expand Down Expand Up @@ -172,6 +172,7 @@ In this repository provided my Python solutions of LeetCode problems.
|234.|[Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/)|[Python](/Easy/234.PalindromeLinkedList.py)|Easy|`Linked List`|
|237.|[Delete Node in a Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list/)|[Python](/Easy/237.DeleteNodeinaLinkedList.py)|Easy|`Linked List`|
|238.|[Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/)|[Python](https://github.com/YuriSpiridonov/30-Day-LeetCoding-Challenge/blob/master/Week%203/ProductofArrayExceptSelf.py)|Medium|
|242.|[Valid Anagram](https://leetcode.com/problems/valid-anagram/)|[Python](/Easy/242.ValidAnagram.py)|Easy|
|257.|[Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths/)|[Python](/Easy/257.BinaryTreePaths.py)|Easy|`Binary Tree` (preorder), `Recursion`|
|258.|[Add Digits](https://leetcode.com/problems/add-digits/)|[Python](/Easy/258.AddDigits.py)|Easy||
|260.|[Single Number III](https://leetcode.com/problems/single-number-iii/)|[Python](/Medium/260.SingleNumberIII.py)|Medium|`Set`|
Expand Down

0 comments on commit 7abccbb

Please sign in to comment.