diff options
author | Jack Sangdahl <[email protected]> | 2025-03-10 00:36:13 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-03-10 00:36:13 -0600 |
commit | 7c60dee83b436e8e8a667bf9f191beced8de4fc3 (patch) | |
tree | eb7a24ee2067f92245c57bb118e85a1baf15df50 /possible_bipartition.rs | |
parent | 5d7cdc215e4ba1ec4cbb24c084cccb5e5e641468 (diff) | |
download | leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.tar.gz leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.zip |
chore: move cpp and rust code to directory
Diffstat (limited to 'possible_bipartition.rs')
-rw-r--r-- | possible_bipartition.rs | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/possible_bipartition.rs b/possible_bipartition.rs deleted file mode 100644 index 13b8cf5..0000000 --- a/possible_bipartition.rs +++ /dev/null @@ -1,40 +0,0 @@ -use std::collections::VecDeque; -struct Solution; - -impl Solution { - pub fn possible_bipartition(n: i32, dislikes: Vec<Vec<i32>>) -> bool { - let mut dmap: Vec<Vec<usize>> = vec![vec![]; n as usize]; - for d in dislikes.iter() { - dmap[d[0] as usize - 1].push(d[1] as usize - 1); - dmap[d[1] as usize - 1].push(d[0] as usize - 1); - } - let mut v: Vec<Option<bool>> = vec![None; n as usize]; - for i in 0..n as usize { - if v[i].is_some() { - continue; - } - let mut vd: VecDeque<(usize, bool)> = VecDeque::new(); - vd.push_back((i, true)); - while let Some(last) = vd.pop_front() { - if let Some(b) = v[last.0] { - if b != last.1 { - return false; - } - continue; - } - v[last.0] = Some(last.1); - for j in dmap[last.0].iter() { - if v[*j].is_none() { - vd.push_back((*j, !last.1)); - } - } - } - } - true - } -} - -fn main() { - let dislikes = vec![vec![1,2], vec![1,3], vec![2,4]]; - print!("{}", Solution::possible_bipartition(4, dislikes)); -} |