1582. 二进制矩阵中的特殊位置
This commit is contained in:
parent
563c0b3589
commit
f8fd02dcb8
81
src/main.rs
81
src/main.rs
|
|
@ -1,48 +1,57 @@
|
||||||
use std::cell::RefCell;
|
|
||||||
|
|
||||||
struct Solution;
|
struct Solution;
|
||||||
mod arr;
|
mod arr;
|
||||||
impl Solution {
|
impl Solution {
|
||||||
pub fn find_kth_bit(n: i32,mut k: i32) -> char {
|
pub fn num_special(mat: Vec<Vec<i32>>) -> i32 {
|
||||||
let len = Self::get_length_arr()(n);
|
let mut disable = vec![false; mat[0].len()];
|
||||||
if n == 1 || k == 0 {
|
let mut arr = vec![0; mat[0].len()];
|
||||||
return '0';
|
for i in 0..mat.len() {
|
||||||
}
|
let mut disable_i = false;
|
||||||
if k == len / 2 + 1 {
|
let mut next_do_disable = false;
|
||||||
return '1';
|
let mut last_index = 1000_usize;
|
||||||
}
|
for j in 0..mat[0].len() {
|
||||||
if k > len / 2 + 1 {
|
if mat[i][j] == 1 {
|
||||||
if Self::find_kth_bit(n - 1, (len / 2+1) - (k - (len / 2 + 1))) == '1' {
|
if next_do_disable {
|
||||||
'0'
|
disable_i = true;
|
||||||
} else {
|
arr[last_index] = 0;
|
||||||
'1'
|
disable[last_index] = true;
|
||||||
}
|
disable[j] = true;
|
||||||
} else {
|
arr[j] = 0;
|
||||||
Self::find_kth_bit(n - 1, k)
|
}
|
||||||
}
|
if disable[j] {
|
||||||
}
|
disable_i = true;
|
||||||
fn get_length_arr() -> impl Fn(i32) -> i32 {
|
continue;
|
||||||
let cell = RefCell::new(None);
|
}
|
||||||
move |n| {
|
if disable_i {
|
||||||
let mut value = cell.borrow_mut();
|
disable[j] = true;
|
||||||
if value.is_none() {
|
if arr[j] != 0 {
|
||||||
let mut arr = Vec::with_capacity(20);
|
arr[j] = 0;
|
||||||
arr.push(1);
|
}
|
||||||
for _ in 1..20 {
|
continue;
|
||||||
arr.push(arr[arr.len() - 1] * 2 + 1);
|
}
|
||||||
|
if arr[j] != 0 {
|
||||||
|
disable[j] = true;
|
||||||
|
arr[j] = 0;
|
||||||
|
disable_i = true;
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
arr[j] += 1;
|
||||||
|
next_do_disable = true;
|
||||||
|
last_index = j;
|
||||||
}
|
}
|
||||||
*value = Some(arr);
|
|
||||||
}
|
|
||||||
if let Some(x) = value.as_ref() {
|
|
||||||
x[n as usize - 1]
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
arr.iter().sum()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let result = Solution::find_kth_bit(4, 14);
|
let result = Solution::num_special(arr::make_matrix("[[0,0,0,0,0,0],[0,0,1,0,0,0],[0,0,0,0,1,0],[0,0,0,0,0,0],[0,0,1,0,0,1],[0,0,0,0,0,0],[0,0,0,0,0,0]]"));
|
||||||
println!("{:?}", result);
|
println!("{:?}", result);
|
||||||
}
|
}
|
||||||
|
// [[0,0,0,0,0,0],
|
||||||
|
// [0,0,1,0,0,0],
|
||||||
|
// [0,0,0,0,1,0],
|
||||||
|
// [0,0,0,0,0,0],
|
||||||
|
// [0,0,1,0,0,1],
|
||||||
|
// [0,0,0,0,0,0],
|
||||||
|
// [0,0,0,0,0,0]]
|
||||||
Loading…
Reference in New Issue