Skip to content

Commit 875147a

Browse files
committed
add 982
1 parent 4a18555 commit 875147a

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

S0982-triples-with-bitwise-and-equal-to-zero/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "S0982-triples-with-bitwise-and-equal-to-zero"
3+
version = "0.1.0"
4+
authors = ["xargin <cao1988228@163.com>"]
5+
edition = "2018"
6+
7+
[dependencies]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}
4+
5+
struct Solution;
6+
impl Solution {
7+
pub fn count_triplets(a: Vec<i32>) -> i32 {
8+
let mut res = 0;
9+
(0..a.len()).for_each(|i| {
10+
(i..a.len()).for_each(|j| {
11+
let tmp = a[i] & a[j];
12+
(j..a.len()).for_each(|k| {
13+
if tmp & a[k] == 0 {
14+
if i == j && j == k {
15+
res += 1;
16+
} else if i == j || j == k || i == k {
17+
res += 3;
18+
} else {
19+
res += 6;
20+
}
21+
}
22+
})
23+
})
24+
});
25+
res
26+
}
27+
}

0 commit comments

Comments
 (0)