Skip to content

Commit 4f11e20

Browse files
committed
2/16/2021
1 parent 573e773 commit 4f11e20

File tree

4 files changed

+89
-26
lines changed

4 files changed

+89
-26
lines changed

README.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
|2|[Add Two Numbers](src/_0002_add_two_numbers.rs)|
1212
|3|[Longest Substring Without Repeating Characters](src/_0003_longest_substring_without_repeating_characters.rs)|
1313
|5|[Longest Palindromic Substring](src/_0005_longest_palindromic_substring.rs)|
14-
|7|[Reverse Integer ](src/_0007_reverse_integer.rs)|
15-
|9|[Palindrome Number ](src/_0009_palindrome_number.rs)|
14+
|7|[Reverse Integer](src/_0007_reverse_integer.rs)|
15+
|9|[Palindrome Number](src/_0009_palindrome_number.rs)|
1616
|11|[Container With Most Water](src/_0011_container_with_most_water.rs)|
1717
|14|[Longest Common Prefix](src/_0014_longest_common_prefix.rs)|
1818
|15|[3Sum](src/_0015_3sum.rs)|
1919
|17|[Letter Combinations of a Phone Number](src/_0017_letter_combinations_of_a_phone_number.rs)|
2020
|20|[Valid Parentheses](src/_0020_valid_parentheses.rs)|
21-
|21|[Merge Two Sorted Lists ](src/_0021_merge_two_sorted_lists.rs)|
22-
|22|[Generate Parentheses ](src/_0022_generate_parentheses.rs)|
21+
|21|[Merge Two Sorted Lists](src/_0021_merge_two_sorted_lists.rs)|
22+
|22|[Generate Parentheses](src/_0022_generate_parentheses.rs)|
2323
|34|[Find First and Last Position of Element in Sorted Array](src/_0034_find_first_and_last_position_of_element_in_sorted_array.rs)|
24-
|36|[Valid Sudoku ](src/_0036_valid_sudoku.rs)|
24+
|36|[Valid Sudoku](src/_0036_valid_sudoku.rs)|
2525
|38|[Count and Say](src/_0038_count_and_say.rs)|
2626
|42|[Trapping Rain Water](src/_0042_trapping_rain_water.rs)|
2727
|46|[Permutations](src/_0046_permutations.rs)|
@@ -85,13 +85,13 @@
8585
|344|[Reverse String](src/_0344_reverse_string.rs)|
8686
|347|[Top K Frequent Elements](src/_0347_top_k_frequent_elements.rs)|
8787
|349|[Intersection of Two Arrays](src/_0349_intersection_of_two_arrays.rs)|
88-
|350|[Intersection of Two Arrays II ](src/_0350_intersection_of_two_arrays_ii.rs)|
88+
|350|[Intersection of Two Arrays II](src/_0350_intersection_of_two_arrays_ii.rs)|
8989
|359|[Logger Rate Limiter](src/_0359_logger_rate_limiter.rs)|
9090
|371|[Sum of Two Integers ](src/_0371_sum_of_two_integers.rs)|
9191
|383|[Ransom Note](src/_0383_ransom_note.rs)|
9292
|386|[Lexicographical Numbers](src/_0386_lexicographical_numbers.rs)|
9393
|387|[First Unique Character in a String ](src/_0387_first_unique_character_in_a_string.rs)|
94-
|394|[Decode String ](src/_0394_decode_string.rs)|
94+
|394|[Decode String](src/_0394_decode_string.rs)|
9595
|404|[Sum of Left Leaves](src/_0404_sum_of_left_leaves.rs)|
9696
|412|[Fizz Buzz ](src/_0412_fizz_buzz.rs)|
9797
|415|[Add Strings ](src/_0415_add_strings.rs)|
@@ -108,22 +108,23 @@
108108
|520|[Detect Capital](src/_0520_detect_capital.rs)|
109109
|532|[K-diff Pairs in an Array](src/_0532_kdiff_pairs_in_an_array.rs)|
110110
|543|[Diameter of Binary Tree](src/_0543_diameter_of_binary_tree.rs)|
111-
|556|[Next Greater Element III ](src/_0556_next_greater_element_iii.rs)|
112-
|557|[Reverse Words in a String III ](src/_0557_reverse_words_in_a_string_iii.rs)|
111+
|556|[Next Greater Element III](src/_0556_next_greater_element_iii.rs)|
112+
|557|[Reverse Words in a String III](src/_0557_reverse_words_in_a_string_iii.rs)|
113113
|559|[Maximum deph of N-ary tree](src/_0559_maximum_depth_of_nary_tree.rs)|
114-
|560|[Subarray Sum Equals K ](src/_0560_subarray_sum_equals_k.rs)|
115-
|561|[Array Partition I ](src/_0561_array_partition_i.rs)|
114+
|560|[Subarray Sum Equals K](src/_0560_subarray_sum_equals_k.rs)|
115+
|561|[Array Partition I](src/_0561_array_partition_i.rs)|
116+
|582|[Kill Process](src/_0582_kill_process.rs)|
116117
|605|[Can Place Flowers](src/_0605_can_place_flowers.rs)|
117-
|617|[Merge Two Binary Trees ](src/_0617_merge_two_binary_trees.rs)|
118-
|678|[Valid Parenthesis String ](src/_0678_valid_parenthesis_string.rs)|
118+
|617|[Merge Two Binary Trees](src/_0617_merge_two_binary_trees.rs)|
119+
|678|[Valid Parenthesis String](src/_0678_valid_parenthesis_string.rs)|
119120
|680|[Valid Palindrome II ](src/_0680_valid_palindrome_ii.rs)|
120-
|692|[Top K Frequent Words ](src/_0692_top_k_frequent_words.rs)|
121+
|692|[Top K Frequent Words](src/_0692_top_k_frequent_words.rs)|
121122
|724|[Find Pivot Index](src/_0724_find_pivot_index.rs)|
122123
|735|[Asteroid Collision ](src/_0735_asteroid_collision.rs)|
123124
|763|[Partition Labels](src/_0763_partition_labels.rs)|
124-
|771|[Jewels and Stones ](src/_0771_jewels_and_stones.rs)|
125-
|796|[Rotate String ](src/_0796_rotate_string.rs)|
126-
|819|[Most Common Word ](src/_0819_most_common_word.rs)|
125+
|771|[Jewels and Stones](src/_0771_jewels_and_stones.rs)|
126+
|796|[Rotate String](src/_0796_rotate_string.rs)|
127+
|819|[Most Common Word](src/_0819_most_common_word.rs)|
127128
|844|[Backspace String Compare](src/_0844_backspace_string_compare.rs)|
128129
|859|[Buddy Strings](src/_0859_buddy_strings.rs)|
129130
|875|[Koko Eating Bananas](src/_0875_koko_eating_bananas.rs)|
@@ -133,36 +134,36 @@
133134
|938|[Range Sum of BST](src/_0938_range_sum_of_bst.rs)|
134135
|953|[Verifying an Alien Dictionary](src/_0953_verifying_an_alien_dictionary.rs)|
135136
|973|[K Closest Points to Origin](src/_0973_k_closest_points_to_origin.rs)|
136-
|977|[Squares of a Sorted Array ](src/_0977_squares_of_a_sorted_array.rs)|
137+
|977|[Squares of a Sorted Array](src/_0977_squares_of_a_sorted_array.rs)|
137138
|994|[Rotting Oranges](src/_0994_rotting_oranges.rs)|
138139
|1013|[Partition Array Into Three Parts With Equal Sum](src/_1013_partition_array_into_three_parts_with_equal_sum.rs)|
139140
|1021|[Remove Outermost Parentheses](src/_1021_remove_outermost_parentheses_1029_two_city_scheduling.rs)|
140141
|1029|[Two City Scheduling](src/_1029_two_city_scheduling.rs)|
141142
|1136|[Parallel Courses](src/_1136_parallel_courses.rs)|
142-
|1239|[Maximum Length of a Concatenated String with Unique Characters ](src/_1239_maximum_length_of_a_concatenated_string_with_unique_characters.rs)|
143+
|1239|[Maximum Length of a Concatenated String with Unique Characters](src/_1239_maximum_length_of_a_concatenated_string_with_unique_characters.rs)|
143144
|1249|[Minimum Remove to Make Valid Parentheses](src/_1249_minimum_remove_to_make_valid_parentheses.rs)|
144145
|1281|[Subtract the Product and Sum of Digits of an Integer](src/_1281_subtract_the_product_and_sum_of_digits_of_an_integer.rs)|
145146
|1287|[Element Appearing More Than 25% In Sorted Array](src/_1287_element_appearing_more_than_25_in_sorted_array.rs)|
146147
|1290|[Convert Binary Number in a Linked List to Integer](src/_1290_convert_binary_number_in_a_linked_list_to_integer.rs)|
147148
|1299|[Replace Elements with Greatest Element on Right Side](src/_1299_replace_elements_with_greatest_element_on_right_side.rs)|
148-
|1304|[Find N Unique Integers Sum up to Zero ](src/_1304_find_n_unique_integers_sum_up_to_zero.rs)|
149+
|1304|[Find N Unique Integers Sum up to Zero](src/_1304_find_n_unique_integers_sum_up_to_zero.rs)|
149150
|1480|[Running Sum of 1d Array](src/_1480_running_sum_of_1d_array.rs)|
150-
|1486|[XOR Operation in an Array ](src/_1486_xor_operation_in_an_array.rs)|
151-
|1496|[Path Crossing ](src/_1496_path_crossing.rs)|
151+
|1486|[XOR Operation in an Array](src/_1486_xor_operation_in_an_array.rs)|
152+
|1496|[Path Crossing](src/_1496_path_crossing.rs)|
152153
|1528|[Shuffle String](src/_1528_shuffle_string.rs)|
153154
|1534|[Count Good Triplets](src/_1534_count_good_triplets.rs)|
154155
|1535|[Find the Winner of an Array Game](src/_1535_find_the_winner_of_an_array_game.rs)|
155-
|1537|[Get the Maximum Score ](src/_1537_get_the_maximum_score.rs)|
156+
|1537|[Get the Maximum Score](src/_1537_get_the_maximum_score.rs)|
156157
|1539|[Kth Missing Positive Number](src/_1539_kth_missing_positive_number.rs)|
157158
|1540|[Can Convert String in K Moves](src/_1540_can_convert_string_in_k_moves.rs)|
158159
|1152|[Analyze User Website Visit Pattern](src/_1572_matrix_diagonal_sum.rs)|
159-
|1572|[Matrix Diagonal Sum ](src/_1572_matrix_diagonal_sum.rs)|
160+
|1572|[Matrix Diagonal Sum](src/_1572_matrix_diagonal_sum.rs)|
160161
|1576|[Replace All ?'s to Avoid Consecutive Repeating Characters](src/_1576_replace_all_question_mark_to_avoid_consecutive_repeating_characters.rs)|
161162
|1577|[Number of Ways Where Square of Number Is Equal to Product of Two Numbers](src/_1577_number_of_ways_where_square_of_number_is_equal_to_product_of_two_numbers.rs)|
162163
|1578|[Minimum Deletion Cost to Avoid Repeating Letters](src/_1578_minimum_deletion_cost_to_avoid_repeating_letters.rs)|
163164
|1582|[Special Positions in a Binary Matrix](src/_1582_special_positions_in_a_binary_matrix.rs)|
164165
|1583|[Count Unhappy Friends](src/_1583_count_unhappy_friends.rs)|
165-
|1588|[Sum of All Odd Length Subarrays ](src/_1588_sum_of_all_odd_length_subarrays.rs)|
166+
|1588|[Sum of All Odd Length Subarrays](src/_1588_sum_of_all_odd_length_subarrays.rs)|
166167
|1593|[Split a String Into the Max Number of Unique Substrings](src/_1593_split_a_string_into_the_max_number_of_unique_substrings.rs)|
167168
|1598|[Crawler Log Folder](src/_1598_rawler_log_folder.rs)|
168169
|1608|[Special Array With X Elements Greater Than or Equal X](src/_1608_special_array_with_x_elements_greater_than_or_equal_x.rs)|
@@ -177,7 +178,7 @@
177178
|1694|[Reformat Phone Number](src/_1694_reformat_phone_number.rs)|
178179
|1695|[Maximum Erasure Value](src/_1695_maximum_erasure_value.rs)|
179180
|1704|[Determine if String Halves Are Alike](src/_1704_determine_if_string_halves_are_alike.rs)|
180-
|1705|[Maximum Number of Eaten Apples ](src/_1705_maximum_number_of_eaten_apples.rs)|
181+
|1705|[Maximum Number of Eaten Apples](src/_1705_maximum_number_of_eaten_apples.rs)|
181182
|1706|[Where Will the Ball Fall](src/_1706_where_will_the_ball_fall.rs)|
182183
|1725|[Number Of Rectangles That Can Form The Largest Square](src/_1725_number_of_rectangles_that_can_form_the_largest_square.rs)|
183184
|1726|[Tuple with Same Product](src/_1726_tuple_with_same_product.rs)|

src/_0582_kill_process.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
struct Solution;
2+
use std::collections::HashMap;
3+
4+
impl Solution {
5+
pub fn kill_process(pid: Vec<i32>, ppid: Vec<i32>, kill: i32) -> Vec<i32> {
6+
let mut map: HashMap<i32, Vec<i32>> = HashMap::new();
7+
let n = pid.len();
8+
for i in 0..n {
9+
map.entry(ppid[i]).or_default().push(pid[i]);
10+
}
11+
12+
let mut result = vec![kill];
13+
let mut queue: Vec<i32> = vec![kill];
14+
while !queue.is_empty() {
15+
let mut temp: Vec<i32> = vec![];
16+
for v in queue {
17+
if let Some(children) = map.get(&v) {
18+
for child in children {
19+
result.push(child.clone());
20+
temp.push(child.clone());
21+
}
22+
}
23+
}
24+
queue = temp;
25+
}
26+
27+
return result;
28+
}
29+
}
30+
31+
#[test]
32+
fn test() {
33+
assert_eq!(
34+
Solution::kill_process(vec![1, 3, 10, 5, 11], vec![3, 0, 5, 3, 5], 5),
35+
vec![5, 10, 11]
36+
);
37+
}

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ mod _0560_subarray_sum_equals_k;
224224
//
225225
mod _0561_array_partition_i;
226226
//
227+
mod _0582_kill_process;
228+
//
227229
mod _0605_can_place_flowers;
228230
//
229231
mod _0617_merge_two_binary_trees;
@@ -364,5 +366,9 @@ mod _1725_number_of_rectangles_that_can_form_the_largest_square;
364366
//
365367
mod _1726_tuple_with_same_product;
366368
//
369+
mod _1736_latest_time_by_replacing_hidden_digits;
370+
//
371+
mod _1737_change_minimum_characters_to_satisfy_one_of_three_conditions;
372+
//
367373
mod test;
368374
//

src/test.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
11
struct Solution;
2+
3+
impl Solution {
4+
pub fn count_balls(low_limit: i32, high_limit: i32) -> i32 {
5+
let mut count = vec![0i32; 36];
6+
7+
for v in low_limit..=high_limit {
8+
let mut num = v.clone();
9+
let mut sum = 0;
10+
while num > 0 {
11+
sum += num % 10;
12+
num /= 10;
13+
}
14+
count[sum as usize] += 1;
15+
}
16+
17+
return *count.iter().max().unwrap();
18+
}
19+
}
20+

0 commit comments

Comments
 (0)