Skip to content

Commit

Permalink
array-product
Browse files Browse the repository at this point in the history
  • Loading branch information
nt-sivan committed May 22, 2024
1 parent e6d80ef commit fbab769
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@
- [2024-05-20 把0移到末尾](./move-zeros)
- [2024-05-21 满足target最小子数组长度](./min-sub-array-len)
- [2024-05-22 找到最大可及的数字](./find-the-maximum-achievable-number)
- [2024-05-23 数组乘积的符号](./array-sign)

7 changes: 7 additions & 0 deletions array-sign/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions array-sign/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "array-sign"
version = "0.1.0"
edition = "2021"

[dependencies]
8 changes: 8 additions & 0 deletions array-sign/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod solution;

use crate::solution::Solution;
fn main() {
println!("Hello, world!{}", Solution::array_sign(vec![-1, -2, -3, -4, 3, 2, 1]));

println!("Hello, world!{}", Solution::array_sign(vec![1, 3, 0, 5, 6]));
}
16 changes: 16 additions & 0 deletions array-sign/src/solution.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pub struct Solution;

impl Solution {
pub fn array_sign(nums: Vec<i32>) -> i32 {
let mut result = 1;
for num in nums {
if num == 0 {
return 0;
} else if num < 0 {
result = -result;
}

}
result
}
}
1 change: 1 addition & 0 deletions array-sign/title.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-05-23 数组乘积的符号

0 comments on commit fbab769

Please sign in to comment.