Skip to content

Commit 3408c62

Browse files
committed
12/5/2020
1 parent bf833f3 commit 3408c62

7 files changed

+87
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ leetcode practise solution in rust
8888
|404|[Sum of Left Leaves](src/_0404_sum_of_left_leaves.rs)|
8989
|412|[Fizz Buzz ](src/_0412_fizz_buzz.rs)|
9090
|415|[Add Strings ](src/_0415_add_strings.rs)|
91+
|437|[Path Sum III](src/_0437_path_sum_iii.rs)|
9192
|443|[String Compression](src/_0443_string_compression.rs)|
9293
|448|[Find All Numbers Disappeared in an Array](src/_0448_find_all_numbers_disappeared_in_an_array.rs)|
9394
|470|[Implement Rand10() Using Rand7()](src/_0470_implement_rand10_using_rand7.rs)|
@@ -151,4 +152,6 @@ leetcode practise solution in rust
151152
|1598|[Crawler Log Folder](src/_1598_rawler_log_folder.rs)|
152153
|1608|[Special Array With X Elements Greater Than or Equal X](src/_1608_special_array_with_x_elements_greater_than_or_equal_x.rs)|
153154
|1609|[Even Odd Tree](src/_1609_even_odd_tree.rs)|
154-
155+
|1678|[Goal Parser Interpretation](src/_1678_goal_parser_interpretation.rs)|
156+
|1679|[Max Number of K-Sum Pairs](src/_1679_max_number_of_k-sum_pairs.rs)|
157+
|1680|[Concatenation of Consecutive Binary Numbers](src/_1680_concatenation_of_consecutive_binary_numbers.rs)|

src/_0437_path_sum_iii.rs

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
struct Solution;
2+
impl Solution {
3+
pub fn interpret(command: String) -> String {
4+
command.replace("()", "o").replace("(al)", "al")
5+
}
6+
}
7+
8+
#[test]
9+
fn test() {
10+
assert_eq!(
11+
Solution::max_operations("G()(al)".to_string()),
12+
"Goal".to_string()
13+
);
14+
assert_eq!(
15+
Solution::max_operations("G()()()()(al)".to_string()),
16+
"Gooooal".to_string()
17+
);
18+
assert_eq!(
19+
Solution::max_operations("(al)G(al)()()G".to_string()),
20+
"alGalooG".to_string()
21+
);
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use std::collections::HashMap;
2+
3+
struct Solution;
4+
impl Solution {
5+
pub fn max_operations(nums: Vec<i32>, k: i32) -> i32 {
6+
let mut occurs: HashMap<i32, i32> = HashMap::new();
7+
let mut result = 0;
8+
for v1 in nums {
9+
let v2 = k - v1;
10+
if let Some(occur) = occurs.get_mut(&v2) {
11+
if *occur > 0 {
12+
*occur -= 1;
13+
result += 1;
14+
continue;
15+
}
16+
}
17+
*occurs.entry(v1).or_default() += 1;
18+
}
19+
result
20+
}
21+
}
22+
23+
#[test]
24+
fn test() {
25+
assert_eq!(Solution::max_operations(vec![1, 2, 3, 4], 2), 5);
26+
assert_eq!(Solution::max_operations(vec![3, 1, 3, 4, 3], 6), 1);
27+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
struct Solution;
2+
3+
impl Solution {
4+
pub fn concatenated_binary(n: i32) -> i32 {
5+
let mut result: usize = 0;
6+
for i in 1..=n as usize {
7+
result <<= Self::binary_digits(i);
8+
result += i;
9+
result %= 1_000_000_007;
10+
}
11+
result as i32
12+
}
13+
14+
fn binary_digits(mut decimal: usize) -> usize {
15+
let mut bits = 0;
16+
while decimal > 0 {
17+
bits += 1;
18+
decimal >> 1;
19+
}
20+
bits
21+
}
22+
}
23+
24+
#[test]
25+
fn test() {
26+
assert_eq!(Solution::concatenated_binary(1), 1);
27+
assert_eq!(Solution::concatenated_binary(3), 3);
28+
assert_eq!(Solution::concatenated_binary(12), 505379714);
29+
}

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ mod _0412_fizz_buzz;
176176
//
177177
mod _0415_add_strings;
178178
//
179+
mod _0437_path_sum_iii;
180+
//
179181
mod _0443_string_compression;
180182
//
181183
mod _0448_find_all_numbers_disappeared_in_an_array;
@@ -311,3 +313,6 @@ mod _1608_special_array_with_x_elements_greater_than_or_equal_x;
311313
mod _1609_even_odd_tree;
312314
//
313315
mod test;
316+
317+
//
318+
mod temp1;

src/test.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)