Compare commits
30 Commits
5428c96ba7
...
20730d34b7
Author | SHA1 | Date | |
---|---|---|---|
20730d34b7 | |||
1aa56ff3c9 | |||
1e2a86cf52 | |||
ef53a58935 | |||
d5635e7618 | |||
f06e82f965 | |||
66d8753334 | |||
846eaa9521 | |||
d6c8702c7a | |||
eb4903c54f | |||
d4b56a88fd | |||
7848468524 | |||
610d05ddb2 | |||
21fffd8882 | |||
50d62c34be | |||
75a12ace37 | |||
ae4d5b5527 | |||
a442d1cd09 | |||
2a5ebdad4c | |||
c41b628fab | |||
2026979f5e | |||
c6a939c5e0 | |||
0aa11d31a2 | |||
1d7f72e3e5 | |||
b76354feb3 | |||
3030d16bad | |||
51bfae35cd | |||
11d6a65155 | |||
0eb65c4ed3 | |||
f98094172e |
7
1108_defanging_an_ip_address/Cargo.lock
generated
Normal file
7
1108_defanging_an_ip_address/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "defanging_an_ip_address"
|
||||||
|
version = "0.1.0"
|
6
1108_defanging_an_ip_address/Cargo.toml
Normal file
6
1108_defanging_an_ip_address/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "defanging_an_ip_address"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
7
1108_defanging_an_ip_address/src/lib.rs
Normal file
7
1108_defanging_an_ip_address/src/lib.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn defang_i_paddr(address: String) -> String {
|
||||||
|
address.replace(".", "[.]")
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,4 @@
|
|||||||
fn main() {}
|
pub struct Solution;
|
||||||
|
|
||||||
struct Solution;
|
|
||||||
|
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn maximum69_number(num: i32) -> i32 {
|
pub fn maximum69_number(num: i32) -> i32 {
|
7
1512_number_of_good_pairs/Cargo.lock
generated
Normal file
7
1512_number_of_good_pairs/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "number_of_good_pairs"
|
||||||
|
version = "0.1.0"
|
6
1512_number_of_good_pairs/Cargo.toml
Normal file
6
1512_number_of_good_pairs/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "number_of_good_pairs"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
17
1512_number_of_good_pairs/src/lib.rs
Normal file
17
1512_number_of_good_pairs/src/lib.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn num_identical_pairs(nums: Vec<i32>) -> i32 {
|
||||||
|
let mut result = 0;
|
||||||
|
|
||||||
|
for i in 0..nums.len() {
|
||||||
|
for j in (i + 1)..nums.len() {
|
||||||
|
if nums[i] == nums[j] {
|
||||||
|
result += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
7
1769_minimum_number_of_operations_to_move_all_balls_to_each_box/Cargo.lock
generated
Normal file
7
1769_minimum_number_of_operations_to_move_all_balls_to_each_box/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "minimum_number_of_operations_to_move_all_balls_to_each_box"
|
||||||
|
version = "0.1.0"
|
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "minimum_number_of_operations_to_move_all_balls_to_each_box"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
@ -0,0 +1,33 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn min_operations(boxes: String) -> Vec<i32> {
|
||||||
|
let boxes: Vec<i32> = boxes.chars().map(|c| c as i32 - 48).collect();
|
||||||
|
|
||||||
|
let mut balls_counted_from_left = vec![0; boxes.len()];
|
||||||
|
for i in 1..boxes.len() {
|
||||||
|
balls_counted_from_left[i] = balls_counted_from_left[i - 1] + boxes[i - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut balls_counted_from_right = vec![0; boxes.len()];
|
||||||
|
for i in (0..(boxes.len() - 1)).rev() {
|
||||||
|
balls_counted_from_right[i] = balls_counted_from_right[i + 1] + boxes[i + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut steps_moving_to_right = vec![0; boxes.len()];
|
||||||
|
for i in 1..boxes.len() {
|
||||||
|
steps_moving_to_right[i] = steps_moving_to_right[i - 1] + balls_counted_from_left[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut steps_moving_to_left = vec![0; boxes.len()];
|
||||||
|
for i in (0..(boxes.len() - 1)).rev() {
|
||||||
|
steps_moving_to_left[i] = steps_moving_to_left[i + 1] + balls_counted_from_right[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
steps_moving_to_left
|
||||||
|
.iter()
|
||||||
|
.zip(steps_moving_to_right.iter())
|
||||||
|
.map(|(&l, &r)| l + r)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
7
1863_sum_of_all_subset_xor_totals/Cargo.lock
generated
Normal file
7
1863_sum_of_all_subset_xor_totals/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sum_of_all_subset_xor_totals"
|
||||||
|
version = "0.1.0"
|
6
1863_sum_of_all_subset_xor_totals/Cargo.toml
Normal file
6
1863_sum_of_all_subset_xor_totals/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "sum_of_all_subset_xor_totals"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
8
1863_sum_of_all_subset_xor_totals/src/lib.rs
Normal file
8
1863_sum_of_all_subset_xor_totals/src/lib.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn subset_xor_sum(nums: Vec<i32>) -> i32 {
|
||||||
|
let or_sum = nums.iter().fold(0, |acc, &num| acc | num);
|
||||||
|
or_sum << (nums.len() - 1)
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,4 @@
|
|||||||
fn main() {
|
pub struct Solution;
|
||||||
println!("Hello, world!");
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Solution;
|
|
||||||
|
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn hamming_weight(mut n: i32) -> i32 {
|
pub fn hamming_weight(mut n: i32) -> i32 {
|
7
1920_build_array_from_permutation/Cargo.lock
generated
Normal file
7
1920_build_array_from_permutation/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "build_array_from_permutation"
|
||||||
|
version = "0.1.0"
|
6
1920_build_array_from_permutation/Cargo.toml
Normal file
6
1920_build_array_from_permutation/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "build_array_from_permutation"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
7
1920_build_array_from_permutation/src/lib.rs
Normal file
7
1920_build_array_from_permutation/src/lib.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn build_array(nums: Vec<i32>) -> Vec<i32> {
|
||||||
|
nums.iter().map(|&val| nums[val as usize]).collect()
|
||||||
|
}
|
||||||
|
}
|
7
1929_concatenation_of_array/Cargo.lock
generated
Normal file
7
1929_concatenation_of_array/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "concatenation_of_array"
|
||||||
|
version = "0.1.0"
|
6
1929_concatenation_of_array/Cargo.toml
Normal file
6
1929_concatenation_of_array/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "concatenation_of_array"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
7
1929_concatenation_of_array/src/lib.rs
Normal file
7
1929_concatenation_of_array/src/lib.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn get_concatenation(nums: Vec<i32>) -> Vec<i32> {
|
||||||
|
vec![nums.clone(), nums].concat()
|
||||||
|
}
|
||||||
|
}
|
1
192_word_frequency/script.sh
Normal file
1
192_word_frequency/script.sh
Normal file
@ -0,0 +1 @@
|
|||||||
|
cat words.txt | tr -s '[:space:]' '\n' | sort | uniq -c | sort -nr | awk '{print $2, $1}'
|
23
194_transpose_file/script.sh
Executable file
23
194_transpose_file/script.sh
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
cat file.txt | awk '
|
||||||
|
{
|
||||||
|
max_cols = 0
|
||||||
|
for (i = 1; i <= NF; i++) {
|
||||||
|
data[i, NR] = $i
|
||||||
|
}
|
||||||
|
if (NF > max_cols) {
|
||||||
|
max_cols = NF
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
END {
|
||||||
|
for (i = 1; i <= max_cols; i++) {
|
||||||
|
for (j = 1; j <= NR; j++) {
|
||||||
|
printf "%s", data[i, j]
|
||||||
|
if (j < NR) {
|
||||||
|
printf " "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'
|
1
195_thenth_line/script.sh
Normal file
1
195_thenth_line/script.sh
Normal file
@ -0,0 +1 @@
|
|||||||
|
sed -n '10p' file.txt
|
7
2011_final_value_of_variable_after_performing_operations/Cargo.lock
generated
Normal file
7
2011_final_value_of_variable_after_performing_operations/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "final_value_of_variable_after_performing_operations"
|
||||||
|
version = "0.1.0"
|
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "final_value_of_variable_after_performing_operations"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
@ -0,0 +1,17 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn final_value_after_operations(operations: Vec<String>) -> i32 {
|
||||||
|
let mut result = 0;
|
||||||
|
|
||||||
|
for op in operations {
|
||||||
|
if op.contains('+') {
|
||||||
|
result += 1;
|
||||||
|
} else {
|
||||||
|
result -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
7
202_happy_number/Cargo.lock
generated
Normal file
7
202_happy_number/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "happy_number"
|
||||||
|
version = "0.1.0"
|
6
202_happy_number/Cargo.toml
Normal file
6
202_happy_number/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "happy_number"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
25
202_happy_number/src/lib.rs
Normal file
25
202_happy_number/src/lib.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn is_happy(mut n: i32) -> bool {
|
||||||
|
let mut numbers_shown = HashSet::<i32>::new();
|
||||||
|
numbers_shown.insert(n);
|
||||||
|
|
||||||
|
while n != 1 {
|
||||||
|
let mut new_n = 0;
|
||||||
|
for c in n.to_string().chars() {
|
||||||
|
new_n += (c as i32 - 48).pow(2);
|
||||||
|
}
|
||||||
|
n = new_n;
|
||||||
|
|
||||||
|
if numbers_shown.contains(&n) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
numbers_shown.insert(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
7
2044_count_number_of_maximum_bitwise_or_subsets/Cargo.lock
generated
Normal file
7
2044_count_number_of_maximum_bitwise_or_subsets/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "count_number_of_maximum_bitwise_or_subsets"
|
||||||
|
version = "0.1.0"
|
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "count_number_of_maximum_bitwise_or_subsets"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
37
2044_count_number_of_maximum_bitwise_or_subsets/src/lib.rs
Normal file
37
2044_count_number_of_maximum_bitwise_or_subsets/src/lib.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn count_max_or_subsets(nums: Vec<i32>) -> i32 {
|
||||||
|
let max_or_sum = nums.iter().fold(0, |acc, &num| acc | num);
|
||||||
|
|
||||||
|
let mut result = 0;
|
||||||
|
let mut stack: Vec<DFSParams> = nums
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(index, &num)| DFSParams { index, or_sum: num })
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
while !stack.is_empty() {
|
||||||
|
let current = stack.pop().unwrap();
|
||||||
|
|
||||||
|
if current.or_sum == max_or_sum {
|
||||||
|
result += 1 << (nums.len() - current.index - 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in (current.index + 1)..nums.len() {
|
||||||
|
stack.push(DFSParams {
|
||||||
|
index: i,
|
||||||
|
or_sum: current.or_sum | nums[i],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DFSParams {
|
||||||
|
index: usize,
|
||||||
|
or_sum: i32,
|
||||||
|
}
|
7
206_reverse_linked_list/Cargo.lock
generated
Normal file
7
206_reverse_linked_list/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "reverse_linked_list"
|
||||||
|
version = "0.1.0"
|
6
206_reverse_linked_list/Cargo.toml
Normal file
6
206_reverse_linked_list/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "reverse_linked_list"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
56
206_reverse_linked_list/src/lib.rs
Normal file
56
206_reverse_linked_list/src/lib.rs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
|
pub struct ListNode {
|
||||||
|
pub val: i32,
|
||||||
|
pub next: Option<Box<ListNode>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ListNode {
|
||||||
|
#[inline]
|
||||||
|
fn new(val: i32) -> Self {
|
||||||
|
ListNode { next: None, val }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn reverse_list(head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
|
||||||
|
let mut arr: Vec<i32> = vec![];
|
||||||
|
let mut current_node = head;
|
||||||
|
|
||||||
|
while let Some(node) = current_node.take() {
|
||||||
|
arr.push(node.val);
|
||||||
|
current_node = node.next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if arr.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut head = Some(Box::new(ListNode::new(*arr.last().unwrap())));
|
||||||
|
let mut current_node = &mut head;
|
||||||
|
|
||||||
|
for &num in arr[..arr.len() - 1].iter().rev() {
|
||||||
|
current_node.as_mut().unwrap().next = Some(Box::new(ListNode::new(num)));
|
||||||
|
current_node = &mut current_node.as_mut().unwrap().next;
|
||||||
|
}
|
||||||
|
|
||||||
|
head
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reverse_list_2(mut head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
|
||||||
|
if head.is_none() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let mut p: Option<Box<ListNode>> = None;
|
||||||
|
|
||||||
|
while let Some(mut node) = head.take() {
|
||||||
|
let next = node.next;
|
||||||
|
node.next = p;
|
||||||
|
p = Some(node);
|
||||||
|
head = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
p
|
||||||
|
}
|
||||||
|
}
|
7
2181_merge_nodes_in_between_zeros/Cargo.lock
generated
Normal file
7
2181_merge_nodes_in_between_zeros/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "merge_nodes_in_between_zeros"
|
||||||
|
version = "0.1.0"
|
6
2181_merge_nodes_in_between_zeros/Cargo.toml
Normal file
6
2181_merge_nodes_in_between_zeros/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "merge_nodes_in_between_zeros"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
39
2181_merge_nodes_in_between_zeros/src/lib.rs
Normal file
39
2181_merge_nodes_in_between_zeros/src/lib.rs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
|
pub struct ListNode {
|
||||||
|
pub val: i32,
|
||||||
|
pub next: Option<Box<ListNode>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ListNode {
|
||||||
|
#[inline]
|
||||||
|
fn new(val: i32) -> Self {
|
||||||
|
ListNode { next: None, val }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn merge_nodes(head: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
|
||||||
|
let mut result_head = Some(Box::new(ListNode::new(0)));
|
||||||
|
let mut result_current_node = &mut result_head;
|
||||||
|
|
||||||
|
let mut current_node = head.unwrap().next;
|
||||||
|
while let Some(node) = current_node.take() {
|
||||||
|
if node.val != 0 {
|
||||||
|
result_current_node.as_mut().unwrap().val += node.val;
|
||||||
|
} else {
|
||||||
|
if node.next.as_ref().is_none() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
result_current_node.as_mut().unwrap().next = Some(Box::new(ListNode::new(0)));
|
||||||
|
result_current_node = &mut result_current_node.as_mut().unwrap().next;
|
||||||
|
}
|
||||||
|
|
||||||
|
current_node = node.next;
|
||||||
|
}
|
||||||
|
|
||||||
|
result_head
|
||||||
|
}
|
||||||
|
}
|
7
2348_number_of_zero_filled_subarrays/Cargo.lock
generated
Normal file
7
2348_number_of_zero_filled_subarrays/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "number_of_zero_filled_subarrays"
|
||||||
|
version = "0.1.0"
|
6
2348_number_of_zero_filled_subarrays/Cargo.toml
Normal file
6
2348_number_of_zero_filled_subarrays/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "number_of_zero_filled_subarrays"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
20
2348_number_of_zero_filled_subarrays/src/lib.rs
Normal file
20
2348_number_of_zero_filled_subarrays/src/lib.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn zero_filled_subarray(mut nums: Vec<i32>) -> i64 {
|
||||||
|
let mut result = 0i64;
|
||||||
|
|
||||||
|
let mut continuous_count = 0i64;
|
||||||
|
nums.push(1);
|
||||||
|
for num in nums {
|
||||||
|
if num == 0 {
|
||||||
|
continuous_count += 1;
|
||||||
|
} else {
|
||||||
|
result += (1 + continuous_count) * continuous_count / 2;
|
||||||
|
continuous_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
7
2469_convert_the_temperature/Cargo.lock
generated
Normal file
7
2469_convert_the_temperature/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "convert_the_temperature"
|
||||||
|
version = "0.1.0"
|
6
2469_convert_the_temperature/Cargo.toml
Normal file
6
2469_convert_the_temperature/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "convert_the_temperature"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
7
2469_convert_the_temperature/src/lib.rs
Normal file
7
2469_convert_the_temperature/src/lib.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn convert_temperature(celsius: f64) -> Vec<f64> {
|
||||||
|
vec![celsius + 273.15, celsius * 1.8 + 32.0]
|
||||||
|
}
|
||||||
|
}
|
7
2769_find_the_maximum_achievable_number/Cargo.lock
generated
Normal file
7
2769_find_the_maximum_achievable_number/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "find_the_maximum_achievable_number"
|
||||||
|
version = "0.1.0"
|
6
2769_find_the_maximum_achievable_number/Cargo.toml
Normal file
6
2769_find_the_maximum_achievable_number/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "find_the_maximum_achievable_number"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
7
2769_find_the_maximum_achievable_number/src/lib.rs
Normal file
7
2769_find_the_maximum_achievable_number/src/lib.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn the_maximum_achievable_x(num: i32, t: i32) -> i32 {
|
||||||
|
num + 2 * t
|
||||||
|
}
|
||||||
|
}
|
7
2807_insert_greatest_common_divisors_in_linked_list/Cargo.lock
generated
Normal file
7
2807_insert_greatest_common_divisors_in_linked_list/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "insert_greatest_common_divisors_in_linked_list"
|
||||||
|
version = "0.1.0"
|
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "insert_greatest_common_divisors_in_linked_list"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
@ -0,0 +1,52 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
|
pub struct ListNode {
|
||||||
|
pub val: i32,
|
||||||
|
pub next: Option<Box<ListNode>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn insert_greatest_common_divisors(
|
||||||
|
mut head: Option<Box<ListNode>>,
|
||||||
|
) -> Option<Box<ListNode>> {
|
||||||
|
let mut current = &mut head;
|
||||||
|
|
||||||
|
while let Some(node) = current {
|
||||||
|
if let Some(next_node) = &node.next {
|
||||||
|
let a = node.val;
|
||||||
|
let b = next_node.val;
|
||||||
|
let gcd = Solution::gcd(a, b);
|
||||||
|
|
||||||
|
let next = node.next.take();
|
||||||
|
node.next = Some(Box::new(ListNode { val: gcd, next }));
|
||||||
|
|
||||||
|
current = &mut node.next.as_mut().unwrap().next;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
head
|
||||||
|
}
|
||||||
|
|
||||||
|
fn gcd(mut a: i32, mut b: i32) -> i32 {
|
||||||
|
if a > b {
|
||||||
|
let tmp = a;
|
||||||
|
a = b;
|
||||||
|
b = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let rem = b % a;
|
||||||
|
b = a;
|
||||||
|
a = rem;
|
||||||
|
|
||||||
|
if rem == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b
|
||||||
|
}
|
||||||
|
}
|
7
2894_divisible_and_non_divisible_sums_difference/Cargo.lock
generated
Normal file
7
2894_divisible_and_non_divisible_sums_difference/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "divisible_and_non_divisible_sums_difference"
|
||||||
|
version = "0.1.0"
|
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "divisible_and_non_divisible_sums_difference"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
10
2894_divisible_and_non_divisible_sums_difference/src/lib.rs
Normal file
10
2894_divisible_and_non_divisible_sums_difference/src/lib.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn difference_of_sums(n: i32, m: i32) -> i32 {
|
||||||
|
let (dividable, undividable): (Vec<i32>, Vec<i32>) =
|
||||||
|
(1..(n + 1)).partition(|&val| val % m == 0);
|
||||||
|
|
||||||
|
undividable.iter().sum::<i32>() - dividable.iter().sum::<i32>()
|
||||||
|
}
|
||||||
|
}
|
7
2942_find_words_containing_character/Cargo.lock
generated
Normal file
7
2942_find_words_containing_character/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "find_words_containing_character"
|
||||||
|
version = "0.1.0"
|
6
2942_find_words_containing_character/Cargo.toml
Normal file
6
2942_find_words_containing_character/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "find_words_containing_character"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
12
2942_find_words_containing_character/src/lib.rs
Normal file
12
2942_find_words_containing_character/src/lib.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn find_words_containing(words: Vec<String>, x: char) -> Vec<i32> {
|
||||||
|
words
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter(|(_, word)| word.contains(x))
|
||||||
|
.map(|(index, _)| index as i32)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
7
29_divide_two_integer/Cargo.lock
generated
Normal file
7
29_divide_two_integer/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "divide_two_integer"
|
||||||
|
version = "0.1.0"
|
6
29_divide_two_integer/Cargo.toml
Normal file
6
29_divide_two_integer/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "divide_two_integer"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
58
29_divide_two_integer/src/lib.rs
Normal file
58
29_divide_two_integer/src/lib.rs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
/// - Dividend = Quotient * Divisor + Rem
|
||||||
|
/// - Rem < Divisor
|
||||||
|
pub fn divide(mut dividend: i32, mut divisor: i32) -> i32 {
|
||||||
|
if divisor == i32::MIN {
|
||||||
|
return if dividend == i32::MIN { 1 } else { 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
let is_positive = dividend.is_positive() == divisor.is_positive();
|
||||||
|
|
||||||
|
let mut is_overflow = false;
|
||||||
|
if dividend == i32::MIN {
|
||||||
|
is_overflow = true;
|
||||||
|
dividend += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dividend = dividend.abs();
|
||||||
|
divisor = divisor.abs();
|
||||||
|
|
||||||
|
if dividend < divisor {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut quotient = 0;
|
||||||
|
let mut rem;
|
||||||
|
loop {
|
||||||
|
let mut exp = 1;
|
||||||
|
while divisor << exp <= dividend && divisor << exp > 0 {
|
||||||
|
exp += 1;
|
||||||
|
}
|
||||||
|
exp -= 1;
|
||||||
|
|
||||||
|
quotient += 1 << exp;
|
||||||
|
rem = dividend - (divisor << exp);
|
||||||
|
if rem < divisor {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
dividend = rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_overflow && rem + 1 >= divisor {
|
||||||
|
if is_positive {
|
||||||
|
if quotient == i32::MAX {
|
||||||
|
quotient
|
||||||
|
} else {
|
||||||
|
quotient + 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
-quotient - 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if is_positive { quotient } else { -quotient }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
3110_score_of_a_string/Cargo.lock
generated
Normal file
7
3110_score_of_a_string/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "score_of_a_string"
|
||||||
|
version = "0.1.0"
|
6
3110_score_of_a_string/Cargo.toml
Normal file
6
3110_score_of_a_string/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "score_of_a_string"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
10
3110_score_of_a_string/src/lib.rs
Normal file
10
3110_score_of_a_string/src/lib.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn score_of_string(s: String) -> i32 {
|
||||||
|
s.chars()
|
||||||
|
.zip(s.chars().skip(1))
|
||||||
|
.map(|(a, b)| (a as i32 - b as i32).abs())
|
||||||
|
.sum()
|
||||||
|
}
|
||||||
|
}
|
7
342_power_of_four/Cargo.lock
generated
Normal file
7
342_power_of_four/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "power_of_four"
|
||||||
|
version = "0.1.0"
|
6
342_power_of_four/Cargo.toml
Normal file
6
342_power_of_four/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "power_of_four"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
21
342_power_of_four/src/lib.rs
Normal file
21
342_power_of_four/src/lib.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn is_power_of_four(mut n: i32) -> bool {
|
||||||
|
if n <= 0 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while n > 0 {
|
||||||
|
if n == 1 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if n % 4 != 0 {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
n /= 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
7
3467_transform_array_by_parity/Cargo.lock
generated
Normal file
7
3467_transform_array_by_parity/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "transform_array_by_parity"
|
||||||
|
version = "0.1.0"
|
6
3467_transform_array_by_parity/Cargo.toml
Normal file
6
3467_transform_array_by_parity/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "transform_array_by_parity"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
10
3467_transform_array_by_parity/src/lib.rs
Normal file
10
3467_transform_array_by_parity/src/lib.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn transform_array(nums: Vec<i32>) -> Vec<i32> {
|
||||||
|
let even_count = nums.iter().filter(|&num| num % 2 == 0).count();
|
||||||
|
let mut result = vec![0; even_count];
|
||||||
|
result.extend(vec![1; nums.len() - even_count].iter());
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,6 @@
|
|||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
|
||||||
fn main() {
|
pub struct Solution;
|
||||||
let x = "000".to_string();
|
|
||||||
let y = "0".to_string();
|
|
||||||
println!("{}", Solution::plus(x, y));
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Solution;
|
|
||||||
|
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn multiply(x: String, y: String) -> String {
|
pub fn multiply(x: String, y: String) -> String {
|
@ -1,8 +1,4 @@
|
|||||||
fn main() {
|
pub struct Solution;
|
||||||
println!("Hello, world!");
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Solution;
|
|
||||||
|
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn unique_paths(m: i32, n: i32) -> i32 {
|
pub fn unique_paths(m: i32, n: i32) -> i32 {
|
@ -1,11 +1,4 @@
|
|||||||
fn main() {
|
pub struct Solution;
|
||||||
println!(
|
|
||||||
"{}",
|
|
||||||
Solution::unique_paths_with_obstacles(vec![vec![0], vec![1]])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Solution;
|
|
||||||
|
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn unique_paths_with_obstacles(obstacle_grid: Vec<Vec<i32>>) -> i32 {
|
pub fn unique_paths_with_obstacles(obstacle_grid: Vec<Vec<i32>>) -> i32 {
|
7
64_minimum_path_sum/Cargo.lock
generated
Normal file
7
64_minimum_path_sum/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "minimum_path_sum"
|
||||||
|
version = "0.1.0"
|
6
64_minimum_path_sum/Cargo.toml
Normal file
6
64_minimum_path_sum/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "minimum_path_sum"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
24
64_minimum_path_sum/src/lib.rs
Normal file
24
64_minimum_path_sum/src/lib.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn min_path_sum(mut grid: Vec<Vec<i32>>) -> i32 {
|
||||||
|
let rows = grid.len();
|
||||||
|
let cols = grid[0].len();
|
||||||
|
|
||||||
|
for i in 1..rows {
|
||||||
|
grid[i][0] += grid[i - 1][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
for j in 1..cols {
|
||||||
|
grid[0][j] += grid[0][j - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 1..rows {
|
||||||
|
for j in 1..cols {
|
||||||
|
grid[i][j] = std::cmp::min(grid[i][j] + grid[i - 1][j], grid[i][j] + grid[i][j - 1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
grid[rows - 1][cols - 1]
|
||||||
|
}
|
||||||
|
}
|
7
679_24_game/Cargo.lock
generated
Normal file
7
679_24_game/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "twenty_four_game"
|
||||||
|
version = "0.1.0"
|
6
679_24_game/Cargo.toml
Normal file
6
679_24_game/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "twenty_four_game"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
58
679_24_game/src/lib.rs
Normal file
58
679_24_game/src/lib.rs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn judge_point24(cards: Vec<i32>) -> bool {
|
||||||
|
let mut stack: Vec<Vec<f64>> = vec![cards.iter().map(|&v| v as f64).collect()];
|
||||||
|
|
||||||
|
while let Some(cards) = stack.pop() {
|
||||||
|
if cards.len() == 1 {
|
||||||
|
if (cards.first().unwrap() - 24f64).abs() < 1e-6 {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for i in 0..(cards.len() - 1) {
|
||||||
|
for j in (i + 1)..cards.len() {
|
||||||
|
let a = cards[i];
|
||||||
|
let b = cards[j];
|
||||||
|
|
||||||
|
let mut left_cards = cards.clone();
|
||||||
|
left_cards.remove(j);
|
||||||
|
left_cards.remove(i);
|
||||||
|
|
||||||
|
let mut new_cards = left_cards.clone();
|
||||||
|
new_cards.push(a + b);
|
||||||
|
stack.push(new_cards);
|
||||||
|
|
||||||
|
let mut new_cards = left_cards.clone();
|
||||||
|
new_cards.push(a * b);
|
||||||
|
stack.push(new_cards);
|
||||||
|
|
||||||
|
let mut new_cards = left_cards.clone();
|
||||||
|
new_cards.push(a - b);
|
||||||
|
stack.push(new_cards);
|
||||||
|
|
||||||
|
let mut new_cards = left_cards.clone();
|
||||||
|
new_cards.push(b - a);
|
||||||
|
stack.push(new_cards);
|
||||||
|
|
||||||
|
if b.abs() > 1e-6 {
|
||||||
|
let mut new_cards = left_cards.clone();
|
||||||
|
new_cards.push(a / b);
|
||||||
|
stack.push(new_cards);
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.abs() > 1e-6 {
|
||||||
|
let mut new_cards = left_cards.clone();
|
||||||
|
new_cards.push(b / a);
|
||||||
|
stack.push(new_cards);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
7
771_jewels_and_stones/Cargo.lock
generated
Normal file
7
771_jewels_and_stones/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "jewels_and_stones"
|
||||||
|
version = "0.1.0"
|
6
771_jewels_and_stones/Cargo.toml
Normal file
6
771_jewels_and_stones/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "jewels_and_stones"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
18
771_jewels_and_stones/src/lib.rs
Normal file
18
771_jewels_and_stones/src/lib.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
pub struct Solution;
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn num_jewels_in_stones(jewels: String, stones: String) -> i32 {
|
||||||
|
let jewels: HashSet<char> = HashSet::from_iter(jewels.chars());
|
||||||
|
let mut result = 0;
|
||||||
|
|
||||||
|
for stone in stones.chars() {
|
||||||
|
if jewels.contains(&stone) {
|
||||||
|
result += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,4 @@
|
|||||||
fn main() {
|
pub struct Solution;
|
||||||
println!("Hello, world!");
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Solution;
|
|
||||||
|
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn new21_game(n: i32, k: i32, max_pts: i32) -> f64 {
|
pub fn new21_game(n: i32, k: i32, max_pts: i32) -> f64 {
|
@ -1,11 +1,4 @@
|
|||||||
fn main() {
|
pub struct Solution;
|
||||||
println!(
|
|
||||||
"{}",
|
|
||||||
Solution::unique_paths_iii(vec![vec![1, 0, 0, 0], vec![0, 0, 0, 0], vec![0, 0, 2, -1]])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Solution;
|
|
||||||
|
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn unique_paths_iii(grid: Vec<Vec<i32>>) -> i32 {
|
pub fn unique_paths_iii(grid: Vec<Vec<i32>>) -> i32 {
|
Loading…
x
Reference in New Issue
Block a user