mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 20:40:39 +08:00
Merge pull request #2333 from qiu121/master
📝 Update 0383.赎金信.md with python3 && 📝 Update 0344.反转字符串.md with python3
This commit is contained in:
@ -250,6 +250,20 @@ class Solution:
|
|||||||
s[:] = [s[i] for i in range(len(s) - 1, -1, -1)]
|
s[:] = [s[i] for i in range(len(s) - 1, -1, -1)]
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
(版本七) 使用reverse()
|
||||||
|
|
||||||
|
```python
|
||||||
|
class Solution:
|
||||||
|
def reverseString(self, s: List[str]) -> None:
|
||||||
|
"""
|
||||||
|
Do not return anything, modify s in-place instead.
|
||||||
|
"""
|
||||||
|
# 原地反转,无返回值
|
||||||
|
s.reverse()
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
### Go:
|
### Go:
|
||||||
|
|
||||||
```Go
|
```Go
|
||||||
|
@ -214,6 +214,19 @@ class Solution:
|
|||||||
return all(ransomNote.count(c) <= magazine.count(c) for c in set(ransomNote))
|
return all(ransomNote.count(c) <= magazine.count(c) for c in set(ransomNote))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
(版本六)使用count(简单易懂)
|
||||||
|
|
||||||
|
```python3
|
||||||
|
class Solution:
|
||||||
|
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
|
||||||
|
for char in ransomNote:
|
||||||
|
if char in magazine and ransomNote.count(char) <= magazine.count(char):
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
```
|
||||||
|
|
||||||
### Go:
|
### Go:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
Reference in New Issue
Block a user