mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 02:53:31 +08:00
添加 0383.赎金信.md Python3版本
使用collections.Counter实现
This commit is contained in:
@ -209,6 +209,22 @@ class Solution(object):
|
||||
return True
|
||||
```
|
||||
|
||||
Python写法四:
|
||||
|
||||
```python3
|
||||
class Solution:
|
||||
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
|
||||
c1 = collections.Counter(ransomNote)
|
||||
c2 = collections.Counter(magazine)
|
||||
x = c1 - c2
|
||||
#x只保留值大于0的符号,当c1里面的符号个数小于c2时,不会被保留
|
||||
#所以x只保留下了,magazine不能表达的
|
||||
if(len(x)==0):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
```
|
||||
|
||||
Go:
|
||||
|
||||
```go
|
||||
|
Reference in New Issue
Block a user