Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9372e4d

Browse files
committed
src/bin/maximum-product-of-word-lengths.rs
1 parent 86b6982 commit 9372e4d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
fn main() {}
2+
3+
struct Solution;
4+
5+
impl Solution {
6+
pub fn max_product(words: Vec<String>) -> i32 {
7+
let mut v = vec![0i32; words.len()];
8+
9+
for i in 0..words.len() {
10+
for &j in words[i].as_bytes() {
11+
v[i] |= (1 << (j - b'a'));
12+
}
13+
}
14+
15+
let mut r = 0;
16+
17+
for i in 0..words.len() {
18+
for j in i + 1..words.len() {
19+
if (v[i] & v[j]) == 0 {
20+
r = r.max(words[i].len() * words[j].len())
21+
}
22+
}
23+
}
24+
25+
r as i32
26+
}
27+
}

0 commit comments

Comments
 (0)