更新 0383.赎金信 排版格式修复

This commit is contained in:
jinbudaily
2023-07-19 14:49:56 +08:00
parent 2948791011
commit 0922ede8c7

View File

@ -34,7 +34,7 @@ canConstruct("aa", "aab") -> true
* 第二点 “你可以假设两个字符串均只含有小写字母。” *说明只有小写字母*,这一点很重要
## 暴力解法
### 暴力解法
那么第一个思路其实就是暴力枚举了两层for循环不断去寻找代码如下
@ -66,7 +66,7 @@ public:
这里时间复杂度是比较高的而且里面还有一个字符串删除也就是erase的操作也是费时的当然这段代码也可以过这道题。
## 哈希解法
### 哈希解法
因为题目所只有小写字母,那可以采用空间换取时间的哈希策略, 用一个长度为26的数组还记录magazine里字母出现的次数。
@ -112,8 +112,8 @@ public:
## 其他语言版本
### Java
Java
```Java
class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
@ -146,8 +146,9 @@ class Solution {
```
Python
### Python
(版本一)使用数组
```python
class Solution:
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
@ -213,7 +214,7 @@ class Solution:
return all(ransomNote.count(c) <= magazine.count(c) for c in set(ransomNote))
```
Go
### Go
```go
func canConstruct(ransomNote string, magazine string) bool {
@ -231,7 +232,7 @@ func canConstruct(ransomNote string, magazine string) bool {
}
```
javaScript:
### JavaScript:
```js
/**
@ -254,7 +255,7 @@ var canConstruct = function(ransomNote, magazine) {
};
```
TypeScript:
### TypeScript:
```typescript
function canConstruct(ransomNote: string, magazine: string): boolean {
@ -275,8 +276,8 @@ function canConstruct(ransomNote: string, magazine: string): boolean {
};
```
### PHP:
PHP:
```php
class Solution {
/**
@ -301,7 +302,8 @@ class Solution {
}
```
Swift
### Swift
```swift
func canConstruct(_ ransomNote: String, _ magazine: String) -> Bool {
var record = Array(repeating: 0, count: 26);
@ -324,7 +326,8 @@ func canConstruct(_ ransomNote: String, _ magazine: String) -> Bool {
}
```
Rust:
### Rust:
```rust
impl Solution {
pub fn can_construct(ransom_note: String, magazine: String) -> bool {
@ -347,7 +350,7 @@ impl Solution {
}
```
Scala:
### Scala:
版本一: 使用数组作为哈希表
```scala
@ -411,8 +414,8 @@ object Solution {
}
```
### C#
C#
```csharp
public bool CanConstruct(string ransomNote, string magazine) {
if(ransomNote.Length > magazine.Length) return false;
@ -434,3 +437,4 @@ public bool CanConstruct(string ransomNote, string magazine) {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>