mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
@ -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