id 1428832801 Time: 902 ms MemUsage: 3.9 MB
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
impl Solution {
|
||||
pub fn maximize_square_area(m: i32, n: i32, h_fences: Vec<i32>, v_fences: Vec<i32>) -> i32 {
|
||||
let mut heights = BTreeSet::new();
|
||||
|
||||
heights.insert(m - 1);
|
||||
for i in 0..h_fences.len(){
|
||||
let pos = h_fences[i];
|
||||
heights.insert(pos - 1);
|
||||
heights.insert(m - pos);
|
||||
|
||||
for j in 0..i{
|
||||
heights.insert(pos.abs_diff(h_fences[j]) as i32);
|
||||
}
|
||||
}
|
||||
|
||||
let mut max_width = 0;
|
||||
if heights.contains(&(n - 1)) && n - 1 > max_width {
|
||||
max_width = n - 1;
|
||||
} else {
|
||||
for i in 0..v_fences.len(){
|
||||
let pos = v_fences[i];
|
||||
if heights.contains(&(pos - 1)) && pos - 1 > max_width {
|
||||
max_width = pos - 1;
|
||||
}
|
||||
|
||||
if heights.contains(&(n - pos)) && n - pos > max_width {
|
||||
max_width = n - pos;
|
||||
}
|
||||
|
||||
for j in 0..i {
|
||||
let width = pos.abs_diff(v_fences[j]) as i32;
|
||||
if heights.contains(&(width)) && width > max_width {
|
||||
max_width = width;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if max_width == 0 {
|
||||
-1
|
||||
} else {
|
||||
let max_width = max_width as i64;
|
||||
((max_width * max_width) % 1_000_000_007) as i32
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user