Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Leetcode 2661. First Completely Painted Row or Column
- // https://leetcode.com/problems/first-completely-painted-row-or-column/description/?envType=daily-question&envId=2025-01-20
- impl Solution {
- pub fn first_complete_index(arr: Vec<i32>, mat: Vec<Vec<i32>>) -> i32 {
- let mut uncolored_cells_by_rows: Vec<i32> = vec![mat[0].len() as i32; mat.len()];
- let mut uncolored_cells_by_cols: Vec<i32> = vec![mat.len() as i32; mat[0].len()];
- // let mut table = [(0, 0); 100_001];
- let mut table = vec![(0, 0); arr.len() + 1];
- for (r, cols) in mat.iter().enumerate() {
- for (c, mat_num) in cols.iter().enumerate() {
- *unsafe { table.get_unchecked_mut(*mat_num as usize) } = (r, c);
- }
- }
- for (index, arr_num) in arr.into_iter().enumerate() {
- let (r, c) = *unsafe { table.get_unchecked(arr_num as usize) };
- match unsafe { uncolored_cells_by_rows.get_unchecked_mut(r) } {
- 1 => return index as i32,
- count => *count -= 1,
- }
- match unsafe { uncolored_cells_by_cols.get_unchecked_mut(c) } {
- 1 => return index as i32,
- count => *count -= 1,
- }
- }
- panic!()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement