Skip to content

Commit 0fb22e4

Browse files
committed
Adding Accepted Solution - Problem - 3 - Ransom Note
1 parent 35e6786 commit 0fb22e4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
##==================================
2+
## Leetcode May Challenge
3+
## Username: Vanditg
4+
## Year: 2020
5+
## Problem: 3
6+
## Problem Name: Ransom Note
7+
##===================================
8+
#
9+
#Given an arbitrary ransom note string and another string containing letters from all the magazines,
10+
#write a function that will return true if the ransom note can be constructed from the magazines ; otherwise, it will return false.
11+
#
12+
#Each letter in the magazine string can only be used once in your ransom note.
13+
#
14+
#Note:
15+
#You may assume that both strings contain only lowercase letters.
16+
#
17+
#canConstruct("a", "b") -> false
18+
#canConstruct("aa", "ab") -> false
19+
#canConstruct("aa", "aab") -> true
20+
from collections import Counter as c #Importing Counter module
21+
class Solution:
22+
def canConstruct(self, ransomNote, magazine):
23+
return not c(ransomNote) - c(magazine) #Return True if ransom note constructed from magazine otherwise false

0 commit comments

Comments
 (0)