Skip to content

Commit 581e232

Browse files
committed
11/20/2020
1 parent cc1969e commit 581e232

7 files changed

+59
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ edition = "2018"
66

77
[dependencies]
88
leetcode_prelude = "0.2"
9-
rustgym = "0.1.1"
9+
rustgym = "0.1.1"
10+
rand = "0.7.3"

src/_0350_intersection_of_two_arrays_ii.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl Solution {
1515
let mut result: Vec<i32> = vec![];
1616
for (n1, o1) in map_1 {
1717
if let Some(&o2) = map_2.get(&n1.clone()) {
18-
for i in 0..o1.min(o2) {
18+
for _i in 0..o1.min(o2) {
1919
result.push(n1.clone());
2020
}
2121
}

src/_0386_lexicographical_numbers.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
struct Solution;
2+
3+
impl Solution {
4+
pub fn lexical_order(n: i32) -> Vec<i32> {
5+
let mut result = vec![];
6+
Self::dfs(0, n, &mut result);
7+
result
8+
}
9+
10+
fn dfs(current: i32, n: i32, result: &mut Vec<i32>) {
11+
if current > n {
12+
return;
13+
}
14+
for i in 0..10 {
15+
let temp = current * 10 + i;
16+
if temp != 0 && temp <= n {
17+
result.push(temp);
18+
Self::dfs(temp, n, result);
19+
}
20+
}
21+
}
22+
}
23+
24+
#[test]
25+
fn test() {
26+
assert_eq!(
27+
Solution::lexical_order(13),
28+
vec![1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9]
29+
);
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
struct Solution;
2+
3+
use rand::distributions::Uniform;
4+
use rand::thread_rng;
5+
use rand::Rng;
6+
7+
impl Solution {
8+
pub fn rand10() -> i32 {
9+
let mut i = 50;
10+
while i > 40 {
11+
i = (Self::rand7() - 1) * 7 + Self::rand7();
12+
}
13+
(i - 1) % 10 + 1
14+
}
15+
fn rand7() -> i32 {
16+
let distribution: Uniform<i32> = Uniform::new(0, 7);
17+
let mut rng = thread_rng();
18+
rng.sample(distribution) + 1
19+
}
20+
}

src/_0977_squares_of_a_sorted_array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ struct Solution;
22

33
impl Solution {
44
pub fn sorted_squares(mut a: Vec<i32>) -> Vec<i32> {
5-
a.iter_mut().for_each(|mut s| {
5+
a.iter_mut().for_each(|s| {
66
*s *= *s;
77
});
88
a.sort();

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ mod _0371_sum_of_two_integers;
154154
//
155155
mod _0383_ransom_note;
156156
//
157+
mod _0386_lexicographical_numbers;
158+
//
157159
mod _0387_first_unique_character_in_a_string;
158160
//
159161
mod _0394_decode_string;
@@ -168,6 +170,8 @@ mod _0443_string_compression;
168170
//
169171
mod _0448_find_all_numbers_disappeared_in_an_array;
170172
//
173+
mod _0470_implement_rand10_using_rand7;
174+
//
171175
mod _0496_next_greater_element_i;
172176
//
173177
mod _0503_next_greater_element_ii;

0 commit comments

Comments
 (0)