Skip to content

Commit 4f148b3

Browse files
Merge branch 'doocs:main' into main
2 parents 45f4385 + c692eef commit 4f148b3

File tree

115 files changed

+5446
-171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+5446
-171
lines changed

solution/0000-0099/0014.Longest Common Prefix/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ difficulty: 简单
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0000-0099/0014.Longest%20Common%20Prefix/README.md
55
tags:
66
- 字典树
7+
- 数组
78
- 字符串
89
---
910

solution/0000-0099/0014.Longest Common Prefix/README_EN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ difficulty: Easy
44
edit_url: https://github.com/doocs/leetcode/edit/main/solution/0000-0099/0014.Longest%20Common%20Prefix/README_EN.md
55
tags:
66
- Trie
7+
- Array
78
- String
89
---
910

solution/0500-0599/0506.Relative Ranks/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ class Solution {
9797
public String[] findRelativeRanks(int[] score) {
9898
int n = score.length;
9999
Integer[] idx = new Integer[n];
100-
for (int i = 0; i < n; ++i) {
101-
idx[i] = i;
102-
}
100+
Arrays.setAll(idx, i -> i);
103101
Arrays.sort(idx, (i1, i2) -> score[i2] - score[i1]);
104102
String[] ans = new String[n];
105103
String[] top3 = new String[] {"Gold Medal", "Silver Medal", "Bronze Medal"};

solution/0500-0599/0506.Relative Ranks/README_EN.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ class Solution {
9696
public String[] findRelativeRanks(int[] score) {
9797
int n = score.length;
9898
Integer[] idx = new Integer[n];
99-
for (int i = 0; i < n; ++i) {
100-
idx[i] = i;
101-
}
99+
Arrays.setAll(idx, i -> i);
102100
Arrays.sort(idx, (i1, i2) -> score[i2] - score[i1]);
103101
String[] ans = new String[n];
104102
String[] top3 = new String[] {"Gold Medal", "Silver Medal", "Bronze Medal"};

solution/0500-0599/0506.Relative Ranks/Solution.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ class Solution {
22
public String[] findRelativeRanks(int[] score) {
33
int n = score.length;
44
Integer[] idx = new Integer[n];
5-
for (int i = 0; i < n; ++i) {
6-
idx[i] = i;
7-
}
5+
Arrays.setAll(idx, i -> i);
86
Arrays.sort(idx, (i1, i2) -> score[i2] - score[i1]);
97
String[] ans = new String[n];
108
String[] top3 = new String[] {"Gold Medal", "Silver Medal", "Bronze Medal"};

solution/0500-0599/0594.Longest Harmonious Subsequence/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,28 @@ function findLHS(nums: number[]): number {
174174
}
175175
```
176176

177+
#### Rust
178+
179+
```rust
180+
use std::collections::HashMap;
181+
182+
impl Solution {
183+
pub fn find_lhs(nums: Vec<i32>) -> i32 {
184+
let mut cnt = HashMap::new();
185+
for &x in &nums {
186+
*cnt.entry(x).or_insert(0) += 1;
187+
}
188+
let mut ans = 0;
189+
for (&x, &c) in &cnt {
190+
if let Some(&y) = cnt.get(&(x + 1)) {
191+
ans = ans.max(c + y);
192+
}
193+
}
194+
ans
195+
}
196+
}
197+
```
198+
177199
<!-- tabs:end -->
178200

179201
<!-- solution:end -->

solution/0500-0599/0594.Longest Harmonious Subsequence/README_EN.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,28 @@ function findLHS(nums: number[]): number {
170170
}
171171
```
172172

173+
#### Rust
174+
175+
```rust
176+
use std::collections::HashMap;
177+
178+
impl Solution {
179+
pub fn find_lhs(nums: Vec<i32>) -> i32 {
180+
let mut cnt = HashMap::new();
181+
for &x in &nums {
182+
*cnt.entry(x).or_insert(0) += 1;
183+
}
184+
let mut ans = 0;
185+
for (&x, &c) in &cnt {
186+
if let Some(&y) = cnt.get(&(x + 1)) {
187+
ans = ans.max(c + y);
188+
}
189+
}
190+
ans
191+
}
192+
}
193+
```
194+
173195
<!-- tabs:end -->
174196

175197
<!-- solution:end -->
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::collections::HashMap;
2+
3+
impl Solution {
4+
pub fn find_lhs(nums: Vec<i32>) -> i32 {
5+
let mut cnt = HashMap::new();
6+
for &x in &nums {
7+
*cnt.entry(x).or_insert(0) += 1;
8+
}
9+
let mut ans = 0;
10+
for (&x, &c) in &cnt {
11+
if let Some(&y) = cnt.get(&(x + 1)) {
12+
ans = ans.max(c + y);
13+
}
14+
}
15+
ans
16+
}
17+
}

solution/0800-0899/0853.Car Fleet/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ class Solution {
125125
public int carFleet(int target, int[] position, int[] speed) {
126126
int n = position.length;
127127
Integer[] idx = new Integer[n];
128-
for (int i = 0; i < n; ++i) {
129-
idx[i] = i;
130-
}
128+
Arrays.setAll(idx, i -> i);
131129
Arrays.sort(idx, (i, j) -> position[j] - position[i]);
132130
int ans = 0;
133131
double pre = 0;

solution/0800-0899/0853.Car Fleet/README_EN.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ class Solution {
117117
public int carFleet(int target, int[] position, int[] speed) {
118118
int n = position.length;
119119
Integer[] idx = new Integer[n];
120-
for (int i = 0; i < n; ++i) {
121-
idx[i] = i;
122-
}
120+
Arrays.setAll(idx, i -> i);
123121
Arrays.sort(idx, (i, j) -> position[j] - position[i]);
124122
int ans = 0;
125123
double pre = 0;

0 commit comments

Comments
 (0)