[INFO] fetching crate leetcode_for_rust 0.1.37... [INFO] linting leetcode_for_rust-0.1.37 against nightly for clippy-nonminimal_bool-denied [INFO] extracting crate leetcode_for_rust 0.1.37 into /workspace/builds/worker-5-tc1/source [INFO] started tweaking crates.io crate leetcode_for_rust 0.1.37 [INFO] finished tweaking crates.io crate leetcode_for_rust 0.1.37 [INFO] tweaked toml for crates.io crate leetcode_for_rust 0.1.37 written to /workspace/builds/worker-5-tc1/source/Cargo.toml [INFO] validating manifest of crates.io crate leetcode_for_rust 0.1.37 on toolchain nightly [INFO] running `Command { std: CARGO_HOME="/workspace/cargo-home" RUSTUP_HOME="/workspace/rustup-home" "/workspace/cargo-home/bin/cargo" "+nightly" "metadata" "--manifest-path" "Cargo.toml" "--no-deps", kill_on_drop: false }` [INFO] running `Command { std: CARGO_HOME="/workspace/cargo-home" RUSTUP_HOME="/workspace/rustup-home" "/workspace/cargo-home/bin/cargo" "+nightly" "generate-lockfile" "--manifest-path" "Cargo.toml", kill_on_drop: false }` [INFO] running `Command { std: CARGO_HOME="/workspace/cargo-home" RUSTUP_HOME="/workspace/rustup-home" "/workspace/cargo-home/bin/cargo" "+nightly" "fetch" "--manifest-path" "Cargo.toml", kill_on_drop: false }` [INFO] running `Command { std: "docker" "create" "-v" "/var/lib/crater-agent-workspace/builds/worker-5-tc1/target:/opt/rustwide/target:rw,Z" "-v" "/var/lib/crater-agent-workspace/builds/worker-5-tc1/source:/opt/rustwide/workdir:ro,Z" "-v" "/var/lib/crater-agent-workspace/cargo-home:/opt/rustwide/cargo-home:ro,Z" "-v" "/var/lib/crater-agent-workspace/rustup-home:/opt/rustwide/rustup-home:ro,Z" "-e" "SOURCE_DIR=/opt/rustwide/workdir" "-e" "CARGO_TARGET_DIR=/opt/rustwide/target" "-e" "CARGO_HOME=/opt/rustwide/cargo-home" "-e" "RUSTUP_HOME=/opt/rustwide/rustup-home" "-w" "/opt/rustwide/workdir" "-m" "1610612736" "--user" "0:0" "--network" "none" "ghcr.io/rust-lang/crates-build-env/linux@sha256:d429b63d4308055ea97f60fb1d3dfca48854a00942f1bd2ad806beaf015945ec" "/opt/rustwide/cargo-home/bin/cargo" "+nightly" "metadata" "--no-deps" "--format-version=1", kill_on_drop: false }` [INFO] [stdout] a30dbf8b8dd1ac02d16dbb2e371289b4d061f6dc1b914f17cdf4f4187fc9a1e9 [INFO] running `Command { std: "docker" "start" "-a" "a30dbf8b8dd1ac02d16dbb2e371289b4d061f6dc1b914f17cdf4f4187fc9a1e9", kill_on_drop: false }` [INFO] running `Command { std: "docker" "inspect" "a30dbf8b8dd1ac02d16dbb2e371289b4d061f6dc1b914f17cdf4f4187fc9a1e9", kill_on_drop: false }` [INFO] running `Command { std: "docker" "rm" "-f" "a30dbf8b8dd1ac02d16dbb2e371289b4d061f6dc1b914f17cdf4f4187fc9a1e9", kill_on_drop: false }` [INFO] [stdout] a30dbf8b8dd1ac02d16dbb2e371289b4d061f6dc1b914f17cdf4f4187fc9a1e9 [INFO] running `Command { std: "docker" "create" "-v" "/var/lib/crater-agent-workspace/builds/worker-5-tc1/target:/opt/rustwide/target:rw,Z" "-v" "/var/lib/crater-agent-workspace/builds/worker-5-tc1/source:/opt/rustwide/workdir:ro,Z" "-v" "/var/lib/crater-agent-workspace/cargo-home:/opt/rustwide/cargo-home:ro,Z" "-v" "/var/lib/crater-agent-workspace/rustup-home:/opt/rustwide/rustup-home:ro,Z" "-e" "SOURCE_DIR=/opt/rustwide/workdir" "-e" "CARGO_TARGET_DIR=/opt/rustwide/target" "-e" "CARGO_INCREMENTAL=0" "-e" "RUST_BACKTRACE=full" "-e" "RUSTFLAGS=--cap-lints=forbid" "-e" "RUSTDOCFLAGS=--cap-lints=forbid" "-e" "CARGO_HOME=/opt/rustwide/cargo-home" "-e" "RUSTUP_HOME=/opt/rustwide/rustup-home" "-w" "/opt/rustwide/workdir" "-m" "1610612736" "--user" "0:0" "--network" "none" "ghcr.io/rust-lang/crates-build-env/linux@sha256:d429b63d4308055ea97f60fb1d3dfca48854a00942f1bd2ad806beaf015945ec" "/opt/rustwide/cargo-home/bin/cargo" "+nightly" "clippy" "--frozen" "--all" "--all-targets" "--message-format=json", kill_on_drop: false }` [INFO] [stdout] 9e78ffba6e47a9c558413cde3abe0ab19910451730ac119325cb59f75d25168b [INFO] running `Command { std: "docker" "start" "-a" "9e78ffba6e47a9c558413cde3abe0ab19910451730ac119325cb59f75d25168b", kill_on_drop: false }` [INFO] [stderr] Checking leetcode_for_rust v0.1.37 (/opt/rustwide/workdir) [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0036_valid_sudoku/mod.rs:177:1 [INFO] [stdout] | [INFO] [stdout] 177 | / /// [INFO] [stdout] 178 | | [INFO] [stdout] | |_^ [INFO] [stdout] 179 | pub fn is_valid_sudoku(board: Vec>) -> bool { [INFO] [stdout] | ---------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = note: `#[warn(clippy::empty_line_after_doc_comments)]` on by default [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 59 ~ //! # Solutions [INFO] [stdout] 60 ~ //! [INFO] [stdout] 61 ~ //! # Approach 1: DFS [INFO] [stdout] 62 ~ //! [INFO] [stdout] 63 ~ //! * Time complexity: [INFO] [stdout] 64 ~ //! [INFO] [stdout] 65 ~ //! * Space complexity: [INFO] [stdout] 66 ~ //! [INFO] [stdout] 67 ~ //! * Runtime: 4 ms [INFO] [stdout] 68 ~ //! * Memory: 2.5 MB [INFO] [stdout] 69 ~ //! [INFO] [stdout] 70 ~ //! ```rust [INFO] [stdout] 71 ~ //! impl Solution { [INFO] [stdout] 72 ~ //! pub fn is_valid_sudoku(board: Vec>) -> bool { [INFO] [stdout] 73 ~ //! // 快速检索第i, j列, 第k宫的数字是否被占用 [INFO] [stdout] 74 ~ //! let mut line = [[false; 9]; 9]; // j [INFO] [stdout] 75 ~ //! let mut column = [[false; 9]; 9]; // i [INFO] [stdout] 76 ~ //! let mut ceil = [[false; 9]; 9]; // k [INFO] [stdout] 77 ~ //! let mut origin = [[false; 9]; 9]; // 原始数字位置 [INFO] [stdout] 78 ~ //! // 初始化 [INFO] [stdout] 79 ~ //! for row in 0..9 { [INFO] [stdout] 80 ~ //! for col in 0..9 { [INFO] [stdout] 81 ~ //! let num = match board[row][col].to_digit(10) { [INFO] [stdout] 82 ~ //! Some(n) => (n - 1) as usize, [INFO] [stdout] 83 ~ //! None => continue [INFO] [stdout] 84 ~ //! }; [INFO] [stdout] 85 ~ //! [INFO] [stdout] 86 ~ //! if line[row][num] || column[col][num] ||ceil[Self::ceil_k((row, col))][num] { return false; } [INFO] [stdout] 87 ~ //! line[row][num] = true; [INFO] [stdout] 88 ~ //! column[col][num] = true; [INFO] [stdout] 89 ~ //! origin[row][col] = true; [INFO] [stdout] 90 ~ //! ceil[Self::ceil_k((row, col))][num] = true; [INFO] [stdout] 91 ~ //! } [INFO] [stdout] 92 ~ //! } [INFO] [stdout] 93 ~ //! true [INFO] [stdout] 94 ~ //! } [INFO] [stdout] 95 ~ //! [INFO] [stdout] 96 ~ //! // 求出pos属于第几个ceil [INFO] [stdout] 97 ~ //! fn ceil_k(pos: (usize, usize)) -> usize { [INFO] [stdout] 98 ~ //! (pos.0 / 3) * 3 + pos.1 / 3 [INFO] [stdout] 99 ~ //! } [INFO] [stdout] 100 ~ //! } [INFO] [stdout] 101 ~ //! ``` [INFO] [stdout] 102 ~ //! [INFO] [stdout] 103 ~ //! # Approach 2: DFS [INFO] [stdout] 104 ~ //! [INFO] [stdout] 105 ~ //! * Time complexity: [INFO] [stdout] 106 ~ //! [INFO] [stdout] 107 ~ //! * Space complexity: [INFO] [stdout] 108 ~ //! [INFO] [stdout] 109 ~ //! * Runtime: 5 ms [INFO] [stdout] 110 ~ //! * Memory: 2.5 MB [INFO] [stdout] 111 ~ //! [INFO] [stdout] 112 ~ //! ```rust [INFO] [stdout] 113 ~ //! impl Solution { [INFO] [stdout] 114 ~ //! pub fn is_valid_sudoku(board: Vec>) -> bool { [INFO] [stdout] 115 ~ //! let mut table = vec![false; 9]; [INFO] [stdout] 116 ~ //! [INFO] [stdout] 117 ~ //! Solution::check_row(&board, &mut table) && [INFO] [stdout] 118 ~ //! Solution::check_col(&board, &mut table) && [INFO] [stdout] 119 ~ //! Solution::check_block(&board, &mut table) [INFO] [stdout] 120 ~ //! } [INFO] [stdout] 121 ~ //! [INFO] [stdout] 122 ~ //! pub fn check_row(board: &Vec>, table: &mut Vec) -> bool { [INFO] [stdout] 123 ~ //! // check row [INFO] [stdout] 124 ~ //! for row in board.iter() { [INFO] [stdout] 125 ~ //! for pos in 0..9 { table[pos] = false; } [INFO] [stdout] 126 ~ //! for col in row { [INFO] [stdout] 127 ~ //! match col.to_digit(10) { [INFO] [stdout] 128 ~ //! Some(n) => { [INFO] [stdout] 129 ~ //! if table[(n-1) as usize] { return false; } [INFO] [stdout] 130 ~ //! table[(n-1) as usize] = true; [INFO] [stdout] 131 ~ //! }, [INFO] [stdout] 132 ~ //! None => continue, [INFO] [stdout] 133 ~ //! } [INFO] [stdout] 134 ~ //! } [INFO] [stdout] 135 ~ //! } [INFO] [stdout] 136 ~ //! true [INFO] [stdout] 137 ~ //! } [INFO] [stdout] 138 ~ //! [INFO] [stdout] 139 ~ //! pub fn check_col(board: &Vec>, table: &mut Vec) -> bool { [INFO] [stdout] 140 ~ //! // check col [INFO] [stdout] 141 ~ //! for col in 0..9 { [INFO] [stdout] 142 ~ //! for pos in 0..9 { table[pos] = false; } [INFO] [stdout] 143 ~ //! for row in board.iter() { [INFO] [stdout] 144 ~ //! match row[col].to_digit(10) { [INFO] [stdout] 145 ~ //! Some(n) => { [INFO] [stdout] 146 ~ //! if table[(n-1) as usize] { return false; } [INFO] [stdout] 147 ~ //! table[(n-1) as usize] = true; [INFO] [stdout] 148 ~ //! }, [INFO] [stdout] 149 ~ //! None => continue, [INFO] [stdout] 150 ~ //! } [INFO] [stdout] 151 ~ //! } [INFO] [stdout] 152 ~ //! } [INFO] [stdout] 153 ~ //! true [INFO] [stdout] 154 ~ //! } [INFO] [stdout] 155 ~ //! [INFO] [stdout] 156 ~ //! pub fn check_block(board: &Vec>, table: &mut Vec) -> bool { [INFO] [stdout] 157 ~ //! // check 3 * 3 block [INFO] [stdout] 158 ~ //! for i in 0..3 { [INFO] [stdout] 159 ~ //! for j in 0..3 { [INFO] [stdout] 160 ~ //! for pos in 0..9 { table[pos] = false; } [INFO] [stdout] 161 ~ //! for row in 3 * i .. 3 * (i + 1) { [INFO] [stdout] 162 ~ //! for col in 3 * j .. 3 * (j + 1) { [INFO] [stdout] 163 ~ //! match board[row][col].to_digit(10) { [INFO] [stdout] 164 ~ //! Some(n) => { [INFO] [stdout] 165 ~ //! if table[(n-1) as usize] { return false; } [INFO] [stdout] 166 ~ //! table[(n-1) as usize] = true; [INFO] [stdout] 167 ~ //! }, [INFO] [stdout] 168 ~ //! None => continue, [INFO] [stdout] 169 ~ //! } [INFO] [stdout] 170 ~ //! } [INFO] [stdout] 171 ~ //! } [INFO] [stdout] 172 ~ //! } [INFO] [stdout] 173 ~ //! } [INFO] [stdout] 174 ~ //! true [INFO] [stdout] 175 ~ //! } [INFO] [stdout] 176 ~ //! } [INFO] [stdout] 177 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0037_sudoku_solver/mod.rs:159:1 [INFO] [stdout] | [INFO] [stdout] 159 | / /// [INFO] [stdout] 160 | | [INFO] [stdout] | |_^ [INFO] [stdout] 161 | pub fn solve_sudoku(board: &mut Vec>) { [INFO] [stdout] | ------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 29 ~ //! # Solutions [INFO] [stdout] 30 ~ //! [INFO] [stdout] 31 ~ //! # Approach 1: DFS [INFO] [stdout] 32 ~ //! [INFO] [stdout] 33 ~ //! * Time complexity: [INFO] [stdout] 34 ~ //! [INFO] [stdout] 35 ~ //! * Space complexity: [INFO] [stdout] 36 ~ //! [INFO] [stdout] 37 ~ //! * Runtime: 12 ms [INFO] [stdout] 38 ~ //! * Memory: 2.4 MB [INFO] [stdout] 39 ~ //! [INFO] [stdout] 40 ~ //! ```rust [INFO] [stdout] 41 ~ //! impl Solution { [INFO] [stdout] 42 ~ //! pub fn solve_sudoku(board: &mut Vec>) { [INFO] [stdout] 43 ~ //! if board.is_empty() { return; } [INFO] [stdout] 44 ~ //! Self::solve(board); [INFO] [stdout] 45 ~ //! } [INFO] [stdout] 46 ~ //! [INFO] [stdout] 47 ~ //! pub fn solve(board: &mut Vec>) -> bool { [INFO] [stdout] 48 ~ //! for row in 0..board.len() { [INFO] [stdout] 49 ~ //! for col in 0..board[row].len() { [INFO] [stdout] 50 ~ //! if board[row][col] != '.' { continue; } [INFO] [stdout] 51 ~ //! [INFO] [stdout] 52 ~ //! for c in "123456789".chars().collect::>() { [INFO] [stdout] 53 ~ //! if !Self::is_valid(&board, row, col, c) { continue; } [INFO] [stdout] 54 ~ //! [INFO] [stdout] 55 ~ //! board[row][col] = c; [INFO] [stdout] 56 ~ //! [INFO] [stdout] 57 ~ //! if Self::solve(board) { return true; } [INFO] [stdout] 58 ~ //! [INFO] [stdout] 59 ~ //! board[row][col] = '.'; [INFO] [stdout] 60 ~ //! } [INFO] [stdout] 61 ~ //! [INFO] [stdout] 62 ~ //! return false; [INFO] [stdout] 63 ~ //! } [INFO] [stdout] 64 ~ //! } [INFO] [stdout] 65 ~ //! return true; [INFO] [stdout] 66 ~ //! } [INFO] [stdout] 67 ~ //! [INFO] [stdout] 68 ~ //! pub fn is_valid(board: &Vec>, row: usize, col: usize, c: char) -> bool { [INFO] [stdout] 69 ~ //! for i in 0..9 { [INFO] [stdout] 70 ~ //! if board[row][i] != '.' && board[row][i] == c { return false; } // check row [INFO] [stdout] 71 ~ //! if board[i][col] != '.' && board[i][col] == c { return false; } // check col [INFO] [stdout] 72 ~ //! let block = board[(3 * (row as i32 / 3) + i as i32 / 3) as usize][(3 * (col as i32 / 3) + i as i32 % 3) as usize]; [INFO] [stdout] 73 ~ //! if block != '.' && block == c { return false; } // check 3 * 3 block; [INFO] [stdout] 74 ~ //! } [INFO] [stdout] 75 ~ //! true [INFO] [stdout] 76 ~ //! } [INFO] [stdout] 77 ~ //! } [INFO] [stdout] 78 ~ //! ``` [INFO] [stdout] 79 ~ //! [INFO] [stdout] 80 ~ //! # Approach 2: DFS [INFO] [stdout] 81 ~ //! [INFO] [stdout] 82 ~ //! * Time complexity: [INFO] [stdout] 83 ~ //! [INFO] [stdout] 84 ~ //! * Space complexity: [INFO] [stdout] 85 ~ //! [INFO] [stdout] 86 ~ //! * Runtime: 0 ms [INFO] [stdout] 87 ~ //! * Memory: 2.5 MB [INFO] [stdout] 88 ~ //! [INFO] [stdout] 89 ~ //! ```rust [INFO] [stdout] 90 ~ //! use std::char; [INFO] [stdout] 91 ~ //! [INFO] [stdout] 92 ~ //! impl Solution { [INFO] [stdout] 93 ~ //! pub fn solve_sudoku(board: &mut Vec>) { [INFO] [stdout] 94 ~ //! if board.is_empty() { return; } [INFO] [stdout] 95 ~ //! [INFO] [stdout] 96 ~ //! // 快速检索第i, j列, 第k宫的数字是否被占用 [INFO] [stdout] 97 ~ //! let mut lines = [[false; 9]; 9]; [INFO] [stdout] 98 ~ //! let mut columns = [[false; 9]; 9]; [INFO] [stdout] 99 ~ //! let mut ceils = [[false; 9]; 9]; [INFO] [stdout] 100 ~ //! let mut origins = [[false; 9]; 9]; [INFO] [stdout] 101 ~ //! [INFO] [stdout] 102 ~ //! // initialize lines columns ceils and origins [INFO] [stdout] 103 ~ //! for row in 0..9 { [INFO] [stdout] 104 ~ //! for col in 0..9 { [INFO] [stdout] 105 ~ //! let num = match board[row][col].to_digit(10) { [INFO] [stdout] 106 ~ //! Some(n) => (n - 1) as usize, [INFO] [stdout] 107 ~ //! None => continue, [INFO] [stdout] 108 ~ //! }; [INFO] [stdout] 109 ~ //! [INFO] [stdout] 110 ~ //! lines[row][num] = true; [INFO] [stdout] 111 ~ //! columns[col][num] = true; [INFO] [stdout] 112 ~ //! origins[row][col] = true; [INFO] [stdout] 113 ~ //! ceils[Self::ceil_pos((row, col))][num] = true; [INFO] [stdout] 114 ~ //! } [INFO] [stdout] 115 ~ //! } [INFO] [stdout] 116 ~ //! [INFO] [stdout] 117 ~ //! Self::solve(board, (0, 0), &mut lines, &mut columns, &mut ceils, &mut origins); [INFO] [stdout] 118 ~ //! } [INFO] [stdout] 119 ~ //! [INFO] [stdout] 120 ~ //! pub fn solve(board: &mut Vec>, [INFO] [stdout] 121 ~ //! (row, col): (usize, usize), [INFO] [stdout] 122 ~ //! lines: &mut[[bool; 9]; 9], [INFO] [stdout] 123 ~ //! columns: &mut[[bool; 9]; 9], [INFO] [stdout] 124 ~ //! ceils: &mut[[bool; 9]; 9], [INFO] [stdout] 125 ~ //! origins: &mut[[bool; 9]; 9]) -> bool { [INFO] [stdout] 126 ~ //! [INFO] [stdout] 127 ~ //! if row >= 9 { return true; } [INFO] [stdout] 128 ~ //! let next_pos = (row + (col + 1) / 9, (col + 1) % 9); [INFO] [stdout] 129 ~ //! if origins[row][col] { return Self::solve(board, next_pos, lines, columns, ceils, origins); } [INFO] [stdout] 130 ~ //! [INFO] [stdout] 131 ~ //! let mut flag = false; [INFO] [stdout] 132 ~ //! for num in 0..9 { [INFO] [stdout] 133 ~ //! let ceil = Self::ceil_pos((row, col)); [INFO] [stdout] 134 ~ //! if lines[row][num] || columns[col][num] || ceils[ceil][num] { continue; } [INFO] [stdout] 135 ~ //! [INFO] [stdout] 136 ~ //! // 数字num + 1没用过 [INFO] [stdout] 137 ~ //! lines[row][num] = true; [INFO] [stdout] 138 ~ //! columns[col][num] = true; [INFO] [stdout] 139 ~ //! ceils[ceil][num] = true; [INFO] [stdout] 140 ~ //! [INFO] [stdout] 141 ~ //! board[row][col] = char::from_digit(num as u32 + 1, 10).unwrap(); [INFO] [stdout] 142 ~ //! [INFO] [stdout] 143 ~ //! flag |= Self::solve(board, next_pos, lines, columns, ceils, origins); [INFO] [stdout] 144 ~ //! [INFO] [stdout] 145 ~ //! if flag { break; } // 已填数 OK [INFO] [stdout] 146 ~ //! lines[row][num] = false; [INFO] [stdout] 147 ~ //! columns[col][num] = false; [INFO] [stdout] 148 ~ //! ceils[ceil][num] = false; [INFO] [stdout] 149 ~ //! } [INFO] [stdout] 150 ~ //! [INFO] [stdout] 151 ~ //! flag [INFO] [stdout] 152 ~ //! } [INFO] [stdout] 153 ~ //! [INFO] [stdout] 154 ~ //! // 求出pos属于第几个ceil [INFO] [stdout] 155 ~ //! pub fn ceil_pos(pos: (usize, usize)) -> usize { [INFO] [stdout] 156 ~ //! (pos.0 / 3) * 3 + pos.1 / 3 [INFO] [stdout] 157 ~ //! } [INFO] [stdout] 158 ~ //! } [INFO] [stdout] 159 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0051_n_queens/mod.rs:205:1 [INFO] [stdout] | [INFO] [stdout] 205 | / /// [INFO] [stdout] 206 | | [INFO] [stdout] | |_^ [INFO] [stdout] 207 | pub fn solve_n_queens(n: i32) -> Vec> { [INFO] [stdout] | --------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 32 ~ //! # Solutions [INFO] [stdout] 33 ~ //! [INFO] [stdout] 34 ~ //! # Approach 1: DFS [INFO] [stdout] 35 ~ //! [INFO] [stdout] 36 ~ //! * Time complexity: [INFO] [stdout] 37 ~ //! [INFO] [stdout] 38 ~ //! * Space complexity: [INFO] [stdout] 39 ~ //! [INFO] [stdout] 40 ~ //! * Runtime: 4 ms [INFO] [stdout] 41 ~ //! * Memory: 2.8 MB [INFO] [stdout] 42 ~ //! [INFO] [stdout] 43 ~ //! ```rust [INFO] [stdout] 44 ~ //! impl Solution { [INFO] [stdout] 45 ~ //! pub fn solve_n_queens(n: i32) -> Vec> { [INFO] [stdout] 46 ~ //! if n < 1 { return vec![]; } [INFO] [stdout] 47 ~ //! [INFO] [stdout] 48 ~ //! let mut result = vec![]; [INFO] [stdout] 49 ~ //! let mut current_queens = vec![]; [INFO] [stdout] 50 ~ //! let mut cols = vec![]; [INFO] [stdout] 51 ~ //! let mut xy_sum = vec![]; [INFO] [stdout] 52 ~ //! let mut xy_sub = vec![]; [INFO] [stdout] 53 ~ //! let row = 0; [INFO] [stdout] 54 ~ //! [INFO] [stdout] 55 ~ //! Self::_dfs(n, &mut result, &mut current_queens, row, &mut cols, &mut xy_sum, &mut xy_sub); [INFO] [stdout] 56 ~ //! [INFO] [stdout] 57 ~ //! result [INFO] [stdout] 58 ~ //! } [INFO] [stdout] 59 ~ //! [INFO] [stdout] 60 ~ //! pub fn _dfs( [INFO] [stdout] 61 ~ //! n: i32, [INFO] [stdout] 62 ~ //! result: &mut Vec>, [INFO] [stdout] 63 ~ //! current_queens: &mut Vec, [INFO] [stdout] 64 ~ //! row: i32, [INFO] [stdout] 65 ~ //! cols: &mut Vec, [INFO] [stdout] 66 ~ //! xy_sum: &mut Vec, [INFO] [stdout] 67 ~ //! xy_sub: &mut Vec [INFO] [stdout] 68 ~ //! ) { [INFO] [stdout] 69 ~ //! if row >= n { [INFO] [stdout] 70 ~ //! result.push(Self::matrix(current_queens, n)); [INFO] [stdout] 71 ~ //! return; [INFO] [stdout] 72 ~ //! } [INFO] [stdout] 73 ~ //! [INFO] [stdout] 74 ~ //! for col in 0..n { [INFO] [stdout] 75 ~ //! if cols.contains(&col) || xy_sum.contains(&(row + col)) || xy_sub.contains(&(row - col)) { [INFO] [stdout] 76 ~ //! continue; [INFO] [stdout] 77 ~ //! } [INFO] [stdout] 78 ~ //! [INFO] [stdout] 79 ~ //! cols.push(col); [INFO] [stdout] 80 ~ //! xy_sum.push(row + col); [INFO] [stdout] 81 ~ //! xy_sub.push(row - col); [INFO] [stdout] 82 ~ //! Self::_dfs(n, result, &mut [current_queens.clone(), [col].to_vec()].concat(), row + 1, cols, xy_sum, xy_sub); [INFO] [stdout] 83 ~ //! [INFO] [stdout] 84 ~ //! cols.retain(|&x| x != col); [INFO] [stdout] 85 ~ //! xy_sum.retain(|&x| x != (row + col)); [INFO] [stdout] 86 ~ //! xy_sub.retain(|&x| x != (row - col)); [INFO] [stdout] 87 ~ //! } [INFO] [stdout] 88 ~ //! } [INFO] [stdout] 89 ~ //! [INFO] [stdout] 90 ~ //! pub fn matrix(queens: &mut Vec, n: i32) -> Vec { [INFO] [stdout] 91 ~ //! let mut arr = vec![]; [INFO] [stdout] 92 ~ //! let queens_len = queens.len(); [INFO] [stdout] 93 ~ //! for i in queens { [INFO] [stdout] 94 ~ //! let mut char_vector = vec!['.'; n as usize]; [INFO] [stdout] 95 ~ //! char_vector[*i as usize] = 'Q'; [INFO] [stdout] 96 ~ //! let str: String = char_vector.into_iter().collect(); [INFO] [stdout] 97 ~ //! arr.push(str); [INFO] [stdout] 98 ~ //! } [INFO] [stdout] 99 ~ //! [INFO] [stdout] 100 ~ //! arr [INFO] [stdout] 101 ~ //! } [INFO] [stdout] 102 ~ //! } [INFO] [stdout] 103 ~ //! ``` [INFO] [stdout] 104 ~ //! [INFO] [stdout] 105 ~ //! # Approach 2: DFS [INFO] [stdout] 106 ~ //! [INFO] [stdout] 107 ~ //! * Time complexity: [INFO] [stdout] 108 ~ //! [INFO] [stdout] 109 ~ //! * Space complexity: [INFO] [stdout] 110 ~ //! [INFO] [stdout] 111 ~ //! * Runtime: 0 ms [INFO] [stdout] 112 ~ //! * Memory: 2.8 MB [INFO] [stdout] 113 ~ //! [INFO] [stdout] 114 ~ //! ```rust [INFO] [stdout] 115 ~ //! impl Solution { [INFO] [stdout] 116 ~ //! pub fn solve_n_queens(n: i32) -> Vec> { [INFO] [stdout] 117 ~ //! let mut board = vec![vec!['.'; n as usize]; n as usize]; [INFO] [stdout] 118 ~ //! let mut solution = vec![]; [INFO] [stdout] 119 ~ //! Self::schedule_queens(&mut board, &mut solution, n as usize, 0); [INFO] [stdout] 120 ~ //! solution [INFO] [stdout] 121 ~ //! } [INFO] [stdout] 122 ~ //! [INFO] [stdout] 123 ~ //! fn schedule_queens(board: &mut Vec>, solution: &mut Vec>, len: usize, row: usize) { [INFO] [stdout] 124 ~ //! for col in 0..len { [INFO] [stdout] 125 ~ //! if !Self::collision(&board, len, row, col) { [INFO] [stdout] 126 ~ //! board[row][col] = 'Q'; [INFO] [stdout] 127 ~ //! if row == len - 1 { [INFO] [stdout] 128 ~ //! solution.push(board.iter().map(|vec| vec.iter().collect()).collect()); [INFO] [stdout] 129 ~ //! } else { [INFO] [stdout] 130 ~ //! Self::schedule_queens(board, solution, len, row+1); [INFO] [stdout] 131 ~ //! } [INFO] [stdout] 132 ~ //! board[row][col] = '.'; [INFO] [stdout] 133 ~ //! } [INFO] [stdout] 134 ~ //! } [INFO] [stdout] 135 ~ //! } [INFO] [stdout] 136 ~ //! [INFO] [stdout] 137 ~ //! #[inline(always)] [INFO] [stdout] 138 ~ //! fn collision(board: &Vec>, len: usize, row: usize, col: usize) -> bool { [INFO] [stdout] 139 ~ //! for i in 0..row { [INFO] [stdout] 140 ~ //! if board[i][col] == 'Q' { return true } [INFO] [stdout] 141 ~ //! } [INFO] [stdout] 142 ~ //! let (mut i, mut j) = (row as i32 - 1, col as i32 - 1); [INFO] [stdout] 143 ~ //! while i >= 0 && j >= 0 { [INFO] [stdout] 144 ~ //! if board[i as usize][j as usize] == 'Q' { return true } [INFO] [stdout] 145 ~ //! i -= 1; j -= 1; [INFO] [stdout] 146 ~ //! } [INFO] [stdout] 147 ~ //! let (mut i, mut j) = (row as i32 - 1, col as i32 + 1); [INFO] [stdout] 148 ~ //! while i >= 0 && j < len as i32 { [INFO] [stdout] 149 ~ //! if board[i as usize][j as usize] == 'Q' { return true} [INFO] [stdout] 150 ~ //! i -= 1; j += 1; [INFO] [stdout] 151 ~ //! } [INFO] [stdout] 152 ~ //! false [INFO] [stdout] 153 ~ //! } [INFO] [stdout] 154 ~ //! } [INFO] [stdout] 155 ~ //! ``` [INFO] [stdout] 156 ~ //! [INFO] [stdout] 157 ~ //! # Approach 3: BitWies [INFO] [stdout] 158 ~ //! [INFO] [stdout] 159 ~ //! * Time complexity: [INFO] [stdout] 160 ~ //! [INFO] [stdout] 161 ~ //! * Space complexity: [INFO] [stdout] 162 ~ //! [INFO] [stdout] 163 ~ //! * Runtime: 0 ms [INFO] [stdout] 164 ~ //! * Memory: 2.8 MB [INFO] [stdout] 165 ~ //! [INFO] [stdout] 166 ~ //! ```rust [INFO] [stdout] 167 ~ //! impl Solution { [INFO] [stdout] 168 ~ //! pub fn solve_n_queens(n: i32) -> Vec> { [INFO] [stdout] 169 ~ //! if n < 1 { return vec! []; } [INFO] [stdout] 170 ~ //! [INFO] [stdout] 171 ~ //! let mut board = vec![vec!['.'; n as usize]; n as usize]; [INFO] [stdout] 172 ~ //! let mut result = vec![]; [INFO] [stdout] 173 ~ //! Self::_dfs(&mut board, &mut result, n, 0, 0, 0, 0); [INFO] [stdout] 174 ~ //! result [INFO] [stdout] 175 ~ //! } [INFO] [stdout] 176 ~ //! pub fn _dfs( [INFO] [stdout] 177 ~ //! board: &mut Vec>, [INFO] [stdout] 178 ~ //! result: &mut Vec>, [INFO] [stdout] 179 ~ //! n: i32, [INFO] [stdout] 180 ~ //! row: i32, [INFO] [stdout] 181 ~ //! col: i32, [INFO] [stdout] 182 ~ //! xy_sum: i32, [INFO] [stdout] 183 ~ //! xy_sub: i32 [INFO] [stdout] 184 ~ //! ) { [INFO] [stdout] 185 ~ //! if row >= n { [INFO] [stdout] 186 ~ //! result.push(board.iter().map(|vec| vec.iter().collect()).collect()); [INFO] [stdout] 187 ~ //! return; [INFO] [stdout] 188 ~ //! } [INFO] [stdout] 189 ~ //! [INFO] [stdout] 190 ~ //! // bits = 2^t0 + 2^t1 + 2^t2 + ... (t0 < t1 < t2 < ...) [INFO] [stdout] 191 ~ //! let mut bits = (!(col | xy_sum | xy_sub)) & ((1 << n) - 1); [INFO] [stdout] 192 ~ //! while bits != 0 { [INFO] [stdout] 193 ~ //! // p = 2^t0, so log2(p) = t0, t0 is the position to puts Q [INFO] [stdout] 194 ~ //! let p = bits & -bits; [INFO] [stdout] 195 ~ //! board[row as usize][((p as f32).log2()) as usize] = 'Q'; // puts Q in board[row][t0] [INFO] [stdout] 196 ~ //! Self::_dfs(board, result, n, row + 1, col | p, (xy_sum | p) << 1, (xy_sub | p) >> 1); // row + 1 and next recursion [INFO] [stdout] 197 ~ //! board[row as usize][((p as f32).log2())as usize] = '.'; [INFO] [stdout] 198 ~ //! bits = bits & (bits - 1); [INFO] [stdout] 199 ~ //! } [INFO] [stdout] 200 ~ //! } [INFO] [stdout] 201 ~ //! } [INFO] [stdout] 202 ~ //! ``` [INFO] [stdout] 203 ~ //! Reference [INFO] [stdout] 204 ~ //! * [LeetCode51](http://www.voidcn.com/article/p-wsavmpbh-bpn.html) [INFO] [stdout] 205 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0052_n_queens_ii/mod.rs:170:1 [INFO] [stdout] | [INFO] [stdout] 170 | / /// * [LeetCode52](https://www.cnblogs.com/albert1017/archive/2013/01/15/2860973.html) [INFO] [stdout] 171 | | [INFO] [stdout] | |_^ [INFO] [stdout] 172 | pub fn total_n_queens(n: i32) -> i32 { [INFO] [stdout] | --------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 31 ~ //! # Solutions [INFO] [stdout] 32 ~ //! [INFO] [stdout] 33 ~ //! # Approach 1: DFS [INFO] [stdout] 34 ~ //! [INFO] [stdout] 35 ~ //! * Time complexity: [INFO] [stdout] 36 ~ //! [INFO] [stdout] 37 ~ //! * Space complexity: [INFO] [stdout] 38 ~ //! [INFO] [stdout] 39 ~ //! * Runtime: 4 ms [INFO] [stdout] 40 ~ //! * Memory: 2.8 MB [INFO] [stdout] 41 ~ //! [INFO] [stdout] 42 ~ //! ```rust [INFO] [stdout] 43 ~ //! impl Solution { [INFO] [stdout] 44 ~ //! pub fn total_n_queens(n: i32) -> i32 { [INFO] [stdout] 45 ~ //! if n < 1 { return 0; } [INFO] [stdout] 46 ~ //! [INFO] [stdout] 47 ~ //! let mut result = 0; [INFO] [stdout] 48 ~ //! let mut cols = vec![]; [INFO] [stdout] 49 ~ //! let mut xy_sum = vec![]; [INFO] [stdout] 50 ~ //! let mut xy_sub = vec![]; [INFO] [stdout] 51 ~ //! let row = 0; [INFO] [stdout] 52 ~ //! [INFO] [stdout] 53 ~ //! Self::_dfs(n, &mut result, row, &mut cols, &mut xy_sum, &mut xy_sub); [INFO] [stdout] 54 ~ //! [INFO] [stdout] 55 ~ //! result [INFO] [stdout] 56 ~ //! } [INFO] [stdout] 57 ~ //! [INFO] [stdout] 58 ~ //! pub fn _dfs(n: i32, result: &mut i32, row: i32, cols: &mut Vec, xy_sum: &mut Vec, xy_sub: &mut Vec) { [INFO] [stdout] 59 ~ //! if row >= n { [INFO] [stdout] 60 ~ //! *result += 1; [INFO] [stdout] 61 ~ //! return; [INFO] [stdout] 62 ~ //! } [INFO] [stdout] 63 ~ //! [INFO] [stdout] 64 ~ //! for col in 0..n { [INFO] [stdout] 65 ~ //! if cols.contains(&col) || xy_sum.contains(&(row + col)) || xy_sub.contains(&(row - col)) { [INFO] [stdout] 66 ~ //! continue; [INFO] [stdout] 67 ~ //! } [INFO] [stdout] 68 ~ //! [INFO] [stdout] 69 ~ //! cols.push(col); [INFO] [stdout] 70 ~ //! xy_sum.push(row + col); [INFO] [stdout] 71 ~ //! xy_sub.push(row - col); [INFO] [stdout] 72 ~ //! Self::_dfs(n, result, row + 1, cols, xy_sum, xy_sub); [INFO] [stdout] 73 ~ //! [INFO] [stdout] 74 ~ //! cols.retain(|&x| x != col); [INFO] [stdout] 75 ~ //! xy_sum.retain(|&x| x != (row + col)); [INFO] [stdout] 76 ~ //! xy_sub.retain(|&x| x != (row - col)); [INFO] [stdout] 77 ~ //! } [INFO] [stdout] 78 ~ //! } [INFO] [stdout] 79 ~ //! } [INFO] [stdout] 80 ~ //! ``` [INFO] [stdout] 81 ~ //! [INFO] [stdout] 82 ~ //! # Approach 2: DFS [INFO] [stdout] 83 ~ //! [INFO] [stdout] 84 ~ //! * Time complexity: [INFO] [stdout] 85 ~ //! [INFO] [stdout] 86 ~ //! * Space complexity: [INFO] [stdout] 87 ~ //! [INFO] [stdout] 88 ~ //! * Runtime: 0 ms [INFO] [stdout] 89 ~ //! * Memory: 2.8 MB [INFO] [stdout] 90 ~ //! [INFO] [stdout] 91 ~ //! ```rust [INFO] [stdout] 92 ~ //! impl Solution { [INFO] [stdout] 93 ~ //! pub fn total_n_queens(n: i32) -> Vec> { [INFO] [stdout] 94 ~ //! let mut board = vec![vec!['.'; n as usize]; n as usize]; [INFO] [stdout] 95 ~ //! let mut num = 0; [INFO] [stdout] 96 ~ //! Self::schedule_queens(&mut board, &mut num, n as usize, 0); [INFO] [stdout] 97 ~ //! solution [INFO] [stdout] 98 ~ //! } [INFO] [stdout] 99 ~ //! [INFO] [stdout] 100 ~ //! fn schedule_queens(board: &mut Vec>, num &mut i32, len: usize, row: usize) { [INFO] [stdout] 101 ~ //! for col in 0..len { [INFO] [stdout] 102 ~ //! if !Self::collision(&board, len, row, col) { [INFO] [stdout] 103 ~ //! board[row][col] = 'Q'; [INFO] [stdout] 104 ~ //! if row == len - 1 { [INFO] [stdout] 105 ~ //! *num += 1; [INFO] [stdout] 106 ~ //! } else { [INFO] [stdout] 107 ~ //! Self::schedule_queens(board, solution, len, row+1); [INFO] [stdout] 108 ~ //! } [INFO] [stdout] 109 ~ //! board[row][col] = '.'; [INFO] [stdout] 110 ~ //! } [INFO] [stdout] 111 ~ //! } [INFO] [stdout] 112 ~ //! } [INFO] [stdout] 113 ~ //! [INFO] [stdout] 114 ~ //! #[inline(always)] [INFO] [stdout] 115 ~ //! fn collision(board: &Vec>, len: usize, row: usize, col: usize) -> bool { [INFO] [stdout] 116 ~ //! for i in 0..row { [INFO] [stdout] 117 ~ //! if board[i][col] == 'Q' { return true } [INFO] [stdout] 118 ~ //! } [INFO] [stdout] 119 ~ //! let (mut i, mut j) = (row as i32 - 1, col as i32 - 1); [INFO] [stdout] 120 ~ //! while i >= 0 && j >= 0 { [INFO] [stdout] 121 ~ //! if board[i as usize][j as usize] == 'Q' { return true } [INFO] [stdout] 122 ~ //! i -= 1; j -= 1; [INFO] [stdout] 123 ~ //! } [INFO] [stdout] 124 ~ //! let (mut i, mut j) = (row as i32 - 1, col as i32 + 1); [INFO] [stdout] 125 ~ //! while i >= 0 && j < len as i32 { [INFO] [stdout] 126 ~ //! if board[i as usize][j as usize] == 'Q' { return true} [INFO] [stdout] 127 ~ //! i -= 1; j += 1; [INFO] [stdout] 128 ~ //! } [INFO] [stdout] 129 ~ //! false [INFO] [stdout] 130 ~ //! } [INFO] [stdout] 131 ~ //! } [INFO] [stdout] 132 ~ //! ``` [INFO] [stdout] 133 ~ //! [INFO] [stdout] 134 ~ //! # Approach 3: BitWise [INFO] [stdout] 135 ~ //! [INFO] [stdout] 136 ~ //! * Time complexity: [INFO] [stdout] 137 ~ //! [INFO] [stdout] 138 ~ //! * Space complexity: [INFO] [stdout] 139 ~ //! [INFO] [stdout] 140 ~ //! * Runtime: 0 ms [INFO] [stdout] 141 ~ //! * Memory: 2.3 MB [INFO] [stdout] 142 ~ //! [INFO] [stdout] 143 ~ //! ```rust [INFO] [stdout] 144 ~ //! impl Solution { [INFO] [stdout] 145 ~ //! pub fn total_n_queens(n: i32) -> i32 { [INFO] [stdout] 146 ~ //! if n < 1 { return 0; } [INFO] [stdout] 147 ~ //! [INFO] [stdout] 148 ~ //! let mut result = 0; [INFO] [stdout] 149 ~ //! Self::_dfs(n, &mut result, 0, 0, 0, 0); [INFO] [stdout] 150 ~ //! result [INFO] [stdout] 151 ~ //! } [INFO] [stdout] 152 ~ //! [INFO] [stdout] 153 ~ //! pub fn _dfs(n: i32, result: &mut i32, row: i32, col: i32, pie: i32, na: i32) { [INFO] [stdout] 154 ~ //! if row >= n { [INFO] [stdout] 155 ~ //! *result += 1; [INFO] [stdout] 156 ~ //! return; [INFO] [stdout] 157 ~ //! } [INFO] [stdout] 158 ~ //! [INFO] [stdout] 159 ~ //! let mut bits = (!(col | pie | na)) & ((1 << n) - 1); [INFO] [stdout] 160 ~ //! while bits != 0 { [INFO] [stdout] 161 ~ //! let p = bits & -bits; [INFO] [stdout] 162 ~ //! Self::_dfs(n, result, row + 1, col | p, (pie | p) << 1, (na | p) >> 1); [INFO] [stdout] 163 ~ //! bits = bits & (bits - 1); [INFO] [stdout] 164 ~ //! } [INFO] [stdout] 165 ~ //! } [INFO] [stdout] 166 ~ //! [INFO] [stdout] 167 ~ //! ``` [INFO] [stdout] 168 ~ //! Reference [INFO] [stdout] 169 ~ //! * [LeetCode52](https://lichangke.github.io/2019/04/18/LeetCode-52-N%E7%9A%87%E5%90%8E-II(N-Queens-II)/) [INFO] [stdout] 170 ~ //! * [LeetCode52](https://www.cnblogs.com/albert1017/archive/2013/01/15/2860973.html) [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0072_edit_distance/mod.rs:116:1 [INFO] [stdout] | [INFO] [stdout] 116 | / /// [INFO] [stdout] 117 | | [INFO] [stdout] | |_^ [INFO] [stdout] 118 | pub fn min_distance(word1: String, word2: String) -> i32 { [INFO] [stdout] | ------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 35 ~ //! # Solutions [INFO] [stdout] 36 ~ //! [INFO] [stdout] 37 ~ //! # Approach 1: Dynamic Programming [INFO] [stdout] 38 ~ //! [INFO] [stdout] 39 ~ //! * Time complexity: O(m*n) [INFO] [stdout] 40 ~ //! [INFO] [stdout] 41 ~ //! * Space complexity: O(m*n) [INFO] [stdout] 42 ~ //! [INFO] [stdout] 43 ~ //! * Runtime: 4 ms [INFO] [stdout] 44 ~ //! * Memory: 4.5 MB [INFO] [stdout] 45 ~ //! [INFO] [stdout] 46 ~ //! ```rust [INFO] [stdout] 47 ~ //! impl Solution { [INFO] [stdout] 48 ~ //! pub fn min_distance(word1: String, word2: String) -> i32 { [INFO] [stdout] 49 ~ //! let word1_bytes = word1.into_bytes(); [INFO] [stdout] 50 ~ //! let word2_bytes = word2.into_bytes(); [INFO] [stdout] 51 ~ //! let m = word1_bytes.len(); [INFO] [stdout] 52 ~ //! let n = word2_bytes.len(); [INFO] [stdout] 53 ~ //! let mut dp = vec![vec![0; n + 1]; m + 1]; [INFO] [stdout] 54 ~ //! [INFO] [stdout] 55 ~ //! // number of deletions to reach word2[0] [INFO] [stdout] 56 ~ //! for i in 0..=m { dp[i][0] = i; } [INFO] [stdout] 57 ~ //! // to construct word2[j] just with word1[0] need to j insertions [INFO] [stdout] 58 ~ //! for j in 0..=n { dp[0][j] = j; } [INFO] [stdout] 59 ~ //! [INFO] [stdout] 60 ~ //! for i in 1..=m { [INFO] [stdout] 61 ~ //! for j in 1..=n { [INFO] [stdout] 62 ~ //! // we can obtain word2[0..j] from word1[0..i] either by [INFO] [stdout] 63 ~ //! // deleting the ith charactor. knowing eg: dp[i - 1][j] [INFO] [stdout] 64 ~ //! // inserting the jth charactor. knowing eg: dp[i][j - 1] [INFO] [stdout] 65 ~ //! // or replate ith charactor with jth charactor. knowing eg: dp[i - 1][j - 1] [INFO] [stdout] 66 ~ //! dp[i][j] = (dp[i - 1][j - 1] + (word1_bytes[i - 1] != word2_bytes[j - 1]) as usize) [INFO] [stdout] 67 ~ //! .min(dp[i - 1][j] + 1) [INFO] [stdout] 68 ~ //! .min(dp[i][j - 1] + 1); [INFO] [stdout] 69 ~ //! } [INFO] [stdout] 70 ~ //! } [INFO] [stdout] 71 ~ //! dp[m][n] as i32 [INFO] [stdout] 72 ~ //! } [INFO] [stdout] 73 ~ //! } [INFO] [stdout] 74 ~ //! ``` [INFO] [stdout] 75 ~ //! [INFO] [stdout] 76 ~ //! # Approach 2: Dynamic Programming [INFO] [stdout] 77 ~ //! [INFO] [stdout] 78 ~ //! * Time complexity: O(m*n) [INFO] [stdout] 79 ~ //! [INFO] [stdout] 80 ~ //! * Space complexity: O(m*n) [INFO] [stdout] 81 ~ //! [INFO] [stdout] 82 ~ //! * Runtime: 4 ms [INFO] [stdout] 83 ~ //! * Memory: 4.5 MB [INFO] [stdout] 84 ~ //! [INFO] [stdout] 85 ~ //! ```rust [INFO] [stdout] 86 ~ //! impl Solution { [INFO] [stdout] 87 ~ //! pub fn min_distance(word1: String, word2: String) -> i32 { [INFO] [stdout] 88 ~ //! let word1_bytes = word1.into_bytes(); [INFO] [stdout] 89 ~ //! let word2_bytes = word2.into_bytes(); [INFO] [stdout] 90 ~ //! let m = word1_bytes.len(); [INFO] [stdout] 91 ~ //! let n = word2_bytes.len(); [INFO] [stdout] 92 ~ //! let mut dp = vec![vec![0; n + 1]; m + 1]; [INFO] [stdout] 93 ~ //! [INFO] [stdout] 94 ~ //! // number of deletions to reach word2[0] [INFO] [stdout] 95 ~ //! for i in 0..=m { dp[i][0] = i; } [INFO] [stdout] 96 ~ //! // to construct word2[j] just with word1[0] need to j insertions [INFO] [stdout] 97 ~ //! for j in 0..=n { dp[0][j] = j; } [INFO] [stdout] 98 ~ //! [INFO] [stdout] 99 ~ //! for i in 1..=m { [INFO] [stdout] 100 ~ //! for j in 1..=n { [INFO] [stdout] 101 ~ //! if word1_bytes[i - 1] == word2_bytes[j - 1] { [INFO] [stdout] 102 ~ //! dp[i][j] = dp[i - 1][j - 1]; [INFO] [stdout] 103 ~ //! } else { [INFO] [stdout] 104 ~ //! // we can obtain word2[0..j] from word1[0..i] either by [INFO] [stdout] 105 ~ //! // deleting the ith charactor. knowing eg: dp[i - 1][j] [INFO] [stdout] 106 ~ //! // inserting the jth charactor. knowing eg: dp[i][j - 1] [INFO] [stdout] 107 ~ //! // or replate ith charactor with jth charactor. knowing eg: dp[i - 1][j - 1] [INFO] [stdout] 108 ~ //! dp[i][j] = dp[i - 1][j].min(dp[i][j - 1]).min(dp[i - 1][j - 1]) + 1; [INFO] [stdout] 109 ~ //! } [INFO] [stdout] 110 ~ //! } [INFO] [stdout] 111 ~ //! } [INFO] [stdout] 112 ~ //! dp[m][n] as i32 [INFO] [stdout] 113 ~ //! } [INFO] [stdout] 114 ~ //! } [INFO] [stdout] 115 ~ //! ``` [INFO] [stdout] 116 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0200_number_of_islands/mod.rs:169:1 [INFO] [stdout] | [INFO] [stdout] 169 | / /// [INFO] [stdout] 170 | | [INFO] [stdout] | |_^ [INFO] [stdout] 171 | pub fn num_islands(grid: Vec>) -> i32 { [INFO] [stdout] | ------------------ the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 30 ~ //! # Solutions [INFO] [stdout] 31 ~ //! [INFO] [stdout] 32 ~ //! # Approach 1: Union Find [INFO] [stdout] 33 ~ //! [INFO] [stdout] 34 ~ //! * Time complexity: O(m*n) [INFO] [stdout] 35 ~ //! [INFO] [stdout] 36 ~ //! * Space complexity: O(m*n) [INFO] [stdout] 37 ~ //! [INFO] [stdout] 38 ~ //! * Runtime: 4 ms [INFO] [stdout] 39 ~ //! * Memory: 4.6 MB [INFO] [stdout] 40 ~ //! [INFO] [stdout] 41 ~ //! ```rust [INFO] [stdout] 42 ~ //! struct UnionFind { [INFO] [stdout] 43 ~ //! parents: Vec, [INFO] [stdout] 44 ~ //! count: i32, [INFO] [stdout] 45 ~ //! rank: Vec, [INFO] [stdout] 46 ~ //! } [INFO] [stdout] 47 ~ //! [INFO] [stdout] 48 ~ //! impl UnionFind { [INFO] [stdout] 49 ~ //! fn new(grid: &Vec>) -> Self { [INFO] [stdout] 50 ~ //! let m = grid.len(); [INFO] [stdout] 51 ~ //! let n = grid[0].len(); [INFO] [stdout] 52 ~ //! let mut count = 0; [INFO] [stdout] 53 ~ //! let mut parents = vec![-1; m * n]; [INFO] [stdout] 54 ~ //! let rank = vec![0; m * n]; [INFO] [stdout] 55 ~ //! for i in 0..m { [INFO] [stdout] 56 ~ //! for j in 0..n { [INFO] [stdout] 57 ~ //! if grid[i][j] == '1' { [INFO] [stdout] 58 ~ //! parents[i * n + j] = (i * n + j) as i32; [INFO] [stdout] 59 ~ //! count += 1; [INFO] [stdout] 60 ~ //! } [INFO] [stdout] 61 ~ //! } [INFO] [stdout] 62 ~ //! } [INFO] [stdout] 63 ~ //! UnionFind { parents: parents, count: count, rank: rank } [INFO] [stdout] 64 ~ //! } [INFO] [stdout] 65 ~ //! [INFO] [stdout] 66 ~ //! fn find(&mut self, i: i32) -> i32 { [INFO] [stdout] 67 ~ //! if self.parents[i as usize] != i { [INFO] [stdout] 68 ~ //! self.parents[i as usize] = self.find(self.parents[i as usize]) [INFO] [stdout] 69 ~ //! }; [INFO] [stdout] 70 ~ //! self.parents[i as usize] [INFO] [stdout] 71 ~ //! } [INFO] [stdout] 72 ~ //! [INFO] [stdout] 73 ~ //! fn union(&mut self, x: i32, y: i32) -> i32 { [INFO] [stdout] 74 ~ //! let x_parent = self.find(x); [INFO] [stdout] 75 ~ //! let y_parent = self.find(y); [INFO] [stdout] 76 ~ //! [INFO] [stdout] 77 ~ //! if x_parent == y_parent { return self.count; } [INFO] [stdout] 78 ~ //! [INFO] [stdout] 79 ~ //! if self.rank[x_parent as usize] < self.rank[y_parent as usize] { [INFO] [stdout] 80 ~ //! self.parents[x_parent as usize] = y_parent; [INFO] [stdout] 81 ~ //! } else if self.rank[x_parent as usize] > self.rank[y_parent as usize] { [INFO] [stdout] 82 ~ //! self.parents[y_parent as usize] = x_parent; [INFO] [stdout] 83 ~ //! } else { [INFO] [stdout] 84 ~ //! self.parents[y_parent as usize] = x_parent; [INFO] [stdout] 85 ~ //! self.rank[y_parent as usize] += 1; [INFO] [stdout] 86 ~ //! } [INFO] [stdout] 87 ~ //! self.count -= 1; [INFO] [stdout] 88 ~ //! [INFO] [stdout] 89 ~ //! self.count [INFO] [stdout] 90 ~ //! } [INFO] [stdout] 91 ~ //! } [INFO] [stdout] 92 ~ //! [INFO] [stdout] 93 ~ //! impl Solution { [INFO] [stdout] 94 ~ //! pub fn num_islands(grid: Vec>) -> i32 { [INFO] [stdout] 95 ~ //! if grid.is_empty() { return 0; } [INFO] [stdout] 96 ~ //! [INFO] [stdout] 97 ~ //! let directions: Vec<(i32, i32)> = vec![(-1, 0), (1, 0), (0, -1), (0, 1)]; [INFO] [stdout] 98 ~ //! let (m, n) = (grid.len(), grid[0].len()); [INFO] [stdout] 99 ~ //! let mut uf = UnionFind::new(&grid); [INFO] [stdout] 100 ~ //! [INFO] [stdout] 101 ~ //! for i in 0..m { [INFO] [stdout] 102 ~ //! for j in 0..n { [INFO] [stdout] 103 ~ //! if grid[i][j] == '0' { continue; } [INFO] [stdout] 104 ~ //! [INFO] [stdout] 105 ~ //! for d in &directions { [INFO] [stdout] 106 ~ //! let (dr, dc) = (i as i32 + d.0, j as i32 + d.1); [INFO] [stdout] 107 ~ //! if dr >= 0 && [INFO] [stdout] 108 ~ //! dc >= 0 && [INFO] [stdout] 109 ~ //! dr < m as i32 && [INFO] [stdout] 110 ~ //! dc < n as i32 && [INFO] [stdout] 111 ~ //! grid[dr as usize][dc as usize] == '1' { [INFO] [stdout] 112 ~ //! uf.union((i * n + j) as i32, dr * n as i32 + dc); [INFO] [stdout] 113 ~ //! } [INFO] [stdout] 114 ~ //! } [INFO] [stdout] 115 ~ //! } [INFO] [stdout] 116 ~ //! } [INFO] [stdout] 117 ~ //! uf.count [INFO] [stdout] 118 ~ //! [INFO] [stdout] 119 ~ //! } [INFO] [stdout] 120 ~ //! } [INFO] [stdout] 121 ~ //! ``` [INFO] [stdout] 122 ~ //! [INFO] [stdout] 123 ~ //! # Approach 2: DFS [INFO] [stdout] 124 ~ //! [INFO] [stdout] 125 ~ //! * Time complexity: O(m*n) [INFO] [stdout] 126 ~ //! [INFO] [stdout] 127 ~ //! * Space complexity: O(m*n) [INFO] [stdout] 128 ~ //! [INFO] [stdout] 129 ~ //! * Runtime: 16ms [INFO] [stdout] 130 ~ //! * Memory: 4.7MB [INFO] [stdout] 131 ~ //! [INFO] [stdout] 132 ~ //! ```rust [INFO] [stdout] 133 ~ //! use std::collections::HashSet; [INFO] [stdout] 134 ~ //! [INFO] [stdout] 135 ~ //! impl Solution { [INFO] [stdout] 136 ~ //! pub fn num_islands(grid: Vec>) -> i32 { [INFO] [stdout] 137 ~ //! if grid.is_empty() { return 0; } [INFO] [stdout] 138 ~ //! [INFO] [stdout] 139 ~ //! let mut visited: HashSet<(usize, usize)> = HashSet::new(); [INFO] [stdout] 140 ~ //! let mut result = 0; [INFO] [stdout] 141 ~ //! let m = grid.len(); [INFO] [stdout] 142 ~ //! let n = grid[0].len(); [INFO] [stdout] 143 ~ //! [INFO] [stdout] 144 ~ //! for i in 0..m { [INFO] [stdout] 145 ~ //! for j in 0..n { [INFO] [stdout] 146 ~ //! if !visited.contains(&(i, j)) && grid[i][j] == '1' { [INFO] [stdout] 147 ~ //! Self::dfs(&grid, &mut visited, i, j); [INFO] [stdout] 148 ~ //! result += 1; [INFO] [stdout] 149 ~ //! } [INFO] [stdout] 150 ~ //! } [INFO] [stdout] 151 ~ //! } [INFO] [stdout] 152 ~ //! [INFO] [stdout] 153 ~ //! result [INFO] [stdout] 154 ~ //! } [INFO] [stdout] 155 ~ //! [INFO] [stdout] 156 ~ //! const DIRECTIONS: [[i32; 2]; 4] = [[1, 0], [-1, 0], [0, 1], [0, -1]]; [INFO] [stdout] 157 ~ //! pub fn dfs(grid: &Vec>, visited: &mut HashSet<(usize, usize)>, m: usize, n: usize) { [INFO] [stdout] 158 ~ //! if m >= grid.len() || n >= grid[0].len() || grid[m][n] == '0' || visited.contains(&(m, n)) { return; } [INFO] [stdout] 159 ~ //! [INFO] [stdout] 160 ~ //! visited.insert((m, n)); [INFO] [stdout] 161 ~ //! for dis in Self::DIRECTIONS.iter() { [INFO] [stdout] 162 ~ //! let dr = (dis[0] + m as i32) as usize; [INFO] [stdout] 163 ~ //! let dc = (dis[1] + n as i32) as usize; [INFO] [stdout] 164 ~ //! Self::dfs(grid, visited, dr, dc); [INFO] [stdout] 165 ~ //! } [INFO] [stdout] 166 ~ //! } [INFO] [stdout] 167 ~ //! } [INFO] [stdout] 168 ~ //! ``` [INFO] [stdout] 169 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: redundant field names in struct initialization [INFO] [stdout] --> src/cd0200_number_of_islands/mod.rs:219:21 [INFO] [stdout] | [INFO] [stdout] 219 | UnionFind { parents: parents, count: count, rank: rank } [INFO] [stdout] | ^^^^^^^^^^^^^^^^ help: replace it with: `parents` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names [INFO] [stdout] = note: `#[warn(clippy::redundant_field_names)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: redundant field names in struct initialization [INFO] [stdout] --> src/cd0200_number_of_islands/mod.rs:219:39 [INFO] [stdout] | [INFO] [stdout] 219 | UnionFind { parents: parents, count: count, rank: rank } [INFO] [stdout] | ^^^^^^^^^^^^ help: replace it with: `count` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: redundant field names in struct initialization [INFO] [stdout] --> src/cd0200_number_of_islands/mod.rs:219:53 [INFO] [stdout] | [INFO] [stdout] 219 | UnionFind { parents: parents, count: count, rank: rank } [INFO] [stdout] | ^^^^^^^^^^ help: replace it with: `rank` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:46:5 [INFO] [stdout] | [INFO] [stdout] 46 | /// if head.is_none() { return None; } [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] = note: `#[warn(clippy::tabs_in_doc_comments)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:48:5 [INFO] [stdout] | [INFO] [stdout] 48 | /// let mut prev = None; [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:49:5 [INFO] [stdout] | [INFO] [stdout] 49 | /// let mut current = head; [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:50:5 [INFO] [stdout] | [INFO] [stdout] 50 | /// while let Some(mut tmp) = current.take() { [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:51:5 [INFO] [stdout] | [INFO] [stdout] 51 | /// let next = tmp.next.take(); [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:52:5 [INFO] [stdout] | [INFO] [stdout] 52 | /// tmp.next = prev.take(); [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:53:5 [INFO] [stdout] | [INFO] [stdout] 53 | /// prev = Some(tmp); [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:54:5 [INFO] [stdout] | [INFO] [stdout] 54 | /// current = next; [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:55:5 [INFO] [stdout] | [INFO] [stdout] 55 | /// } [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:57:5 [INFO] [stdout] | [INFO] [stdout] 57 | /// prev [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: `...` range patterns are deprecated [INFO] [stdout] --> src/cd0224_basic_calculator/mod.rs:88:16 [INFO] [stdout] | [INFO] [stdout] 88 | '0'...'9' => { [INFO] [stdout] | ^^^ help: use `..=` for an inclusive range [INFO] [stdout] | [INFO] [stdout] = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! [INFO] [stdout] = note: for more information, see [INFO] [stdout] = note: `#[warn(ellipsis_inclusive_range_patterns)]` (part of `#[warn(rust_2021_compatibility)]`) on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0300_longest_increasing_subsequence/mod.rs:116:1 [INFO] [stdout] | [INFO] [stdout] 116 | / /// [INFO] [stdout] 117 | | [INFO] [stdout] | |_^ [INFO] [stdout] 118 | pub fn length_of_lis(nums: Vec) -> i32 { [INFO] [stdout] | -------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 19 ~ //! # Solutions [INFO] [stdout] 20 ~ //! [INFO] [stdout] 21 ~ //! # Approach 1: Dynamic Programming [INFO] [stdout] 22 ~ //! [INFO] [stdout] 23 ~ //! * Time complexity: O(nlogn) [INFO] [stdout] 24 ~ //! [INFO] [stdout] 25 ~ //! * Space complexity: O(n) [INFO] [stdout] 26 ~ //! [INFO] [stdout] 27 ~ //! * Runtime: 0 ms [INFO] [stdout] 28 ~ //! * Memory: 2.5 MB [INFO] [stdout] 29 ~ //! [INFO] [stdout] 30 ~ //! ```rust [INFO] [stdout] 31 ~ //! impl Solution { [INFO] [stdout] 32 ~ //! pub fn length_of_lis(nums: Vec) -> i32 { [INFO] [stdout] 33 ~ //! if nums.len() <= 1 { return nums.len() as i32; } [INFO] [stdout] 34 ~ //! [INFO] [stdout] 35 ~ //! let mut lis = vec![]; [INFO] [stdout] 36 ~ //! lis.push(nums[0]); [INFO] [stdout] 37 ~ //! [INFO] [stdout] 38 ~ //! for i in 1..nums.len() { [INFO] [stdout] 39 ~ //! match lis.binary_search(&nums[i]) { [INFO] [stdout] 40 ~ //! Ok(n) => (), [INFO] [stdout] 41 ~ //! Err(n) => { [INFO] [stdout] 42 ~ //! if n >= lis.len() { lis.push(nums[i]); } else { lis[n] = nums[i]; } [INFO] [stdout] 43 ~ //! }, [INFO] [stdout] 44 ~ //! } [INFO] [stdout] 45 ~ //! } [INFO] [stdout] 46 ~ //! lis.len() as i32 [INFO] [stdout] 47 ~ //! } [INFO] [stdout] 48 ~ //! } [INFO] [stdout] 49 ~ //! ``` [INFO] [stdout] 50 ~ //! [INFO] [stdout] 51 ~ //! # Approach 2: Dynamic Programming [INFO] [stdout] 52 ~ //! [INFO] [stdout] 53 ~ //! * Time complexity: O(n2) [INFO] [stdout] 54 ~ //! [INFO] [stdout] 55 ~ //! * Space complexity: O(n) [INFO] [stdout] 56 ~ //! [INFO] [stdout] 57 ~ //! * Runtime: 12 ms [INFO] [stdout] 58 ~ //! * Memory: 2.5 MB [INFO] [stdout] 59 ~ //! [INFO] [stdout] 60 ~ //! ```rust [INFO] [stdout] 61 ~ //! use std::cmp::max; [INFO] [stdout] 62 ~ //! [INFO] [stdout] 63 ~ //! impl Solution { [INFO] [stdout] 64 ~ //! pub fn length_of_lis(nums: Vec) -> i32 { [INFO] [stdout] 65 ~ //! if nums.len() <= 1 { return nums.len() as i32; } [INFO] [stdout] 66 ~ //! [INFO] [stdout] 67 ~ //! let mut dp = vec![1; nums.len()]; [INFO] [stdout] 68 ~ //! let mut max_lis = 1; [INFO] [stdout] 69 ~ //! [INFO] [stdout] 70 ~ //! for i in 1..nums.len() { [INFO] [stdout] 71 ~ //! let mut tmp_max = 0; [INFO] [stdout] 72 ~ //! for j in 0..i { [INFO] [stdout] 73 ~ //! if nums[i] > nums[j] { [INFO] [stdout] 74 ~ //! tmp_max = max(tmp_max, dp[j]); [INFO] [stdout] 75 ~ //! } [INFO] [stdout] 76 ~ //! dp[i] = tmp_max + 1; [INFO] [stdout] 77 ~ //! } [INFO] [stdout] 78 ~ //! max_lis = max(max_lis, dp[i]); [INFO] [stdout] 79 ~ //! } [INFO] [stdout] 80 ~ //! max_lis [INFO] [stdout] 81 ~ //! } [INFO] [stdout] 82 ~ //! } [INFO] [stdout] 83 ~ //! ``` [INFO] [stdout] 84 ~ //! [INFO] [stdout] 85 ~ //! # Approach 3: Dynamic Programming [INFO] [stdout] 86 ~ //! [INFO] [stdout] 87 ~ //! * Time complexity: O(n2) [INFO] [stdout] 88 ~ //! [INFO] [stdout] 89 ~ //! * Space complexity: O(n) [INFO] [stdout] 90 ~ //! [INFO] [stdout] 91 ~ //! * Runtime: 8 ms [INFO] [stdout] 92 ~ //! * Memory: 2.5 MB [INFO] [stdout] 93 ~ //! [INFO] [stdout] 94 ~ //! ```rust [INFO] [stdout] 95 ~ //! use std::cmp::max; [INFO] [stdout] 96 ~ //! [INFO] [stdout] 97 ~ //! impl Solution { [INFO] [stdout] 98 ~ //! pub fn length_of_lis(nums: Vec) -> i32 { [INFO] [stdout] 99 ~ //! if nums.len() <= 1 { return nums.len() as i32; } [INFO] [stdout] 100 ~ //! [INFO] [stdout] 101 ~ //! let mut dp = vec![1; nums.len()]; [INFO] [stdout] 102 ~ //! let mut max_lis = 1; [INFO] [stdout] 103 ~ //! [INFO] [stdout] 104 ~ //! for i in 1..nums.len() { [INFO] [stdout] 105 ~ //! for j in 0..i { [INFO] [stdout] 106 ~ //! if nums[i] > nums[j] { [INFO] [stdout] 107 ~ //! dp[i] = max(dp[i], dp[j] + 1); [INFO] [stdout] 108 ~ //! } [INFO] [stdout] 109 ~ //! } [INFO] [stdout] 110 ~ //! max_lis = max(max_lis, dp[i]); [INFO] [stdout] 111 ~ //! } [INFO] [stdout] 112 ~ //! max_lis [INFO] [stdout] 113 ~ //! } [INFO] [stdout] 114 ~ //! } [INFO] [stdout] 115 ~ //! ``` [INFO] [stdout] 116 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0309_best_time_to_buy_and_sell_stock_with_cooldown/mod.rs:81:1 [INFO] [stdout] | [INFO] [stdout] 81 | / /// [INFO] [stdout] 82 | | [INFO] [stdout] | |_^ [INFO] [stdout] 83 | pub fn max_profit(prices: Vec) -> i32 { [INFO] [stdout] | ----------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 19 ~ //! # Solutions [INFO] [stdout] 20 ~ //! [INFO] [stdout] 21 ~ //! # Approach 1: Dynamic Programming [INFO] [stdout] 22 ~ //! [INFO] [stdout] 23 ~ //! * Time complexity: O(n) [INFO] [stdout] 24 ~ //! [INFO] [stdout] 25 ~ //! * Space complexity: O(n) [INFO] [stdout] 26 ~ //! [INFO] [stdout] 27 ~ //! * Runtime: 0 ms [INFO] [stdout] 28 ~ //! * Memory: 2.6 MB [INFO] [stdout] 29 ~ //! [INFO] [stdout] 30 ~ //! ```rust [INFO] [stdout] 31 ~ //! use std::cmp::max; [INFO] [stdout] 32 ~ //! [INFO] [stdout] 33 ~ //! impl Solution { [INFO] [stdout] 34 ~ //! pub fn max_profit(prices: Vec) -> i32 { [INFO] [stdout] 35 ~ //! if prices.len() < 2 { return 0; } [INFO] [stdout] 36 ~ //! [INFO] [stdout] 37 ~ //! let cooldown = 1; [INFO] [stdout] 38 ~ //! let mut profits = vec![0; prices.len()]; [INFO] [stdout] 39 ~ //! let mut max_profit = 0; [INFO] [stdout] 40 ~ //! let mut tmp_max = profits[0] - prices[0]; [INFO] [stdout] 41 ~ //! [INFO] [stdout] 42 ~ //! for i in 1..prices.len() { [INFO] [stdout] 43 ~ //! profits[i] = max(profits[i - 1], tmp_max + prices[i]); [INFO] [stdout] 44 ~ //! tmp_max = max(tmp_max, if i > cooldown { profits[i - 1 - cooldown] } else { profits[i - 1] } - prices[i]); [INFO] [stdout] 45 ~ //! max_profit = max(profits[i], max_profit); [INFO] [stdout] 46 ~ //! } [INFO] [stdout] 47 ~ //! max_profit [INFO] [stdout] 48 ~ //! } [INFO] [stdout] 49 ~ //! } [INFO] [stdout] 50 ~ //! ``` [INFO] [stdout] 51 ~ //! [INFO] [stdout] 52 ~ //! # Approach 2: Dynamic Programming [INFO] [stdout] 53 ~ //! [INFO] [stdout] 54 ~ //! * Time complexity: O(n) [INFO] [stdout] 55 ~ //! [INFO] [stdout] 56 ~ //! * Space complexity: O(n) [INFO] [stdout] 57 ~ //! [INFO] [stdout] 58 ~ //! * Runtime: 0 ms [INFO] [stdout] 59 ~ //! * Memory: 2.5 MB [INFO] [stdout] 60 ~ //! [INFO] [stdout] 61 ~ //! ```rust [INFO] [stdout] 62 ~ //! use std::cmp::max; [INFO] [stdout] 63 ~ //! [INFO] [stdout] 64 ~ //! impl Solution { [INFO] [stdout] 65 ~ //! pub fn max_profit(prices: Vec) -> i32 { [INFO] [stdout] 66 ~ //! if prices.len() < 2 { return 0; } [INFO] [stdout] 67 ~ //! [INFO] [stdout] 68 ~ //! let cooldown = 1; [INFO] [stdout] 69 ~ //! let mut sell = vec![0; prices.len()]; [INFO] [stdout] 70 ~ //! let mut buy = vec![0; prices.len()]; [INFO] [stdout] 71 ~ //! buy[0] = -prices[0]; [INFO] [stdout] 72 ~ //! [INFO] [stdout] 73 ~ //! for i in 1..prices.len() { [INFO] [stdout] 74 ~ //! sell[i] = max(sell[i - 1], buy[i - 1] + prices[i]); [INFO] [stdout] 75 ~ //! buy[i] = max(buy[i - 1], if i > cooldown { sell[i - 1 - cooldown] } else { sell[i - 1] } - prices[i]); [INFO] [stdout] 76 ~ //! } [INFO] [stdout] 77 ~ //! sell[prices.len() - 1] [INFO] [stdout] 78 ~ //! } [INFO] [stdout] 79 ~ //! } [INFO] [stdout] 80 ~ //! ``` [INFO] [stdout] 81 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0322_coin_change/mod.rs:82:1 [INFO] [stdout] | [INFO] [stdout] 82 | / /// [INFO] [stdout] 83 | | [INFO] [stdout] | |_^ [INFO] [stdout] 84 | pub fn coin_change(coins: Vec, amount: i32) -> i32 { [INFO] [stdout] | ------------------ the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 24 ~ //! # Solutions [INFO] [stdout] 25 ~ //! [INFO] [stdout] 26 ~ //! # Approach 1: Dynamic Programming [INFO] [stdout] 27 ~ //! [INFO] [stdout] 28 ~ //! * Time complexity: O(s*n) [INFO] [stdout] 29 ~ //! [INFO] [stdout] 30 ~ //! * Space complexity: O(s) [INFO] [stdout] 31 ~ //! [INFO] [stdout] 32 ~ //! * Runtime: 4 ms [INFO] [stdout] 33 ~ //! * Memory: 3 MB [INFO] [stdout] 34 ~ //! [INFO] [stdout] 35 ~ //! ```rust [INFO] [stdout] 36 ~ //! impl Solution { [INFO] [stdout] 37 ~ //! pub fn coin_change(coins: Vec, amount: i32) -> i32 { [INFO] [stdout] 38 ~ //! let mut dp = vec![amount + 1; (amount + 1) as usize]; [INFO] [stdout] 39 ~ //! dp[0] = 0; [INFO] [stdout] 40 ~ //! [INFO] [stdout] 41 ~ //! for i in 1..=amount { [INFO] [stdout] 42 ~ //! for &coin in coins.iter() { [INFO] [stdout] 43 ~ //! if i >= coin { [INFO] [stdout] 44 ~ //! dp[i as usize] = i32::min(dp[i as usize], dp[(i - coin) as usize] + 1); [INFO] [stdout] 45 ~ //! } [INFO] [stdout] 46 ~ //! } [INFO] [stdout] 47 ~ //! } [INFO] [stdout] 48 ~ //! let last = *dp.last().unwrap(); [INFO] [stdout] 49 ~ //! if last > amount { return -1; } else { return last; } [INFO] [stdout] 50 ~ //! } [INFO] [stdout] 51 ~ //! } [INFO] [stdout] 52 ~ //! ``` [INFO] [stdout] 53 ~ //! [INFO] [stdout] 54 ~ //! # Approach 2: Dynamic Programming [INFO] [stdout] 55 ~ //! [INFO] [stdout] 56 ~ //! * Time complexity: O(s*n) [INFO] [stdout] 57 ~ //! [INFO] [stdout] 58 ~ //! * Space complexity: O(s) [INFO] [stdout] 59 ~ //! [INFO] [stdout] 60 ~ //! * Runtime: 4 ms [INFO] [stdout] 61 ~ //! * Memory: 4 MB [INFO] [stdout] 62 ~ //! [INFO] [stdout] 63 ~ //! ```rust [INFO] [stdout] 64 ~ //! impl Solution { [INFO] [stdout] 65 ~ //! pub fn coin_change(coins: Vec, amount: i32) -> i32 { [INFO] [stdout] 66 ~ //! let mut dp = vec![-1; (amount+1) as usize]; [INFO] [stdout] 67 ~ //! dp[0] = 0; [INFO] [stdout] 68 ~ //! [INFO] [stdout] 69 ~ //! for i in 1..=amount as usize { [INFO] [stdout] 70 ~ //! dp[i] = std::i32::MAX; [INFO] [stdout] 71 ~ //! for &coin in coins.iter() { [INFO] [stdout] 72 ~ //! if i >= coin as usize && dp[i - coin as usize] != -1 { [INFO] [stdout] 73 ~ //! dp[i] = i32::min(dp[i], dp[i - coin as usize] + 1); [INFO] [stdout] 74 ~ //! } [INFO] [stdout] 75 ~ //! } [INFO] [stdout] 76 ~ //! if dp[i] == std::i32::MAX { dp[i] = -1; } [INFO] [stdout] 77 ~ //! } [INFO] [stdout] 78 ~ //! *dp.last().unwrap() [INFO] [stdout] 79 ~ //! } [INFO] [stdout] 80 ~ //! } [INFO] [stdout] 81 ~ //! ``` [INFO] [stdout] 82 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0547_friend_circles/mod.rs:137:1 [INFO] [stdout] | [INFO] [stdout] 137 | / /// [INFO] [stdout] 138 | | [INFO] [stdout] | |_^ [INFO] [stdout] 139 | pub fn find_circle_num(m: Vec>) -> i32 { [INFO] [stdout] | ---------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 37 ~ //! # Solutions [INFO] [stdout] 38 ~ //! [INFO] [stdout] 39 ~ //! # Approach 1: Union Find [INFO] [stdout] 40 ~ //! [INFO] [stdout] 41 ~ //! * Time complexity: O(m*n) [INFO] [stdout] 42 ~ //! [INFO] [stdout] 43 ~ //! * Space complexity: O(m*n) [INFO] [stdout] 44 ~ //! [INFO] [stdout] 45 ~ //! * Runtime: 0 ms [INFO] [stdout] 46 ~ //! * Memory: 2.7 MB [INFO] [stdout] 47 ~ //! [INFO] [stdout] 48 ~ //! ```rust [INFO] [stdout] 49 ~ //! struct UnionFind { [INFO] [stdout] 50 ~ //! parents: Vec, [INFO] [stdout] 51 ~ //! count: i32, [INFO] [stdout] 52 ~ //! } [INFO] [stdout] 53 ~ //! [INFO] [stdout] 54 ~ //! impl UnionFind { [INFO] [stdout] 55 ~ //! fn new(grid: &Vec>) -> Self { [INFO] [stdout] 56 ~ //! let m = grid.len(); [INFO] [stdout] 57 ~ //! let count = m as i32; [INFO] [stdout] 58 ~ //! let mut parents = vec![]; [INFO] [stdout] 59 ~ //! for i in 0..m { parents.push(i as i32); } [INFO] [stdout] 60 ~ //! [INFO] [stdout] 61 ~ //! UnionFind { parents: parents, count: count } [INFO] [stdout] 62 ~ //! } [INFO] [stdout] 63 ~ //! [INFO] [stdout] 64 ~ //! fn find(&mut self, i: i32) -> i32 { [INFO] [stdout] 65 ~ //! if self.parents[i as usize] != i { self.parents[i as usize] = self.find(self.parents[i as usize]) }; [INFO] [stdout] 66 ~ //! self.parents[i as usize] [INFO] [stdout] 67 ~ //! } [INFO] [stdout] 68 ~ //! [INFO] [stdout] 69 ~ //! fn union(&mut self, x: i32, y: i32) -> i32 { [INFO] [stdout] 70 ~ //! let x_parent = self.find(x); [INFO] [stdout] 71 ~ //! let y_parent = self.find(y); [INFO] [stdout] 72 ~ //! [INFO] [stdout] 73 ~ //! if x_parent == y_parent { return self.count; } [INFO] [stdout] 74 ~ //! [INFO] [stdout] 75 ~ //! self.parents[x_parent as usize] = y_parent; [INFO] [stdout] 76 ~ //! self.count -= 1; [INFO] [stdout] 77 ~ //! [INFO] [stdout] 78 ~ //! self.count [INFO] [stdout] 79 ~ //! } [INFO] [stdout] 80 ~ //! } [INFO] [stdout] 81 ~ //! [INFO] [stdout] 82 ~ //! impl Solution { [INFO] [stdout] 83 ~ //! pub fn find_circle_num(m: Vec>) -> i32 { [INFO] [stdout] 84 ~ //! if m.is_empty() { return 0; } [INFO] [stdout] 85 ~ //! let n = m.len(); [INFO] [stdout] 86 ~ //! let mut uf = UnionFind::new(&m); [INFO] [stdout] 87 ~ //! [INFO] [stdout] 88 ~ //! for i in 0..n { [INFO] [stdout] 89 ~ //! for j in 0..n { [INFO] [stdout] 90 ~ //! if m[i][j] == 1 { uf.union(i as i32, j as i32); } [INFO] [stdout] 91 ~ //! } [INFO] [stdout] 92 ~ //! } [INFO] [stdout] 93 ~ //! uf.count [INFO] [stdout] 94 ~ //! } [INFO] [stdout] 95 ~ //! } [INFO] [stdout] 96 ~ //! ``` [INFO] [stdout] 97 ~ //! [INFO] [stdout] 98 ~ //! # Solutions [INFO] [stdout] 99 ~ //! [INFO] [stdout] 100 ~ //! # Approach 2: DFS [INFO] [stdout] 101 ~ //! [INFO] [stdout] 102 ~ //! * Time complexity: [INFO] [stdout] 103 ~ //! [INFO] [stdout] 104 ~ //! * Space complexity: [INFO] [stdout] 105 ~ //! [INFO] [stdout] 106 ~ //! * Runtime: 0 ms [INFO] [stdout] 107 ~ //! * Memory: 2.7 MB [INFO] [stdout] 108 ~ //! [INFO] [stdout] 109 ~ //! ```rust [INFO] [stdout] 110 ~ //! impl Solution { [INFO] [stdout] 111 ~ //! pub fn find_circle_num(m: Vec>) -> i32 { [INFO] [stdout] 112 ~ //! if m.is_empty() { return 0; } [INFO] [stdout] 113 ~ //! [INFO] [stdout] 114 ~ //! let n = m.len(); [INFO] [stdout] 115 ~ //! let mut visited: Vec = vec![]; [INFO] [stdout] 116 ~ //! let mut count = 0; [INFO] [stdout] 117 ~ //! [INFO] [stdout] 118 ~ //! for i in 0..n { [INFO] [stdout] 119 ~ //! if !visited.contains(&(i as i32)) { [INFO] [stdout] 120 ~ //! Self::dfs(&m, &mut visited, i, n); [INFO] [stdout] 121 ~ //! count += 1; [INFO] [stdout] 122 ~ //! } [INFO] [stdout] 123 ~ //! } [INFO] [stdout] 124 ~ //! count [INFO] [stdout] 125 ~ //! } [INFO] [stdout] 126 ~ //! [INFO] [stdout] 127 ~ //! pub fn dfs(m: &Vec>, visited: &mut Vec, i: usize, n: usize) { [INFO] [stdout] 128 ~ //! for j in 0..n { [INFO] [stdout] 129 ~ //! if m[i][j] == 1 && !visited.contains(&(j as i32)) { [INFO] [stdout] 130 ~ //! visited.push(j as i32); [INFO] [stdout] 131 ~ //! Self::dfs(m, visited, j, n); [INFO] [stdout] 132 ~ //! } [INFO] [stdout] 133 ~ //! } [INFO] [stdout] 134 ~ //! } [INFO] [stdout] 135 ~ //! } [INFO] [stdout] 136 ~ //! ``` [INFO] [stdout] 137 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: redundant field names in struct initialization [INFO] [stdout] --> src/cd0547_friend_circles/mod.rs:165:21 [INFO] [stdout] | [INFO] [stdout] 165 | UnionFind { parents: parents, count: count } [INFO] [stdout] | ^^^^^^^^^^^^^^^^ help: replace it with: `parents` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: redundant field names in struct initialization [INFO] [stdout] --> src/cd0547_friend_circles/mod.rs:165:39 [INFO] [stdout] | [INFO] [stdout] 165 | UnionFind { parents: parents, count: count } [INFO] [stdout] | ^^^^^^^^^^^^ help: replace it with: `count` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:21:33 [INFO] [stdout] | [INFO] [stdout] 21 | //! circularDeque.insertLast(1); // return true [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:22:33 [INFO] [stdout] | [INFO] [stdout] 22 | //! circularDeque.insertLast(2); // return true [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:23:34 [INFO] [stdout] | [INFO] [stdout] 23 | //! circularDeque.insertFront(3); // return true [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:24:34 [INFO] [stdout] | [INFO] [stdout] 24 | //! circularDeque.insertFront(4); // return false, the queue is full [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:25:31 [INFO] [stdout] | [INFO] [stdout] 25 | //! circularDeque.getRear(); // return 2 [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:26:28 [INFO] [stdout] | [INFO] [stdout] 26 | //! circularDeque.isFull(); // return true [INFO] [stdout] | ^^^^^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:27:32 [INFO] [stdout] | [INFO] [stdout] 27 | //! circularDeque.deleteLast(); // return true [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:28:34 [INFO] [stdout] | [INFO] [stdout] 28 | //! circularDeque.insertFront(4); // return true [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:29:30 [INFO] [stdout] | [INFO] [stdout] 29 | //! circularDeque.getFront(); // return 4 [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0714_best_time_to_buy_and_sell_stock_with_transaction_fee/mod.rs:115:1 [INFO] [stdout] | [INFO] [stdout] 115 | / /// [INFO] [stdout] 116 | | [INFO] [stdout] | |_^ [INFO] [stdout] 117 | pub fn max_profit(prices: Vec, fee: i32) -> i32 { [INFO] [stdout] | ----------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 28 ~ //! # Solutions [INFO] [stdout] 29 ~ //! [INFO] [stdout] 30 ~ //! # Approach 1: Dynamic Programming [INFO] [stdout] 31 ~ //! [INFO] [stdout] 32 ~ //! * Time complexity: O(n) [INFO] [stdout] 33 ~ //! [INFO] [stdout] 34 ~ //! * Space complexity: O(n) [INFO] [stdout] 35 ~ //! [INFO] [stdout] 36 ~ //! * Runtime: 8 ms [INFO] [stdout] 37 ~ //! * Memory: 3.7 MB [INFO] [stdout] 38 ~ //! [INFO] [stdout] 39 ~ //! ```rust [INFO] [stdout] 40 ~ //! use std::cmp::max; [INFO] [stdout] 41 ~ //! [INFO] [stdout] 42 ~ //! impl Solution { [INFO] [stdout] 43 ~ //! pub fn max_profit(prices: Vec, fee: i32) -> i32 { [INFO] [stdout] 44 ~ //! if prices.len() < 2 || fee >= 50000 { return 0; } [INFO] [stdout] 45 ~ //! [INFO] [stdout] 46 ~ //! let mut profits = vec![0; prices.len()]; [INFO] [stdout] 47 ~ //! let mut max_profit = 0; [INFO] [stdout] 48 ~ //! let mut tmp_max = profits[0] - prices[0]; [INFO] [stdout] 49 ~ //! [INFO] [stdout] 50 ~ //! for i in 1..prices.len() { [INFO] [stdout] 51 ~ //! profits[i] = max(profits[i - 1], tmp_max + prices[i] - fee); [INFO] [stdout] 52 ~ //! tmp_max = max(tmp_max, profits[i - 1] - prices[i]); [INFO] [stdout] 53 ~ //! max_profit = max(max_profit, profits[i]); [INFO] [stdout] 54 ~ //! } [INFO] [stdout] 55 ~ //! max_profit [INFO] [stdout] 56 ~ //! } [INFO] [stdout] 57 ~ //! } [INFO] [stdout] 58 ~ //! ``` [INFO] [stdout] 59 ~ //! [INFO] [stdout] 60 ~ //! # Approach 2: Dynamic Programming [INFO] [stdout] 61 ~ //! [INFO] [stdout] 62 ~ //! * Time complexity: O(n) [INFO] [stdout] 63 ~ //! [INFO] [stdout] 64 ~ //! * Space complexity: O(n) [INFO] [stdout] 65 ~ //! [INFO] [stdout] 66 ~ //! * Runtime: 8 ms [INFO] [stdout] 67 ~ //! * Memory: 3.6 MB [INFO] [stdout] 68 ~ //! [INFO] [stdout] 69 ~ //! ```rust [INFO] [stdout] 70 ~ //!use std::cmp::max; [INFO] [stdout] 71 ~ //! [INFO] [stdout] 72 ~ //!impl Solution { [INFO] [stdout] 73 ~ //! pub fn max_profit(prices: Vec, fee: i32) -> i32 { [INFO] [stdout] 74 ~ //! if prices.len() < 2 || fee >= 50000 { return 0; } [INFO] [stdout] 75 ~ //! [INFO] [stdout] 76 ~ //! let mut sell = vec![0; prices.len()]; [INFO] [stdout] 77 ~ //! let mut buy = vec![0; prices.len()]; [INFO] [stdout] 78 ~ //! buy[0] = -prices[0]; [INFO] [stdout] 79 ~ //! [INFO] [stdout] 80 ~ //! for i in 1..prices.len() { [INFO] [stdout] 81 ~ //! sell[i] = max(sell[i - 1], buy[i - 1] + prices[i] - fee); [INFO] [stdout] 82 ~ //! buy[i] = max(buy[i - 1], sell[i - 1] - prices[i]); [INFO] [stdout] 83 ~ //! } [INFO] [stdout] 84 ~ //! sell[prices.len() - 1] [INFO] [stdout] 85 ~ //! } [INFO] [stdout] 86 ~ //!} [INFO] [stdout] 87 ~ //! ``` [INFO] [stdout] 88 ~ //! [INFO] [stdout] 89 ~ //! # Approach 3: Dynamic Programming [INFO] [stdout] 90 ~ //! [INFO] [stdout] 91 ~ //! * Time complexity: O(n) [INFO] [stdout] 92 ~ //! [INFO] [stdout] 93 ~ //! * Space complexity: O(n) [INFO] [stdout] 94 ~ //! [INFO] [stdout] 95 ~ //! * Runtime: 12 ms [INFO] [stdout] 96 ~ //! * Memory: 3.7 MB [INFO] [stdout] 97 ~ //! [INFO] [stdout] 98 ~ //! ```rust [INFO] [stdout] 99 ~ //! use std::cmp::max; [INFO] [stdout] 100 ~ //! [INFO] [stdout] 101 ~ //! impl Solution { [INFO] [stdout] 102 ~ //! pub fn max_profit(prices: Vec, fee: i32) -> i32 { [INFO] [stdout] 103 ~ //! if prices.len() < 2 || fee >= 50000 { return 0; } [INFO] [stdout] 104 ~ //! [INFO] [stdout] 105 ~ //! let mut cash = 0; [INFO] [stdout] 106 ~ //! let mut hold = -prices[0]; [INFO] [stdout] 107 ~ //! for i in 1..prices.len() { [INFO] [stdout] 108 ~ //! cash = max(cash, hold + prices[i] - fee); [INFO] [stdout] 109 ~ //! hold = max(hold, cash - prices[i]); [INFO] [stdout] 110 ~ //! } [INFO] [stdout] 111 ~ //! cash [INFO] [stdout] 112 ~ //! } [INFO] [stdout] 113 ~ //! } [INFO] [stdout] 114 ~ //! ``` [INFO] [stdout] 115 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0036_valid_sudoku/mod.rs:177:1 [INFO] [stdout] | [INFO] [stdout] 177 | / /// [INFO] [stdout] 178 | | [INFO] [stdout] | |_^ [INFO] [stdout] 179 | pub fn is_valid_sudoku(board: Vec>) -> bool { [INFO] [stdout] | ---------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = note: `#[warn(clippy::empty_line_after_doc_comments)]` on by default [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 59 ~ //! # Solutions [INFO] [stdout] 60 ~ //! [INFO] [stdout] 61 ~ //! # Approach 1: DFS [INFO] [stdout] 62 ~ //! [INFO] [stdout] 63 ~ //! * Time complexity: [INFO] [stdout] 64 ~ //! [INFO] [stdout] 65 ~ //! * Space complexity: [INFO] [stdout] 66 ~ //! [INFO] [stdout] 67 ~ //! * Runtime: 4 ms [INFO] [stdout] 68 ~ //! * Memory: 2.5 MB [INFO] [stdout] 69 ~ //! [INFO] [stdout] 70 ~ //! ```rust [INFO] [stdout] 71 ~ //! impl Solution { [INFO] [stdout] 72 ~ //! pub fn is_valid_sudoku(board: Vec>) -> bool { [INFO] [stdout] 73 ~ //! // 快速检索第i, j列, 第k宫的数字是否被占用 [INFO] [stdout] 74 ~ //! let mut line = [[false; 9]; 9]; // j [INFO] [stdout] 75 ~ //! let mut column = [[false; 9]; 9]; // i [INFO] [stdout] 76 ~ //! let mut ceil = [[false; 9]; 9]; // k [INFO] [stdout] 77 ~ //! let mut origin = [[false; 9]; 9]; // 原始数字位置 [INFO] [stdout] 78 ~ //! // 初始化 [INFO] [stdout] 79 ~ //! for row in 0..9 { [INFO] [stdout] 80 ~ //! for col in 0..9 { [INFO] [stdout] 81 ~ //! let num = match board[row][col].to_digit(10) { [INFO] [stdout] 82 ~ //! Some(n) => (n - 1) as usize, [INFO] [stdout] 83 ~ //! None => continue [INFO] [stdout] 84 ~ //! }; [INFO] [stdout] 85 ~ //! [INFO] [stdout] 86 ~ //! if line[row][num] || column[col][num] ||ceil[Self::ceil_k((row, col))][num] { return false; } [INFO] [stdout] 87 ~ //! line[row][num] = true; [INFO] [stdout] 88 ~ //! column[col][num] = true; [INFO] [stdout] 89 ~ //! origin[row][col] = true; [INFO] [stdout] 90 ~ //! ceil[Self::ceil_k((row, col))][num] = true; [INFO] [stdout] 91 ~ //! } [INFO] [stdout] 92 ~ //! } [INFO] [stdout] 93 ~ //! true [INFO] [stdout] 94 ~ //! } [INFO] [stdout] 95 ~ //! [INFO] [stdout] 96 ~ //! // 求出pos属于第几个ceil [INFO] [stdout] 97 ~ //! fn ceil_k(pos: (usize, usize)) -> usize { [INFO] [stdout] 98 ~ //! (pos.0 / 3) * 3 + pos.1 / 3 [INFO] [stdout] 99 ~ //! } [INFO] [stdout] 100 ~ //! } [INFO] [stdout] 101 ~ //! ``` [INFO] [stdout] 102 ~ //! [INFO] [stdout] 103 ~ //! # Approach 2: DFS [INFO] [stdout] 104 ~ //! [INFO] [stdout] 105 ~ //! * Time complexity: [INFO] [stdout] 106 ~ //! [INFO] [stdout] 107 ~ //! * Space complexity: [INFO] [stdout] 108 ~ //! [INFO] [stdout] 109 ~ //! * Runtime: 5 ms [INFO] [stdout] 110 ~ //! * Memory: 2.5 MB [INFO] [stdout] 111 ~ //! [INFO] [stdout] 112 ~ //! ```rust [INFO] [stdout] 113 ~ //! impl Solution { [INFO] [stdout] 114 ~ //! pub fn is_valid_sudoku(board: Vec>) -> bool { [INFO] [stdout] 115 ~ //! let mut table = vec![false; 9]; [INFO] [stdout] 116 ~ //! [INFO] [stdout] 117 ~ //! Solution::check_row(&board, &mut table) && [INFO] [stdout] 118 ~ //! Solution::check_col(&board, &mut table) && [INFO] [stdout] 119 ~ //! Solution::check_block(&board, &mut table) [INFO] [stdout] 120 ~ //! } [INFO] [stdout] 121 ~ //! [INFO] [stdout] 122 ~ //! pub fn check_row(board: &Vec>, table: &mut Vec) -> bool { [INFO] [stdout] 123 ~ //! // check row [INFO] [stdout] 124 ~ //! for row in board.iter() { [INFO] [stdout] 125 ~ //! for pos in 0..9 { table[pos] = false; } [INFO] [stdout] 126 ~ //! for col in row { [INFO] [stdout] 127 ~ //! match col.to_digit(10) { [INFO] [stdout] 128 ~ //! Some(n) => { [INFO] [stdout] 129 ~ //! if table[(n-1) as usize] { return false; } [INFO] [stdout] 130 ~ //! table[(n-1) as usize] = true; [INFO] [stdout] 131 ~ //! }, [INFO] [stdout] 132 ~ //! None => continue, [INFO] [stdout] 133 ~ //! } [INFO] [stdout] 134 ~ //! } [INFO] [stdout] 135 ~ //! } [INFO] [stdout] 136 ~ //! true [INFO] [stdout] 137 ~ //! } [INFO] [stdout] 138 ~ //! [INFO] [stdout] 139 ~ //! pub fn check_col(board: &Vec>, table: &mut Vec) -> bool { [INFO] [stdout] 140 ~ //! // check col [INFO] [stdout] 141 ~ //! for col in 0..9 { [INFO] [stdout] 142 ~ //! for pos in 0..9 { table[pos] = false; } [INFO] [stdout] 143 ~ //! for row in board.iter() { [INFO] [stdout] 144 ~ //! match row[col].to_digit(10) { [INFO] [stdout] 145 ~ //! Some(n) => { [INFO] [stdout] 146 ~ //! if table[(n-1) as usize] { return false; } [INFO] [stdout] 147 ~ //! table[(n-1) as usize] = true; [INFO] [stdout] 148 ~ //! }, [INFO] [stdout] 149 ~ //! None => continue, [INFO] [stdout] 150 ~ //! } [INFO] [stdout] 151 ~ //! } [INFO] [stdout] 152 ~ //! } [INFO] [stdout] 153 ~ //! true [INFO] [stdout] 154 ~ //! } [INFO] [stdout] 155 ~ //! [INFO] [stdout] 156 ~ //! pub fn check_block(board: &Vec>, table: &mut Vec) -> bool { [INFO] [stdout] 157 ~ //! // check 3 * 3 block [INFO] [stdout] 158 ~ //! for i in 0..3 { [INFO] [stdout] 159 ~ //! for j in 0..3 { [INFO] [stdout] 160 ~ //! for pos in 0..9 { table[pos] = false; } [INFO] [stdout] 161 ~ //! for row in 3 * i .. 3 * (i + 1) { [INFO] [stdout] 162 ~ //! for col in 3 * j .. 3 * (j + 1) { [INFO] [stdout] 163 ~ //! match board[row][col].to_digit(10) { [INFO] [stdout] 164 ~ //! Some(n) => { [INFO] [stdout] 165 ~ //! if table[(n-1) as usize] { return false; } [INFO] [stdout] 166 ~ //! table[(n-1) as usize] = true; [INFO] [stdout] 167 ~ //! }, [INFO] [stdout] 168 ~ //! None => continue, [INFO] [stdout] 169 ~ //! } [INFO] [stdout] 170 ~ //! } [INFO] [stdout] 171 ~ //! } [INFO] [stdout] 172 ~ //! } [INFO] [stdout] 173 ~ //! } [INFO] [stdout] 174 ~ //! true [INFO] [stdout] 175 ~ //! } [INFO] [stdout] 176 ~ //! } [INFO] [stdout] 177 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0037_sudoku_solver/mod.rs:159:1 [INFO] [stdout] | [INFO] [stdout] 159 | / /// [INFO] [stdout] 160 | | [INFO] [stdout] | |_^ [INFO] [stdout] 161 | pub fn solve_sudoku(board: &mut Vec>) { [INFO] [stdout] | ------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 29 ~ //! # Solutions [INFO] [stdout] 30 ~ //! [INFO] [stdout] 31 ~ //! # Approach 1: DFS [INFO] [stdout] 32 ~ //! [INFO] [stdout] 33 ~ //! * Time complexity: [INFO] [stdout] 34 ~ //! [INFO] [stdout] 35 ~ //! * Space complexity: [INFO] [stdout] 36 ~ //! [INFO] [stdout] 37 ~ //! * Runtime: 12 ms [INFO] [stdout] 38 ~ //! * Memory: 2.4 MB [INFO] [stdout] 39 ~ //! [INFO] [stdout] 40 ~ //! ```rust [INFO] [stdout] 41 ~ //! impl Solution { [INFO] [stdout] 42 ~ //! pub fn solve_sudoku(board: &mut Vec>) { [INFO] [stdout] 43 ~ //! if board.is_empty() { return; } [INFO] [stdout] 44 ~ //! Self::solve(board); [INFO] [stdout] 45 ~ //! } [INFO] [stdout] 46 ~ //! [INFO] [stdout] 47 ~ //! pub fn solve(board: &mut Vec>) -> bool { [INFO] [stdout] 48 ~ //! for row in 0..board.len() { [INFO] [stdout] 49 ~ //! for col in 0..board[row].len() { [INFO] [stdout] 50 ~ //! if board[row][col] != '.' { continue; } [INFO] [stdout] 51 ~ //! [INFO] [stdout] 52 ~ //! for c in "123456789".chars().collect::>() { [INFO] [stdout] 53 ~ //! if !Self::is_valid(&board, row, col, c) { continue; } [INFO] [stdout] 54 ~ //! [INFO] [stdout] 55 ~ //! board[row][col] = c; [INFO] [stdout] 56 ~ //! [INFO] [stdout] 57 ~ //! if Self::solve(board) { return true; } [INFO] [stdout] 58 ~ //! [INFO] [stdout] 59 ~ //! board[row][col] = '.'; [INFO] [stdout] 60 ~ //! } [INFO] [stdout] 61 ~ //! [INFO] [stdout] 62 ~ //! return false; [INFO] [stdout] 63 ~ //! } [INFO] [stdout] 64 ~ //! } [INFO] [stdout] 65 ~ //! return true; [INFO] [stdout] 66 ~ //! } [INFO] [stdout] 67 ~ //! [INFO] [stdout] 68 ~ //! pub fn is_valid(board: &Vec>, row: usize, col: usize, c: char) -> bool { [INFO] [stdout] 69 ~ //! for i in 0..9 { [INFO] [stdout] 70 ~ //! if board[row][i] != '.' && board[row][i] == c { return false; } // check row [INFO] [stdout] 71 ~ //! if board[i][col] != '.' && board[i][col] == c { return false; } // check col [INFO] [stdout] 72 ~ //! let block = board[(3 * (row as i32 / 3) + i as i32 / 3) as usize][(3 * (col as i32 / 3) + i as i32 % 3) as usize]; [INFO] [stdout] 73 ~ //! if block != '.' && block == c { return false; } // check 3 * 3 block; [INFO] [stdout] 74 ~ //! } [INFO] [stdout] 75 ~ //! true [INFO] [stdout] 76 ~ //! } [INFO] [stdout] 77 ~ //! } [INFO] [stdout] 78 ~ //! ``` [INFO] [stdout] 79 ~ //! [INFO] [stdout] 80 ~ //! # Approach 2: DFS [INFO] [stdout] 81 ~ //! [INFO] [stdout] 82 ~ //! * Time complexity: [INFO] [stdout] 83 ~ //! [INFO] [stdout] 84 ~ //! * Space complexity: [INFO] [stdout] 85 ~ //! [INFO] [stdout] 86 ~ //! * Runtime: 0 ms [INFO] [stdout] 87 ~ //! * Memory: 2.5 MB [INFO] [stdout] 88 ~ //! [INFO] [stdout] 89 ~ //! ```rust [INFO] [stdout] 90 ~ //! use std::char; [INFO] [stdout] 91 ~ //! [INFO] [stdout] 92 ~ //! impl Solution { [INFO] [stdout] 93 ~ //! pub fn solve_sudoku(board: &mut Vec>) { [INFO] [stdout] 94 ~ //! if board.is_empty() { return; } [INFO] [stdout] 95 ~ //! [INFO] [stdout] 96 ~ //! // 快速检索第i, j列, 第k宫的数字是否被占用 [INFO] [stdout] 97 ~ //! let mut lines = [[false; 9]; 9]; [INFO] [stdout] 98 ~ //! let mut columns = [[false; 9]; 9]; [INFO] [stdout] 99 ~ //! let mut ceils = [[false; 9]; 9]; [INFO] [stdout] 100 ~ //! let mut origins = [[false; 9]; 9]; [INFO] [stdout] 101 ~ //! [INFO] [stdout] 102 ~ //! // initialize lines columns ceils and origins [INFO] [stdout] 103 ~ //! for row in 0..9 { [INFO] [stdout] 104 ~ //! for col in 0..9 { [INFO] [stdout] 105 ~ //! let num = match board[row][col].to_digit(10) { [INFO] [stdout] 106 ~ //! Some(n) => (n - 1) as usize, [INFO] [stdout] 107 ~ //! None => continue, [INFO] [stdout] 108 ~ //! }; [INFO] [stdout] 109 ~ //! [INFO] [stdout] 110 ~ //! lines[row][num] = true; [INFO] [stdout] 111 ~ //! columns[col][num] = true; [INFO] [stdout] 112 ~ //! origins[row][col] = true; [INFO] [stdout] 113 ~ //! ceils[Self::ceil_pos((row, col))][num] = true; [INFO] [stdout] 114 ~ //! } [INFO] [stdout] 115 ~ //! } [INFO] [stdout] 116 ~ //! [INFO] [stdout] 117 ~ //! Self::solve(board, (0, 0), &mut lines, &mut columns, &mut ceils, &mut origins); [INFO] [stdout] 118 ~ //! } [INFO] [stdout] 119 ~ //! [INFO] [stdout] 120 ~ //! pub fn solve(board: &mut Vec>, [INFO] [stdout] 121 ~ //! (row, col): (usize, usize), [INFO] [stdout] 122 ~ //! lines: &mut[[bool; 9]; 9], [INFO] [stdout] 123 ~ //! columns: &mut[[bool; 9]; 9], [INFO] [stdout] 124 ~ //! ceils: &mut[[bool; 9]; 9], [INFO] [stdout] 125 ~ //! origins: &mut[[bool; 9]; 9]) -> bool { [INFO] [stdout] 126 ~ //! [INFO] [stdout] 127 ~ //! if row >= 9 { return true; } [INFO] [stdout] 128 ~ //! let next_pos = (row + (col + 1) / 9, (col + 1) % 9); [INFO] [stdout] 129 ~ //! if origins[row][col] { return Self::solve(board, next_pos, lines, columns, ceils, origins); } [INFO] [stdout] 130 ~ //! [INFO] [stdout] 131 ~ //! let mut flag = false; [INFO] [stdout] 132 ~ //! for num in 0..9 { [INFO] [stdout] 133 ~ //! let ceil = Self::ceil_pos((row, col)); [INFO] [stdout] 134 ~ //! if lines[row][num] || columns[col][num] || ceils[ceil][num] { continue; } [INFO] [stdout] 135 ~ //! [INFO] [stdout] 136 ~ //! // 数字num + 1没用过 [INFO] [stdout] 137 ~ //! lines[row][num] = true; [INFO] [stdout] 138 ~ //! columns[col][num] = true; [INFO] [stdout] 139 ~ //! ceils[ceil][num] = true; [INFO] [stdout] 140 ~ //! [INFO] [stdout] 141 ~ //! board[row][col] = char::from_digit(num as u32 + 1, 10).unwrap(); [INFO] [stdout] 142 ~ //! [INFO] [stdout] 143 ~ //! flag |= Self::solve(board, next_pos, lines, columns, ceils, origins); [INFO] [stdout] 144 ~ //! [INFO] [stdout] 145 ~ //! if flag { break; } // 已填数 OK [INFO] [stdout] 146 ~ //! lines[row][num] = false; [INFO] [stdout] 147 ~ //! columns[col][num] = false; [INFO] [stdout] 148 ~ //! ceils[ceil][num] = false; [INFO] [stdout] 149 ~ //! } [INFO] [stdout] 150 ~ //! [INFO] [stdout] 151 ~ //! flag [INFO] [stdout] 152 ~ //! } [INFO] [stdout] 153 ~ //! [INFO] [stdout] 154 ~ //! // 求出pos属于第几个ceil [INFO] [stdout] 155 ~ //! pub fn ceil_pos(pos: (usize, usize)) -> usize { [INFO] [stdout] 156 ~ //! (pos.0 / 3) * 3 + pos.1 / 3 [INFO] [stdout] 157 ~ //! } [INFO] [stdout] 158 ~ //! } [INFO] [stdout] 159 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0051_n_queens/mod.rs:205:1 [INFO] [stdout] | [INFO] [stdout] 205 | / /// [INFO] [stdout] 206 | | [INFO] [stdout] | |_^ [INFO] [stdout] 207 | pub fn solve_n_queens(n: i32) -> Vec> { [INFO] [stdout] | --------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 32 ~ //! # Solutions [INFO] [stdout] 33 ~ //! [INFO] [stdout] 34 ~ //! # Approach 1: DFS [INFO] [stdout] 35 ~ //! [INFO] [stdout] 36 ~ //! * Time complexity: [INFO] [stdout] 37 ~ //! [INFO] [stdout] 38 ~ //! * Space complexity: [INFO] [stdout] 39 ~ //! [INFO] [stdout] 40 ~ //! * Runtime: 4 ms [INFO] [stdout] 41 ~ //! * Memory: 2.8 MB [INFO] [stdout] 42 ~ //! [INFO] [stdout] 43 ~ //! ```rust [INFO] [stdout] 44 ~ //! impl Solution { [INFO] [stdout] 45 ~ //! pub fn solve_n_queens(n: i32) -> Vec> { [INFO] [stdout] 46 ~ //! if n < 1 { return vec![]; } [INFO] [stdout] 47 ~ //! [INFO] [stdout] 48 ~ //! let mut result = vec![]; [INFO] [stdout] 49 ~ //! let mut current_queens = vec![]; [INFO] [stdout] 50 ~ //! let mut cols = vec![]; [INFO] [stdout] 51 ~ //! let mut xy_sum = vec![]; [INFO] [stdout] 52 ~ //! let mut xy_sub = vec![]; [INFO] [stdout] 53 ~ //! let row = 0; [INFO] [stdout] 54 ~ //! [INFO] [stdout] 55 ~ //! Self::_dfs(n, &mut result, &mut current_queens, row, &mut cols, &mut xy_sum, &mut xy_sub); [INFO] [stdout] 56 ~ //! [INFO] [stdout] 57 ~ //! result [INFO] [stdout] 58 ~ //! } [INFO] [stdout] 59 ~ //! [INFO] [stdout] 60 ~ //! pub fn _dfs( [INFO] [stdout] 61 ~ //! n: i32, [INFO] [stdout] 62 ~ //! result: &mut Vec>, [INFO] [stdout] 63 ~ //! current_queens: &mut Vec, [INFO] [stdout] 64 ~ //! row: i32, [INFO] [stdout] 65 ~ //! cols: &mut Vec, [INFO] [stdout] 66 ~ //! xy_sum: &mut Vec, [INFO] [stdout] 67 ~ //! xy_sub: &mut Vec [INFO] [stdout] 68 ~ //! ) { [INFO] [stdout] 69 ~ //! if row >= n { [INFO] [stdout] 70 ~ //! result.push(Self::matrix(current_queens, n)); [INFO] [stdout] 71 ~ //! return; [INFO] [stdout] 72 ~ //! } [INFO] [stdout] 73 ~ //! [INFO] [stdout] 74 ~ //! for col in 0..n { [INFO] [stdout] 75 ~ //! if cols.contains(&col) || xy_sum.contains(&(row + col)) || xy_sub.contains(&(row - col)) { [INFO] [stdout] 76 ~ //! continue; [INFO] [stdout] 77 ~ //! } [INFO] [stdout] 78 ~ //! [INFO] [stdout] 79 ~ //! cols.push(col); [INFO] [stdout] 80 ~ //! xy_sum.push(row + col); [INFO] [stdout] 81 ~ //! xy_sub.push(row - col); [INFO] [stdout] 82 ~ //! Self::_dfs(n, result, &mut [current_queens.clone(), [col].to_vec()].concat(), row + 1, cols, xy_sum, xy_sub); [INFO] [stdout] 83 ~ //! [INFO] [stdout] 84 ~ //! cols.retain(|&x| x != col); [INFO] [stdout] 85 ~ //! xy_sum.retain(|&x| x != (row + col)); [INFO] [stdout] 86 ~ //! xy_sub.retain(|&x| x != (row - col)); [INFO] [stdout] 87 ~ //! } [INFO] [stdout] 88 ~ //! } [INFO] [stdout] 89 ~ //! [INFO] [stdout] 90 ~ //! pub fn matrix(queens: &mut Vec, n: i32) -> Vec { [INFO] [stdout] 91 ~ //! let mut arr = vec![]; [INFO] [stdout] 92 ~ //! let queens_len = queens.len(); [INFO] [stdout] 93 ~ //! for i in queens { [INFO] [stdout] 94 ~ //! let mut char_vector = vec!['.'; n as usize]; [INFO] [stdout] 95 ~ //! char_vector[*i as usize] = 'Q'; [INFO] [stdout] 96 ~ //! let str: String = char_vector.into_iter().collect(); [INFO] [stdout] 97 ~ //! arr.push(str); [INFO] [stdout] 98 ~ //! } [INFO] [stdout] 99 ~ //! [INFO] [stdout] 100 ~ //! arr [INFO] [stdout] 101 ~ //! } [INFO] [stdout] 102 ~ //! } [INFO] [stdout] 103 ~ //! ``` [INFO] [stdout] 104 ~ //! [INFO] [stdout] 105 ~ //! # Approach 2: DFS [INFO] [stdout] 106 ~ //! [INFO] [stdout] 107 ~ //! * Time complexity: [INFO] [stdout] 108 ~ //! [INFO] [stdout] 109 ~ //! * Space complexity: [INFO] [stdout] 110 ~ //! [INFO] [stdout] 111 ~ //! * Runtime: 0 ms [INFO] [stdout] 112 ~ //! * Memory: 2.8 MB [INFO] [stdout] 113 ~ //! [INFO] [stdout] 114 ~ //! ```rust [INFO] [stdout] 115 ~ //! impl Solution { [INFO] [stdout] 116 ~ //! pub fn solve_n_queens(n: i32) -> Vec> { [INFO] [stdout] 117 ~ //! let mut board = vec![vec!['.'; n as usize]; n as usize]; [INFO] [stdout] 118 ~ //! let mut solution = vec![]; [INFO] [stdout] 119 ~ //! Self::schedule_queens(&mut board, &mut solution, n as usize, 0); [INFO] [stdout] 120 ~ //! solution [INFO] [stdout] 121 ~ //! } [INFO] [stdout] 122 ~ //! [INFO] [stdout] 123 ~ //! fn schedule_queens(board: &mut Vec>, solution: &mut Vec>, len: usize, row: usize) { [INFO] [stdout] 124 ~ //! for col in 0..len { [INFO] [stdout] 125 ~ //! if !Self::collision(&board, len, row, col) { [INFO] [stdout] 126 ~ //! board[row][col] = 'Q'; [INFO] [stdout] 127 ~ //! if row == len - 1 { [INFO] [stdout] 128 ~ //! solution.push(board.iter().map(|vec| vec.iter().collect()).collect()); [INFO] [stdout] 129 ~ //! } else { [INFO] [stdout] 130 ~ //! Self::schedule_queens(board, solution, len, row+1); [INFO] [stdout] 131 ~ //! } [INFO] [stdout] 132 ~ //! board[row][col] = '.'; [INFO] [stdout] 133 ~ //! } [INFO] [stdout] 134 ~ //! } [INFO] [stdout] 135 ~ //! } [INFO] [stdout] 136 ~ //! [INFO] [stdout] 137 ~ //! #[inline(always)] [INFO] [stdout] 138 ~ //! fn collision(board: &Vec>, len: usize, row: usize, col: usize) -> bool { [INFO] [stdout] 139 ~ //! for i in 0..row { [INFO] [stdout] 140 ~ //! if board[i][col] == 'Q' { return true } [INFO] [stdout] 141 ~ //! } [INFO] [stdout] 142 ~ //! let (mut i, mut j) = (row as i32 - 1, col as i32 - 1); [INFO] [stdout] 143 ~ //! while i >= 0 && j >= 0 { [INFO] [stdout] 144 ~ //! if board[i as usize][j as usize] == 'Q' { return true } [INFO] [stdout] 145 ~ //! i -= 1; j -= 1; [INFO] [stdout] 146 ~ //! } [INFO] [stdout] 147 ~ //! let (mut i, mut j) = (row as i32 - 1, col as i32 + 1); [INFO] [stdout] 148 ~ //! while i >= 0 && j < len as i32 { [INFO] [stdout] 149 ~ //! if board[i as usize][j as usize] == 'Q' { return true} [INFO] [stdout] 150 ~ //! i -= 1; j += 1; [INFO] [stdout] 151 ~ //! } [INFO] [stdout] 152 ~ //! false [INFO] [stdout] 153 ~ //! } [INFO] [stdout] 154 ~ //! } [INFO] [stdout] 155 ~ //! ``` [INFO] [stdout] 156 ~ //! [INFO] [stdout] 157 ~ //! # Approach 3: BitWies [INFO] [stdout] 158 ~ //! [INFO] [stdout] 159 ~ //! * Time complexity: [INFO] [stdout] 160 ~ //! [INFO] [stdout] 161 ~ //! * Space complexity: [INFO] [stdout] 162 ~ //! [INFO] [stdout] 163 ~ //! * Runtime: 0 ms [INFO] [stdout] 164 ~ //! * Memory: 2.8 MB [INFO] [stdout] 165 ~ //! [INFO] [stdout] 166 ~ //! ```rust [INFO] [stdout] 167 ~ //! impl Solution { [INFO] [stdout] 168 ~ //! pub fn solve_n_queens(n: i32) -> Vec> { [INFO] [stdout] 169 ~ //! if n < 1 { return vec! []; } [INFO] [stdout] 170 ~ //! [INFO] [stdout] 171 ~ //! let mut board = vec![vec!['.'; n as usize]; n as usize]; [INFO] [stdout] 172 ~ //! let mut result = vec![]; [INFO] [stdout] 173 ~ //! Self::_dfs(&mut board, &mut result, n, 0, 0, 0, 0); [INFO] [stdout] 174 ~ //! result [INFO] [stdout] 175 ~ //! } [INFO] [stdout] 176 ~ //! pub fn _dfs( [INFO] [stdout] 177 ~ //! board: &mut Vec>, [INFO] [stdout] 178 ~ //! result: &mut Vec>, [INFO] [stdout] 179 ~ //! n: i32, [INFO] [stdout] 180 ~ //! row: i32, [INFO] [stdout] 181 ~ //! col: i32, [INFO] [stdout] 182 ~ //! xy_sum: i32, [INFO] [stdout] 183 ~ //! xy_sub: i32 [INFO] [stdout] 184 ~ //! ) { [INFO] [stdout] 185 ~ //! if row >= n { [INFO] [stdout] 186 ~ //! result.push(board.iter().map(|vec| vec.iter().collect()).collect()); [INFO] [stdout] 187 ~ //! return; [INFO] [stdout] 188 ~ //! } [INFO] [stdout] 189 ~ //! [INFO] [stdout] 190 ~ //! // bits = 2^t0 + 2^t1 + 2^t2 + ... (t0 < t1 < t2 < ...) [INFO] [stdout] 191 ~ //! let mut bits = (!(col | xy_sum | xy_sub)) & ((1 << n) - 1); [INFO] [stdout] 192 ~ //! while bits != 0 { [INFO] [stdout] 193 ~ //! // p = 2^t0, so log2(p) = t0, t0 is the position to puts Q [INFO] [stdout] 194 ~ //! let p = bits & -bits; [INFO] [stdout] 195 ~ //! board[row as usize][((p as f32).log2()) as usize] = 'Q'; // puts Q in board[row][t0] [INFO] [stdout] 196 ~ //! Self::_dfs(board, result, n, row + 1, col | p, (xy_sum | p) << 1, (xy_sub | p) >> 1); // row + 1 and next recursion [INFO] [stdout] 197 ~ //! board[row as usize][((p as f32).log2())as usize] = '.'; [INFO] [stdout] 198 ~ //! bits = bits & (bits - 1); [INFO] [stdout] 199 ~ //! } [INFO] [stdout] 200 ~ //! } [INFO] [stdout] 201 ~ //! } [INFO] [stdout] 202 ~ //! ``` [INFO] [stdout] 203 ~ //! Reference [INFO] [stdout] 204 ~ //! * [LeetCode51](http://www.voidcn.com/article/p-wsavmpbh-bpn.html) [INFO] [stdout] 205 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0052_n_queens_ii/mod.rs:170:1 [INFO] [stdout] | [INFO] [stdout] 170 | / /// * [LeetCode52](https://www.cnblogs.com/albert1017/archive/2013/01/15/2860973.html) [INFO] [stdout] 171 | | [INFO] [stdout] | |_^ [INFO] [stdout] 172 | pub fn total_n_queens(n: i32) -> i32 { [INFO] [stdout] | --------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 31 ~ //! # Solutions [INFO] [stdout] 32 ~ //! [INFO] [stdout] 33 ~ //! # Approach 1: DFS [INFO] [stdout] 34 ~ //! [INFO] [stdout] 35 ~ //! * Time complexity: [INFO] [stdout] 36 ~ //! [INFO] [stdout] 37 ~ //! * Space complexity: [INFO] [stdout] 38 ~ //! [INFO] [stdout] 39 ~ //! * Runtime: 4 ms [INFO] [stdout] 40 ~ //! * Memory: 2.8 MB [INFO] [stdout] 41 ~ //! [INFO] [stdout] 42 ~ //! ```rust [INFO] [stdout] 43 ~ //! impl Solution { [INFO] [stdout] 44 ~ //! pub fn total_n_queens(n: i32) -> i32 { [INFO] [stdout] 45 ~ //! if n < 1 { return 0; } [INFO] [stdout] 46 ~ //! [INFO] [stdout] 47 ~ //! let mut result = 0; [INFO] [stdout] 48 ~ //! let mut cols = vec![]; [INFO] [stdout] 49 ~ //! let mut xy_sum = vec![]; [INFO] [stdout] 50 ~ //! let mut xy_sub = vec![]; [INFO] [stdout] 51 ~ //! let row = 0; [INFO] [stdout] 52 ~ //! [INFO] [stdout] 53 ~ //! Self::_dfs(n, &mut result, row, &mut cols, &mut xy_sum, &mut xy_sub); [INFO] [stdout] 54 ~ //! [INFO] [stdout] 55 ~ //! result [INFO] [stdout] 56 ~ //! } [INFO] [stdout] 57 ~ //! [INFO] [stdout] 58 ~ //! pub fn _dfs(n: i32, result: &mut i32, row: i32, cols: &mut Vec, xy_sum: &mut Vec, xy_sub: &mut Vec) { [INFO] [stdout] 59 ~ //! if row >= n { [INFO] [stdout] 60 ~ //! *result += 1; [INFO] [stdout] 61 ~ //! return; [INFO] [stdout] 62 ~ //! } [INFO] [stdout] 63 ~ //! [INFO] [stdout] 64 ~ //! for col in 0..n { [INFO] [stdout] 65 ~ //! if cols.contains(&col) || xy_sum.contains(&(row + col)) || xy_sub.contains(&(row - col)) { [INFO] [stdout] 66 ~ //! continue; [INFO] [stdout] 67 ~ //! } [INFO] [stdout] 68 ~ //! [INFO] [stdout] 69 ~ //! cols.push(col); [INFO] [stdout] 70 ~ //! xy_sum.push(row + col); [INFO] [stdout] 71 ~ //! xy_sub.push(row - col); [INFO] [stdout] 72 ~ //! Self::_dfs(n, result, row + 1, cols, xy_sum, xy_sub); [INFO] [stdout] 73 ~ //! [INFO] [stdout] 74 ~ //! cols.retain(|&x| x != col); [INFO] [stdout] 75 ~ //! xy_sum.retain(|&x| x != (row + col)); [INFO] [stdout] 76 ~ //! xy_sub.retain(|&x| x != (row - col)); [INFO] [stdout] 77 ~ //! } [INFO] [stdout] 78 ~ //! } [INFO] [stdout] 79 ~ //! } [INFO] [stdout] 80 ~ //! ``` [INFO] [stdout] 81 ~ //! [INFO] [stdout] 82 ~ //! # Approach 2: DFS [INFO] [stdout] 83 ~ //! [INFO] [stdout] 84 ~ //! * Time complexity: [INFO] [stdout] 85 ~ //! [INFO] [stdout] 86 ~ //! * Space complexity: [INFO] [stdout] 87 ~ //! [INFO] [stdout] 88 ~ //! * Runtime: 0 ms [INFO] [stdout] 89 ~ //! * Memory: 2.8 MB [INFO] [stdout] 90 ~ //! [INFO] [stdout] 91 ~ //! ```rust [INFO] [stdout] 92 ~ //! impl Solution { [INFO] [stdout] 93 ~ //! pub fn total_n_queens(n: i32) -> Vec> { [INFO] [stdout] 94 ~ //! let mut board = vec![vec!['.'; n as usize]; n as usize]; [INFO] [stdout] 95 ~ //! let mut num = 0; [INFO] [stdout] 96 ~ //! Self::schedule_queens(&mut board, &mut num, n as usize, 0); [INFO] [stdout] 97 ~ //! solution [INFO] [stdout] 98 ~ //! } [INFO] [stdout] 99 ~ //! [INFO] [stdout] 100 ~ //! fn schedule_queens(board: &mut Vec>, num &mut i32, len: usize, row: usize) { [INFO] [stdout] 101 ~ //! for col in 0..len { [INFO] [stdout] 102 ~ //! if !Self::collision(&board, len, row, col) { [INFO] [stdout] 103 ~ //! board[row][col] = 'Q'; [INFO] [stdout] 104 ~ //! if row == len - 1 { [INFO] [stdout] 105 ~ //! *num += 1; [INFO] [stdout] 106 ~ //! } else { [INFO] [stdout] 107 ~ //! Self::schedule_queens(board, solution, len, row+1); [INFO] [stdout] 108 ~ //! } [INFO] [stdout] 109 ~ //! board[row][col] = '.'; [INFO] [stdout] 110 ~ //! } [INFO] [stdout] 111 ~ //! } [INFO] [stdout] 112 ~ //! } [INFO] [stdout] 113 ~ //! [INFO] [stdout] 114 ~ //! #[inline(always)] [INFO] [stdout] 115 ~ //! fn collision(board: &Vec>, len: usize, row: usize, col: usize) -> bool { [INFO] [stdout] 116 ~ //! for i in 0..row { [INFO] [stdout] 117 ~ //! if board[i][col] == 'Q' { return true } [INFO] [stdout] 118 ~ //! } [INFO] [stdout] 119 ~ //! let (mut i, mut j) = (row as i32 - 1, col as i32 - 1); [INFO] [stdout] 120 ~ //! while i >= 0 && j >= 0 { [INFO] [stdout] 121 ~ //! if board[i as usize][j as usize] == 'Q' { return true } [INFO] [stdout] 122 ~ //! i -= 1; j -= 1; [INFO] [stdout] 123 ~ //! } [INFO] [stdout] 124 ~ //! let (mut i, mut j) = (row as i32 - 1, col as i32 + 1); [INFO] [stdout] 125 ~ //! while i >= 0 && j < len as i32 { [INFO] [stdout] 126 ~ //! if board[i as usize][j as usize] == 'Q' { return true} [INFO] [stdout] 127 ~ //! i -= 1; j += 1; [INFO] [stdout] 128 ~ //! } [INFO] [stdout] 129 ~ //! false [INFO] [stdout] 130 ~ //! } [INFO] [stdout] 131 ~ //! } [INFO] [stdout] 132 ~ //! ``` [INFO] [stdout] 133 ~ //! [INFO] [stdout] 134 ~ //! # Approach 3: BitWise [INFO] [stdout] 135 ~ //! [INFO] [stdout] 136 ~ //! * Time complexity: [INFO] [stdout] 137 ~ //! [INFO] [stdout] 138 ~ //! * Space complexity: [INFO] [stdout] 139 ~ //! [INFO] [stdout] 140 ~ //! * Runtime: 0 ms [INFO] [stdout] 141 ~ //! * Memory: 2.3 MB [INFO] [stdout] 142 ~ //! [INFO] [stdout] 143 ~ //! ```rust [INFO] [stdout] 144 ~ //! impl Solution { [INFO] [stdout] 145 ~ //! pub fn total_n_queens(n: i32) -> i32 { [INFO] [stdout] 146 ~ //! if n < 1 { return 0; } [INFO] [stdout] 147 ~ //! [INFO] [stdout] 148 ~ //! let mut result = 0; [INFO] [stdout] 149 ~ //! Self::_dfs(n, &mut result, 0, 0, 0, 0); [INFO] [stdout] 150 ~ //! result [INFO] [stdout] 151 ~ //! } [INFO] [stdout] 152 ~ //! [INFO] [stdout] 153 ~ //! pub fn _dfs(n: i32, result: &mut i32, row: i32, col: i32, pie: i32, na: i32) { [INFO] [stdout] 154 ~ //! if row >= n { [INFO] [stdout] 155 ~ //! *result += 1; [INFO] [stdout] 156 ~ //! return; [INFO] [stdout] 157 ~ //! } [INFO] [stdout] 158 ~ //! [INFO] [stdout] 159 ~ //! let mut bits = (!(col | pie | na)) & ((1 << n) - 1); [INFO] [stdout] 160 ~ //! while bits != 0 { [INFO] [stdout] 161 ~ //! let p = bits & -bits; [INFO] [stdout] 162 ~ //! Self::_dfs(n, result, row + 1, col | p, (pie | p) << 1, (na | p) >> 1); [INFO] [stdout] 163 ~ //! bits = bits & (bits - 1); [INFO] [stdout] 164 ~ //! } [INFO] [stdout] 165 ~ //! } [INFO] [stdout] 166 ~ //! [INFO] [stdout] 167 ~ //! ``` [INFO] [stdout] 168 ~ //! Reference [INFO] [stdout] 169 ~ //! * [LeetCode52](https://lichangke.github.io/2019/04/18/LeetCode-52-N%E7%9A%87%E5%90%8E-II(N-Queens-II)/) [INFO] [stdout] 170 ~ //! * [LeetCode52](https://www.cnblogs.com/albert1017/archive/2013/01/15/2860973.html) [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0072_edit_distance/mod.rs:116:1 [INFO] [stdout] | [INFO] [stdout] 116 | / /// [INFO] [stdout] 117 | | [INFO] [stdout] | |_^ [INFO] [stdout] 118 | pub fn min_distance(word1: String, word2: String) -> i32 { [INFO] [stdout] | ------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 35 ~ //! # Solutions [INFO] [stdout] 36 ~ //! [INFO] [stdout] 37 ~ //! # Approach 1: Dynamic Programming [INFO] [stdout] 38 ~ //! [INFO] [stdout] 39 ~ //! * Time complexity: O(m*n) [INFO] [stdout] 40 ~ //! [INFO] [stdout] 41 ~ //! * Space complexity: O(m*n) [INFO] [stdout] 42 ~ //! [INFO] [stdout] 43 ~ //! * Runtime: 4 ms [INFO] [stdout] 44 ~ //! * Memory: 4.5 MB [INFO] [stdout] 45 ~ //! [INFO] [stdout] 46 ~ //! ```rust [INFO] [stdout] 47 ~ //! impl Solution { [INFO] [stdout] 48 ~ //! pub fn min_distance(word1: String, word2: String) -> i32 { [INFO] [stdout] 49 ~ //! let word1_bytes = word1.into_bytes(); [INFO] [stdout] 50 ~ //! let word2_bytes = word2.into_bytes(); [INFO] [stdout] 51 ~ //! let m = word1_bytes.len(); [INFO] [stdout] 52 ~ //! let n = word2_bytes.len(); [INFO] [stdout] 53 ~ //! let mut dp = vec![vec![0; n + 1]; m + 1]; [INFO] [stdout] 54 ~ //! [INFO] [stdout] 55 ~ //! // number of deletions to reach word2[0] [INFO] [stdout] 56 ~ //! for i in 0..=m { dp[i][0] = i; } [INFO] [stdout] 57 ~ //! // to construct word2[j] just with word1[0] need to j insertions [INFO] [stdout] 58 ~ //! for j in 0..=n { dp[0][j] = j; } [INFO] [stdout] 59 ~ //! [INFO] [stdout] 60 ~ //! for i in 1..=m { [INFO] [stdout] 61 ~ //! for j in 1..=n { [INFO] [stdout] 62 ~ //! // we can obtain word2[0..j] from word1[0..i] either by [INFO] [stdout] 63 ~ //! // deleting the ith charactor. knowing eg: dp[i - 1][j] [INFO] [stdout] 64 ~ //! // inserting the jth charactor. knowing eg: dp[i][j - 1] [INFO] [stdout] 65 ~ //! // or replate ith charactor with jth charactor. knowing eg: dp[i - 1][j - 1] [INFO] [stdout] 66 ~ //! dp[i][j] = (dp[i - 1][j - 1] + (word1_bytes[i - 1] != word2_bytes[j - 1]) as usize) [INFO] [stdout] 67 ~ //! .min(dp[i - 1][j] + 1) [INFO] [stdout] 68 ~ //! .min(dp[i][j - 1] + 1); [INFO] [stdout] 69 ~ //! } [INFO] [stdout] 70 ~ //! } [INFO] [stdout] 71 ~ //! dp[m][n] as i32 [INFO] [stdout] 72 ~ //! } [INFO] [stdout] 73 ~ //! } [INFO] [stdout] 74 ~ //! ``` [INFO] [stdout] 75 ~ //! [INFO] [stdout] 76 ~ //! # Approach 2: Dynamic Programming [INFO] [stdout] 77 ~ //! [INFO] [stdout] 78 ~ //! * Time complexity: O(m*n) [INFO] [stdout] 79 ~ //! [INFO] [stdout] 80 ~ //! * Space complexity: O(m*n) [INFO] [stdout] 81 ~ //! [INFO] [stdout] 82 ~ //! * Runtime: 4 ms [INFO] [stdout] 83 ~ //! * Memory: 4.5 MB [INFO] [stdout] 84 ~ //! [INFO] [stdout] 85 ~ //! ```rust [INFO] [stdout] 86 ~ //! impl Solution { [INFO] [stdout] 87 ~ //! pub fn min_distance(word1: String, word2: String) -> i32 { [INFO] [stdout] 88 ~ //! let word1_bytes = word1.into_bytes(); [INFO] [stdout] 89 ~ //! let word2_bytes = word2.into_bytes(); [INFO] [stdout] 90 ~ //! let m = word1_bytes.len(); [INFO] [stdout] 91 ~ //! let n = word2_bytes.len(); [INFO] [stdout] 92 ~ //! let mut dp = vec![vec![0; n + 1]; m + 1]; [INFO] [stdout] 93 ~ //! [INFO] [stdout] 94 ~ //! // number of deletions to reach word2[0] [INFO] [stdout] 95 ~ //! for i in 0..=m { dp[i][0] = i; } [INFO] [stdout] 96 ~ //! // to construct word2[j] just with word1[0] need to j insertions [INFO] [stdout] 97 ~ //! for j in 0..=n { dp[0][j] = j; } [INFO] [stdout] 98 ~ //! [INFO] [stdout] 99 ~ //! for i in 1..=m { [INFO] [stdout] 100 ~ //! for j in 1..=n { [INFO] [stdout] 101 ~ //! if word1_bytes[i - 1] == word2_bytes[j - 1] { [INFO] [stdout] 102 ~ //! dp[i][j] = dp[i - 1][j - 1]; [INFO] [stdout] 103 ~ //! } else { [INFO] [stdout] 104 ~ //! // we can obtain word2[0..j] from word1[0..i] either by [INFO] [stdout] 105 ~ //! // deleting the ith charactor. knowing eg: dp[i - 1][j] [INFO] [stdout] 106 ~ //! // inserting the jth charactor. knowing eg: dp[i][j - 1] [INFO] [stdout] 107 ~ //! // or replate ith charactor with jth charactor. knowing eg: dp[i - 1][j - 1] [INFO] [stdout] 108 ~ //! dp[i][j] = dp[i - 1][j].min(dp[i][j - 1]).min(dp[i - 1][j - 1]) + 1; [INFO] [stdout] 109 ~ //! } [INFO] [stdout] 110 ~ //! } [INFO] [stdout] 111 ~ //! } [INFO] [stdout] 112 ~ //! dp[m][n] as i32 [INFO] [stdout] 113 ~ //! } [INFO] [stdout] 114 ~ //! } [INFO] [stdout] 115 ~ //! ``` [INFO] [stdout] 116 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0200_number_of_islands/mod.rs:169:1 [INFO] [stdout] | [INFO] [stdout] 169 | / /// [INFO] [stdout] 170 | | [INFO] [stdout] | |_^ [INFO] [stdout] 171 | pub fn num_islands(grid: Vec>) -> i32 { [INFO] [stdout] | ------------------ the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 30 ~ //! # Solutions [INFO] [stdout] 31 ~ //! [INFO] [stdout] 32 ~ //! # Approach 1: Union Find [INFO] [stdout] 33 ~ //! [INFO] [stdout] 34 ~ //! * Time complexity: O(m*n) [INFO] [stdout] 35 ~ //! [INFO] [stdout] 36 ~ //! * Space complexity: O(m*n) [INFO] [stdout] 37 ~ //! [INFO] [stdout] 38 ~ //! * Runtime: 4 ms [INFO] [stdout] 39 ~ //! * Memory: 4.6 MB [INFO] [stdout] 40 ~ //! [INFO] [stdout] 41 ~ //! ```rust [INFO] [stdout] 42 ~ //! struct UnionFind { [INFO] [stdout] 43 ~ //! parents: Vec, [INFO] [stdout] 44 ~ //! count: i32, [INFO] [stdout] 45 ~ //! rank: Vec, [INFO] [stdout] 46 ~ //! } [INFO] [stdout] 47 ~ //! [INFO] [stdout] 48 ~ //! impl UnionFind { [INFO] [stdout] 49 ~ //! fn new(grid: &Vec>) -> Self { [INFO] [stdout] 50 ~ //! let m = grid.len(); [INFO] [stdout] 51 ~ //! let n = grid[0].len(); [INFO] [stdout] 52 ~ //! let mut count = 0; [INFO] [stdout] 53 ~ //! let mut parents = vec![-1; m * n]; [INFO] [stdout] 54 ~ //! let rank = vec![0; m * n]; [INFO] [stdout] 55 ~ //! for i in 0..m { [INFO] [stdout] 56 ~ //! for j in 0..n { [INFO] [stdout] 57 ~ //! if grid[i][j] == '1' { [INFO] [stdout] 58 ~ //! parents[i * n + j] = (i * n + j) as i32; [INFO] [stdout] 59 ~ //! count += 1; [INFO] [stdout] 60 ~ //! } [INFO] [stdout] 61 ~ //! } [INFO] [stdout] 62 ~ //! } [INFO] [stdout] 63 ~ //! UnionFind { parents: parents, count: count, rank: rank } [INFO] [stdout] 64 ~ //! } [INFO] [stdout] 65 ~ //! [INFO] [stdout] 66 ~ //! fn find(&mut self, i: i32) -> i32 { [INFO] [stdout] 67 ~ //! if self.parents[i as usize] != i { [INFO] [stdout] 68 ~ //! self.parents[i as usize] = self.find(self.parents[i as usize]) [INFO] [stdout] 69 ~ //! }; [INFO] [stdout] 70 ~ //! self.parents[i as usize] [INFO] [stdout] 71 ~ //! } [INFO] [stdout] 72 ~ //! [INFO] [stdout] 73 ~ //! fn union(&mut self, x: i32, y: i32) -> i32 { [INFO] [stdout] 74 ~ //! let x_parent = self.find(x); [INFO] [stdout] 75 ~ //! let y_parent = self.find(y); [INFO] [stdout] 76 ~ //! [INFO] [stdout] 77 ~ //! if x_parent == y_parent { return self.count; } [INFO] [stdout] 78 ~ //! [INFO] [stdout] 79 ~ //! if self.rank[x_parent as usize] < self.rank[y_parent as usize] { [INFO] [stdout] 80 ~ //! self.parents[x_parent as usize] = y_parent; [INFO] [stdout] 81 ~ //! } else if self.rank[x_parent as usize] > self.rank[y_parent as usize] { [INFO] [stdout] 82 ~ //! self.parents[y_parent as usize] = x_parent; [INFO] [stdout] 83 ~ //! } else { [INFO] [stdout] 84 ~ //! self.parents[y_parent as usize] = x_parent; [INFO] [stdout] 85 ~ //! self.rank[y_parent as usize] += 1; [INFO] [stdout] 86 ~ //! } [INFO] [stdout] 87 ~ //! self.count -= 1; [INFO] [stdout] 88 ~ //! [INFO] [stdout] 89 ~ //! self.count [INFO] [stdout] 90 ~ //! } [INFO] [stdout] 91 ~ //! } [INFO] [stdout] 92 ~ //! [INFO] [stdout] 93 ~ //! impl Solution { [INFO] [stdout] 94 ~ //! pub fn num_islands(grid: Vec>) -> i32 { [INFO] [stdout] 95 ~ //! if grid.is_empty() { return 0; } [INFO] [stdout] 96 ~ //! [INFO] [stdout] 97 ~ //! let directions: Vec<(i32, i32)> = vec![(-1, 0), (1, 0), (0, -1), (0, 1)]; [INFO] [stdout] 98 ~ //! let (m, n) = (grid.len(), grid[0].len()); [INFO] [stdout] 99 ~ //! let mut uf = UnionFind::new(&grid); [INFO] [stdout] 100 ~ //! [INFO] [stdout] 101 ~ //! for i in 0..m { [INFO] [stdout] 102 ~ //! for j in 0..n { [INFO] [stdout] 103 ~ //! if grid[i][j] == '0' { continue; } [INFO] [stdout] 104 ~ //! [INFO] [stdout] 105 ~ //! for d in &directions { [INFO] [stdout] 106 ~ //! let (dr, dc) = (i as i32 + d.0, j as i32 + d.1); [INFO] [stdout] 107 ~ //! if dr >= 0 && [INFO] [stdout] 108 ~ //! dc >= 0 && [INFO] [stdout] 109 ~ //! dr < m as i32 && [INFO] [stdout] 110 ~ //! dc < n as i32 && [INFO] [stdout] 111 ~ //! grid[dr as usize][dc as usize] == '1' { [INFO] [stdout] 112 ~ //! uf.union((i * n + j) as i32, dr * n as i32 + dc); [INFO] [stdout] 113 ~ //! } [INFO] [stdout] 114 ~ //! } [INFO] [stdout] 115 ~ //! } [INFO] [stdout] 116 ~ //! } [INFO] [stdout] 117 ~ //! uf.count [INFO] [stdout] 118 ~ //! [INFO] [stdout] 119 ~ //! } [INFO] [stdout] 120 ~ //! } [INFO] [stdout] 121 ~ //! ``` [INFO] [stdout] 122 ~ //! [INFO] [stdout] 123 ~ //! # Approach 2: DFS [INFO] [stdout] 124 ~ //! [INFO] [stdout] 125 ~ //! * Time complexity: O(m*n) [INFO] [stdout] 126 ~ //! [INFO] [stdout] 127 ~ //! * Space complexity: O(m*n) [INFO] [stdout] 128 ~ //! [INFO] [stdout] 129 ~ //! * Runtime: 16ms [INFO] [stdout] 130 ~ //! * Memory: 4.7MB [INFO] [stdout] 131 ~ //! [INFO] [stdout] 132 ~ //! ```rust [INFO] [stdout] 133 ~ //! use std::collections::HashSet; [INFO] [stdout] 134 ~ //! [INFO] [stdout] 135 ~ //! impl Solution { [INFO] [stdout] 136 ~ //! pub fn num_islands(grid: Vec>) -> i32 { [INFO] [stdout] 137 ~ //! if grid.is_empty() { return 0; } [INFO] [stdout] 138 ~ //! [INFO] [stdout] 139 ~ //! let mut visited: HashSet<(usize, usize)> = HashSet::new(); [INFO] [stdout] 140 ~ //! let mut result = 0; [INFO] [stdout] 141 ~ //! let m = grid.len(); [INFO] [stdout] 142 ~ //! let n = grid[0].len(); [INFO] [stdout] 143 ~ //! [INFO] [stdout] 144 ~ //! for i in 0..m { [INFO] [stdout] 145 ~ //! for j in 0..n { [INFO] [stdout] 146 ~ //! if !visited.contains(&(i, j)) && grid[i][j] == '1' { [INFO] [stdout] 147 ~ //! Self::dfs(&grid, &mut visited, i, j); [INFO] [stdout] 148 ~ //! result += 1; [INFO] [stdout] 149 ~ //! } [INFO] [stdout] 150 ~ //! } [INFO] [stdout] 151 ~ //! } [INFO] [stdout] 152 ~ //! [INFO] [stdout] 153 ~ //! result [INFO] [stdout] 154 ~ //! } [INFO] [stdout] 155 ~ //! [INFO] [stdout] 156 ~ //! const DIRECTIONS: [[i32; 2]; 4] = [[1, 0], [-1, 0], [0, 1], [0, -1]]; [INFO] [stdout] 157 ~ //! pub fn dfs(grid: &Vec>, visited: &mut HashSet<(usize, usize)>, m: usize, n: usize) { [INFO] [stdout] 158 ~ //! if m >= grid.len() || n >= grid[0].len() || grid[m][n] == '0' || visited.contains(&(m, n)) { return; } [INFO] [stdout] 159 ~ //! [INFO] [stdout] 160 ~ //! visited.insert((m, n)); [INFO] [stdout] 161 ~ //! for dis in Self::DIRECTIONS.iter() { [INFO] [stdout] 162 ~ //! let dr = (dis[0] + m as i32) as usize; [INFO] [stdout] 163 ~ //! let dc = (dis[1] + n as i32) as usize; [INFO] [stdout] 164 ~ //! Self::dfs(grid, visited, dr, dc); [INFO] [stdout] 165 ~ //! } [INFO] [stdout] 166 ~ //! } [INFO] [stdout] 167 ~ //! } [INFO] [stdout] 168 ~ //! ``` [INFO] [stdout] 169 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: redundant field names in struct initialization [INFO] [stdout] --> src/cd0200_number_of_islands/mod.rs:219:21 [INFO] [stdout] | [INFO] [stdout] 219 | UnionFind { parents: parents, count: count, rank: rank } [INFO] [stdout] | ^^^^^^^^^^^^^^^^ help: replace it with: `parents` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names [INFO] [stdout] = note: `#[warn(clippy::redundant_field_names)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: redundant field names in struct initialization [INFO] [stdout] --> src/cd0200_number_of_islands/mod.rs:219:39 [INFO] [stdout] | [INFO] [stdout] 219 | UnionFind { parents: parents, count: count, rank: rank } [INFO] [stdout] | ^^^^^^^^^^^^ help: replace it with: `count` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: redundant field names in struct initialization [INFO] [stdout] --> src/cd0200_number_of_islands/mod.rs:219:53 [INFO] [stdout] | [INFO] [stdout] 219 | UnionFind { parents: parents, count: count, rank: rank } [INFO] [stdout] | ^^^^^^^^^^ help: replace it with: `rank` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:46:5 [INFO] [stdout] | [INFO] [stdout] 46 | /// if head.is_none() { return None; } [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] = note: `#[warn(clippy::tabs_in_doc_comments)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:48:5 [INFO] [stdout] | [INFO] [stdout] 48 | /// let mut prev = None; [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:49:5 [INFO] [stdout] | [INFO] [stdout] 49 | /// let mut current = head; [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:50:5 [INFO] [stdout] | [INFO] [stdout] 50 | /// while let Some(mut tmp) = current.take() { [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:51:5 [INFO] [stdout] | [INFO] [stdout] 51 | /// let next = tmp.next.take(); [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:52:5 [INFO] [stdout] | [INFO] [stdout] 52 | /// tmp.next = prev.take(); [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:53:5 [INFO] [stdout] | [INFO] [stdout] 53 | /// prev = Some(tmp); [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:54:5 [INFO] [stdout] | [INFO] [stdout] 54 | /// current = next; [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:55:5 [INFO] [stdout] | [INFO] [stdout] 55 | /// } [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:57:5 [INFO] [stdout] | [INFO] [stdout] 57 | /// prev [INFO] [stdout] | ^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: `...` range patterns are deprecated [INFO] [stdout] --> src/cd0224_basic_calculator/mod.rs:88:16 [INFO] [stdout] | [INFO] [stdout] 88 | '0'...'9' => { [INFO] [stdout] | ^^^ help: use `..=` for an inclusive range [INFO] [stdout] | [INFO] [stdout] = warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! [INFO] [stdout] = note: for more information, see [INFO] [stdout] = note: `#[warn(ellipsis_inclusive_range_patterns)]` (part of `#[warn(rust_2021_compatibility)]`) on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0300_longest_increasing_subsequence/mod.rs:116:1 [INFO] [stdout] | [INFO] [stdout] 116 | / /// [INFO] [stdout] 117 | | [INFO] [stdout] | |_^ [INFO] [stdout] 118 | pub fn length_of_lis(nums: Vec) -> i32 { [INFO] [stdout] | -------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 19 ~ //! # Solutions [INFO] [stdout] 20 ~ //! [INFO] [stdout] 21 ~ //! # Approach 1: Dynamic Programming [INFO] [stdout] 22 ~ //! [INFO] [stdout] 23 ~ //! * Time complexity: O(nlogn) [INFO] [stdout] 24 ~ //! [INFO] [stdout] 25 ~ //! * Space complexity: O(n) [INFO] [stdout] 26 ~ //! [INFO] [stdout] 27 ~ //! * Runtime: 0 ms [INFO] [stdout] 28 ~ //! * Memory: 2.5 MB [INFO] [stdout] 29 ~ //! [INFO] [stdout] 30 ~ //! ```rust [INFO] [stdout] 31 ~ //! impl Solution { [INFO] [stdout] 32 ~ //! pub fn length_of_lis(nums: Vec) -> i32 { [INFO] [stdout] 33 ~ //! if nums.len() <= 1 { return nums.len() as i32; } [INFO] [stdout] 34 ~ //! [INFO] [stdout] 35 ~ //! let mut lis = vec![]; [INFO] [stdout] 36 ~ //! lis.push(nums[0]); [INFO] [stdout] 37 ~ //! [INFO] [stdout] 38 ~ //! for i in 1..nums.len() { [INFO] [stdout] 39 ~ //! match lis.binary_search(&nums[i]) { [INFO] [stdout] 40 ~ //! Ok(n) => (), [INFO] [stdout] 41 ~ //! Err(n) => { [INFO] [stdout] 42 ~ //! if n >= lis.len() { lis.push(nums[i]); } else { lis[n] = nums[i]; } [INFO] [stdout] 43 ~ //! }, [INFO] [stdout] 44 ~ //! } [INFO] [stdout] 45 ~ //! } [INFO] [stdout] 46 ~ //! lis.len() as i32 [INFO] [stdout] 47 ~ //! } [INFO] [stdout] 48 ~ //! } [INFO] [stdout] 49 ~ //! ``` [INFO] [stdout] 50 ~ //! [INFO] [stdout] 51 ~ //! # Approach 2: Dynamic Programming [INFO] [stdout] 52 ~ //! [INFO] [stdout] 53 ~ //! * Time complexity: O(n2) [INFO] [stdout] 54 ~ //! [INFO] [stdout] 55 ~ //! * Space complexity: O(n) [INFO] [stdout] 56 ~ //! [INFO] [stdout] 57 ~ //! * Runtime: 12 ms [INFO] [stdout] 58 ~ //! * Memory: 2.5 MB [INFO] [stdout] 59 ~ //! [INFO] [stdout] 60 ~ //! ```rust [INFO] [stdout] 61 ~ //! use std::cmp::max; [INFO] [stdout] 62 ~ //! [INFO] [stdout] 63 ~ //! impl Solution { [INFO] [stdout] 64 ~ //! pub fn length_of_lis(nums: Vec) -> i32 { [INFO] [stdout] 65 ~ //! if nums.len() <= 1 { return nums.len() as i32; } [INFO] [stdout] 66 ~ //! [INFO] [stdout] 67 ~ //! let mut dp = vec![1; nums.len()]; [INFO] [stdout] 68 ~ //! let mut max_lis = 1; [INFO] [stdout] 69 ~ //! [INFO] [stdout] 70 ~ //! for i in 1..nums.len() { [INFO] [stdout] 71 ~ //! let mut tmp_max = 0; [INFO] [stdout] 72 ~ //! for j in 0..i { [INFO] [stdout] 73 ~ //! if nums[i] > nums[j] { [INFO] [stdout] 74 ~ //! tmp_max = max(tmp_max, dp[j]); [INFO] [stdout] 75 ~ //! } [INFO] [stdout] 76 ~ //! dp[i] = tmp_max + 1; [INFO] [stdout] 77 ~ //! } [INFO] [stdout] 78 ~ //! max_lis = max(max_lis, dp[i]); [INFO] [stdout] 79 ~ //! } [INFO] [stdout] 80 ~ //! max_lis [INFO] [stdout] 81 ~ //! } [INFO] [stdout] 82 ~ //! } [INFO] [stdout] 83 ~ //! ``` [INFO] [stdout] 84 ~ //! [INFO] [stdout] 85 ~ //! # Approach 3: Dynamic Programming [INFO] [stdout] 86 ~ //! [INFO] [stdout] 87 ~ //! * Time complexity: O(n2) [INFO] [stdout] 88 ~ //! [INFO] [stdout] 89 ~ //! * Space complexity: O(n) [INFO] [stdout] 90 ~ //! [INFO] [stdout] 91 ~ //! * Runtime: 8 ms [INFO] [stdout] 92 ~ //! * Memory: 2.5 MB [INFO] [stdout] 93 ~ //! [INFO] [stdout] 94 ~ //! ```rust [INFO] [stdout] 95 ~ //! use std::cmp::max; [INFO] [stdout] 96 ~ //! [INFO] [stdout] 97 ~ //! impl Solution { [INFO] [stdout] 98 ~ //! pub fn length_of_lis(nums: Vec) -> i32 { [INFO] [stdout] 99 ~ //! if nums.len() <= 1 { return nums.len() as i32; } [INFO] [stdout] 100 ~ //! [INFO] [stdout] 101 ~ //! let mut dp = vec![1; nums.len()]; [INFO] [stdout] 102 ~ //! let mut max_lis = 1; [INFO] [stdout] 103 ~ //! [INFO] [stdout] 104 ~ //! for i in 1..nums.len() { [INFO] [stdout] 105 ~ //! for j in 0..i { [INFO] [stdout] 106 ~ //! if nums[i] > nums[j] { [INFO] [stdout] 107 ~ //! dp[i] = max(dp[i], dp[j] + 1); [INFO] [stdout] 108 ~ //! } [INFO] [stdout] 109 ~ //! } [INFO] [stdout] 110 ~ //! max_lis = max(max_lis, dp[i]); [INFO] [stdout] 111 ~ //! } [INFO] [stdout] 112 ~ //! max_lis [INFO] [stdout] 113 ~ //! } [INFO] [stdout] 114 ~ //! } [INFO] [stdout] 115 ~ //! ``` [INFO] [stdout] 116 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0309_best_time_to_buy_and_sell_stock_with_cooldown/mod.rs:81:1 [INFO] [stdout] | [INFO] [stdout] 81 | / /// [INFO] [stdout] 82 | | [INFO] [stdout] | |_^ [INFO] [stdout] 83 | pub fn max_profit(prices: Vec) -> i32 { [INFO] [stdout] | ----------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 19 ~ //! # Solutions [INFO] [stdout] 20 ~ //! [INFO] [stdout] 21 ~ //! # Approach 1: Dynamic Programming [INFO] [stdout] 22 ~ //! [INFO] [stdout] 23 ~ //! * Time complexity: O(n) [INFO] [stdout] 24 ~ //! [INFO] [stdout] 25 ~ //! * Space complexity: O(n) [INFO] [stdout] 26 ~ //! [INFO] [stdout] 27 ~ //! * Runtime: 0 ms [INFO] [stdout] 28 ~ //! * Memory: 2.6 MB [INFO] [stdout] 29 ~ //! [INFO] [stdout] 30 ~ //! ```rust [INFO] [stdout] 31 ~ //! use std::cmp::max; [INFO] [stdout] 32 ~ //! [INFO] [stdout] 33 ~ //! impl Solution { [INFO] [stdout] 34 ~ //! pub fn max_profit(prices: Vec) -> i32 { [INFO] [stdout] 35 ~ //! if prices.len() < 2 { return 0; } [INFO] [stdout] 36 ~ //! [INFO] [stdout] 37 ~ //! let cooldown = 1; [INFO] [stdout] 38 ~ //! let mut profits = vec![0; prices.len()]; [INFO] [stdout] 39 ~ //! let mut max_profit = 0; [INFO] [stdout] 40 ~ //! let mut tmp_max = profits[0] - prices[0]; [INFO] [stdout] 41 ~ //! [INFO] [stdout] 42 ~ //! for i in 1..prices.len() { [INFO] [stdout] 43 ~ //! profits[i] = max(profits[i - 1], tmp_max + prices[i]); [INFO] [stdout] 44 ~ //! tmp_max = max(tmp_max, if i > cooldown { profits[i - 1 - cooldown] } else { profits[i - 1] } - prices[i]); [INFO] [stdout] 45 ~ //! max_profit = max(profits[i], max_profit); [INFO] [stdout] 46 ~ //! } [INFO] [stdout] 47 ~ //! max_profit [INFO] [stdout] 48 ~ //! } [INFO] [stdout] 49 ~ //! } [INFO] [stdout] 50 ~ //! ``` [INFO] [stdout] 51 ~ //! [INFO] [stdout] 52 ~ //! # Approach 2: Dynamic Programming [INFO] [stdout] 53 ~ //! [INFO] [stdout] 54 ~ //! * Time complexity: O(n) [INFO] [stdout] 55 ~ //! [INFO] [stdout] 56 ~ //! * Space complexity: O(n) [INFO] [stdout] 57 ~ //! [INFO] [stdout] 58 ~ //! * Runtime: 0 ms [INFO] [stdout] 59 ~ //! * Memory: 2.5 MB [INFO] [stdout] 60 ~ //! [INFO] [stdout] 61 ~ //! ```rust [INFO] [stdout] 62 ~ //! use std::cmp::max; [INFO] [stdout] 63 ~ //! [INFO] [stdout] 64 ~ //! impl Solution { [INFO] [stdout] 65 ~ //! pub fn max_profit(prices: Vec) -> i32 { [INFO] [stdout] 66 ~ //! if prices.len() < 2 { return 0; } [INFO] [stdout] 67 ~ //! [INFO] [stdout] 68 ~ //! let cooldown = 1; [INFO] [stdout] 69 ~ //! let mut sell = vec![0; prices.len()]; [INFO] [stdout] 70 ~ //! let mut buy = vec![0; prices.len()]; [INFO] [stdout] 71 ~ //! buy[0] = -prices[0]; [INFO] [stdout] 72 ~ //! [INFO] [stdout] 73 ~ //! for i in 1..prices.len() { [INFO] [stdout] 74 ~ //! sell[i] = max(sell[i - 1], buy[i - 1] + prices[i]); [INFO] [stdout] 75 ~ //! buy[i] = max(buy[i - 1], if i > cooldown { sell[i - 1 - cooldown] } else { sell[i - 1] } - prices[i]); [INFO] [stdout] 76 ~ //! } [INFO] [stdout] 77 ~ //! sell[prices.len() - 1] [INFO] [stdout] 78 ~ //! } [INFO] [stdout] 79 ~ //! } [INFO] [stdout] 80 ~ //! ``` [INFO] [stdout] 81 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0322_coin_change/mod.rs:82:1 [INFO] [stdout] | [INFO] [stdout] 82 | / /// [INFO] [stdout] 83 | | [INFO] [stdout] | |_^ [INFO] [stdout] 84 | pub fn coin_change(coins: Vec, amount: i32) -> i32 { [INFO] [stdout] | ------------------ the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 24 ~ //! # Solutions [INFO] [stdout] 25 ~ //! [INFO] [stdout] 26 ~ //! # Approach 1: Dynamic Programming [INFO] [stdout] 27 ~ //! [INFO] [stdout] 28 ~ //! * Time complexity: O(s*n) [INFO] [stdout] 29 ~ //! [INFO] [stdout] 30 ~ //! * Space complexity: O(s) [INFO] [stdout] 31 ~ //! [INFO] [stdout] 32 ~ //! * Runtime: 4 ms [INFO] [stdout] 33 ~ //! * Memory: 3 MB [INFO] [stdout] 34 ~ //! [INFO] [stdout] 35 ~ //! ```rust [INFO] [stdout] 36 ~ //! impl Solution { [INFO] [stdout] 37 ~ //! pub fn coin_change(coins: Vec, amount: i32) -> i32 { [INFO] [stdout] 38 ~ //! let mut dp = vec![amount + 1; (amount + 1) as usize]; [INFO] [stdout] 39 ~ //! dp[0] = 0; [INFO] [stdout] 40 ~ //! [INFO] [stdout] 41 ~ //! for i in 1..=amount { [INFO] [stdout] 42 ~ //! for &coin in coins.iter() { [INFO] [stdout] 43 ~ //! if i >= coin { [INFO] [stdout] 44 ~ //! dp[i as usize] = i32::min(dp[i as usize], dp[(i - coin) as usize] + 1); [INFO] [stdout] 45 ~ //! } [INFO] [stdout] 46 ~ //! } [INFO] [stdout] 47 ~ //! } [INFO] [stdout] 48 ~ //! let last = *dp.last().unwrap(); [INFO] [stdout] 49 ~ //! if last > amount { return -1; } else { return last; } [INFO] [stdout] 50 ~ //! } [INFO] [stdout] 51 ~ //! } [INFO] [stdout] 52 ~ //! ``` [INFO] [stdout] 53 ~ //! [INFO] [stdout] 54 ~ //! # Approach 2: Dynamic Programming [INFO] [stdout] 55 ~ //! [INFO] [stdout] 56 ~ //! * Time complexity: O(s*n) [INFO] [stdout] 57 ~ //! [INFO] [stdout] 58 ~ //! * Space complexity: O(s) [INFO] [stdout] 59 ~ //! [INFO] [stdout] 60 ~ //! * Runtime: 4 ms [INFO] [stdout] 61 ~ //! * Memory: 4 MB [INFO] [stdout] 62 ~ //! [INFO] [stdout] 63 ~ //! ```rust [INFO] [stdout] 64 ~ //! impl Solution { [INFO] [stdout] 65 ~ //! pub fn coin_change(coins: Vec, amount: i32) -> i32 { [INFO] [stdout] 66 ~ //! let mut dp = vec![-1; (amount+1) as usize]; [INFO] [stdout] 67 ~ //! dp[0] = 0; [INFO] [stdout] 68 ~ //! [INFO] [stdout] 69 ~ //! for i in 1..=amount as usize { [INFO] [stdout] 70 ~ //! dp[i] = std::i32::MAX; [INFO] [stdout] 71 ~ //! for &coin in coins.iter() { [INFO] [stdout] 72 ~ //! if i >= coin as usize && dp[i - coin as usize] != -1 { [INFO] [stdout] 73 ~ //! dp[i] = i32::min(dp[i], dp[i - coin as usize] + 1); [INFO] [stdout] 74 ~ //! } [INFO] [stdout] 75 ~ //! } [INFO] [stdout] 76 ~ //! if dp[i] == std::i32::MAX { dp[i] = -1; } [INFO] [stdout] 77 ~ //! } [INFO] [stdout] 78 ~ //! *dp.last().unwrap() [INFO] [stdout] 79 ~ //! } [INFO] [stdout] 80 ~ //! } [INFO] [stdout] 81 ~ //! ``` [INFO] [stdout] 82 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0547_friend_circles/mod.rs:137:1 [INFO] [stdout] | [INFO] [stdout] 137 | / /// [INFO] [stdout] 138 | | [INFO] [stdout] | |_^ [INFO] [stdout] 139 | pub fn find_circle_num(m: Vec>) -> i32 { [INFO] [stdout] | ---------------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 37 ~ //! # Solutions [INFO] [stdout] 38 ~ //! [INFO] [stdout] 39 ~ //! # Approach 1: Union Find [INFO] [stdout] 40 ~ //! [INFO] [stdout] 41 ~ //! * Time complexity: O(m*n) [INFO] [stdout] 42 ~ //! [INFO] [stdout] 43 ~ //! * Space complexity: O(m*n) [INFO] [stdout] 44 ~ //! [INFO] [stdout] 45 ~ //! * Runtime: 0 ms [INFO] [stdout] 46 ~ //! * Memory: 2.7 MB [INFO] [stdout] 47 ~ //! [INFO] [stdout] 48 ~ //! ```rust [INFO] [stdout] 49 ~ //! struct UnionFind { [INFO] [stdout] 50 ~ //! parents: Vec, [INFO] [stdout] 51 ~ //! count: i32, [INFO] [stdout] 52 ~ //! } [INFO] [stdout] 53 ~ //! [INFO] [stdout] 54 ~ //! impl UnionFind { [INFO] [stdout] 55 ~ //! fn new(grid: &Vec>) -> Self { [INFO] [stdout] 56 ~ //! let m = grid.len(); [INFO] [stdout] 57 ~ //! let count = m as i32; [INFO] [stdout] 58 ~ //! let mut parents = vec![]; [INFO] [stdout] 59 ~ //! for i in 0..m { parents.push(i as i32); } [INFO] [stdout] 60 ~ //! [INFO] [stdout] 61 ~ //! UnionFind { parents: parents, count: count } [INFO] [stdout] 62 ~ //! } [INFO] [stdout] 63 ~ //! [INFO] [stdout] 64 ~ //! fn find(&mut self, i: i32) -> i32 { [INFO] [stdout] 65 ~ //! if self.parents[i as usize] != i { self.parents[i as usize] = self.find(self.parents[i as usize]) }; [INFO] [stdout] 66 ~ //! self.parents[i as usize] [INFO] [stdout] 67 ~ //! } [INFO] [stdout] 68 ~ //! [INFO] [stdout] 69 ~ //! fn union(&mut self, x: i32, y: i32) -> i32 { [INFO] [stdout] 70 ~ //! let x_parent = self.find(x); [INFO] [stdout] 71 ~ //! let y_parent = self.find(y); [INFO] [stdout] 72 ~ //! [INFO] [stdout] 73 ~ //! if x_parent == y_parent { return self.count; } [INFO] [stdout] 74 ~ //! [INFO] [stdout] 75 ~ //! self.parents[x_parent as usize] = y_parent; [INFO] [stdout] 76 ~ //! self.count -= 1; [INFO] [stdout] 77 ~ //! [INFO] [stdout] 78 ~ //! self.count [INFO] [stdout] 79 ~ //! } [INFO] [stdout] 80 ~ //! } [INFO] [stdout] 81 ~ //! [INFO] [stdout] 82 ~ //! impl Solution { [INFO] [stdout] 83 ~ //! pub fn find_circle_num(m: Vec>) -> i32 { [INFO] [stdout] 84 ~ //! if m.is_empty() { return 0; } [INFO] [stdout] 85 ~ //! let n = m.len(); [INFO] [stdout] 86 ~ //! let mut uf = UnionFind::new(&m); [INFO] [stdout] 87 ~ //! [INFO] [stdout] 88 ~ //! for i in 0..n { [INFO] [stdout] 89 ~ //! for j in 0..n { [INFO] [stdout] 90 ~ //! if m[i][j] == 1 { uf.union(i as i32, j as i32); } [INFO] [stdout] 91 ~ //! } [INFO] [stdout] 92 ~ //! } [INFO] [stdout] 93 ~ //! uf.count [INFO] [stdout] 94 ~ //! } [INFO] [stdout] 95 ~ //! } [INFO] [stdout] 96 ~ //! ``` [INFO] [stdout] 97 ~ //! [INFO] [stdout] 98 ~ //! # Solutions [INFO] [stdout] 99 ~ //! [INFO] [stdout] 100 ~ //! # Approach 2: DFS [INFO] [stdout] 101 ~ //! [INFO] [stdout] 102 ~ //! * Time complexity: [INFO] [stdout] 103 ~ //! [INFO] [stdout] 104 ~ //! * Space complexity: [INFO] [stdout] 105 ~ //! [INFO] [stdout] 106 ~ //! * Runtime: 0 ms [INFO] [stdout] 107 ~ //! * Memory: 2.7 MB [INFO] [stdout] 108 ~ //! [INFO] [stdout] 109 ~ //! ```rust [INFO] [stdout] 110 ~ //! impl Solution { [INFO] [stdout] 111 ~ //! pub fn find_circle_num(m: Vec>) -> i32 { [INFO] [stdout] 112 ~ //! if m.is_empty() { return 0; } [INFO] [stdout] 113 ~ //! [INFO] [stdout] 114 ~ //! let n = m.len(); [INFO] [stdout] 115 ~ //! let mut visited: Vec = vec![]; [INFO] [stdout] 116 ~ //! let mut count = 0; [INFO] [stdout] 117 ~ //! [INFO] [stdout] 118 ~ //! for i in 0..n { [INFO] [stdout] 119 ~ //! if !visited.contains(&(i as i32)) { [INFO] [stdout] 120 ~ //! Self::dfs(&m, &mut visited, i, n); [INFO] [stdout] 121 ~ //! count += 1; [INFO] [stdout] 122 ~ //! } [INFO] [stdout] 123 ~ //! } [INFO] [stdout] 124 ~ //! count [INFO] [stdout] 125 ~ //! } [INFO] [stdout] 126 ~ //! [INFO] [stdout] 127 ~ //! pub fn dfs(m: &Vec>, visited: &mut Vec, i: usize, n: usize) { [INFO] [stdout] 128 ~ //! for j in 0..n { [INFO] [stdout] 129 ~ //! if m[i][j] == 1 && !visited.contains(&(j as i32)) { [INFO] [stdout] 130 ~ //! visited.push(j as i32); [INFO] [stdout] 131 ~ //! Self::dfs(m, visited, j, n); [INFO] [stdout] 132 ~ //! } [INFO] [stdout] 133 ~ //! } [INFO] [stdout] 134 ~ //! } [INFO] [stdout] 135 ~ //! } [INFO] [stdout] 136 ~ //! ``` [INFO] [stdout] 137 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: redundant field names in struct initialization [INFO] [stdout] --> src/cd0547_friend_circles/mod.rs:165:21 [INFO] [stdout] | [INFO] [stdout] 165 | UnionFind { parents: parents, count: count } [INFO] [stdout] | ^^^^^^^^^^^^^^^^ help: replace it with: `parents` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: redundant field names in struct initialization [INFO] [stdout] --> src/cd0547_friend_circles/mod.rs:165:39 [INFO] [stdout] | [INFO] [stdout] 165 | UnionFind { parents: parents, count: count } [INFO] [stdout] | ^^^^^^^^^^^^ help: replace it with: `count` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:21:33 [INFO] [stdout] | [INFO] [stdout] 21 | //! circularDeque.insertLast(1); // return true [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:22:33 [INFO] [stdout] | [INFO] [stdout] 22 | //! circularDeque.insertLast(2); // return true [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:23:34 [INFO] [stdout] | [INFO] [stdout] 23 | //! circularDeque.insertFront(3); // return true [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:24:34 [INFO] [stdout] | [INFO] [stdout] 24 | //! circularDeque.insertFront(4); // return false, the queue is full [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:25:31 [INFO] [stdout] | [INFO] [stdout] 25 | //! circularDeque.getRear(); // return 2 [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:26:28 [INFO] [stdout] | [INFO] [stdout] 26 | //! circularDeque.isFull(); // return true [INFO] [stdout] | ^^^^^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:27:32 [INFO] [stdout] | [INFO] [stdout] 27 | //! circularDeque.deleteLast(); // return true [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:28:34 [INFO] [stdout] | [INFO] [stdout] 28 | //! circularDeque.insertFront(4); // return true [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: using tabs in doc comments is not recommended [INFO] [stdout] --> src/cd0641_design_circular_deque/mod.rs:29:30 [INFO] [stdout] | [INFO] [stdout] 29 | //! circularDeque.getFront(); // return 4 [INFO] [stdout] | ^^^^^^^^^^^^ help: consider using four spaces per tab [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: empty line after doc comment [INFO] [stdout] --> src/cd0714_best_time_to_buy_and_sell_stock_with_transaction_fee/mod.rs:115:1 [INFO] [stdout] | [INFO] [stdout] 115 | / /// [INFO] [stdout] 116 | | [INFO] [stdout] | |_^ [INFO] [stdout] 117 | pub fn max_profit(prices: Vec, fee: i32) -> i32 { [INFO] [stdout] | ----------------- the comment documents this function [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments [INFO] [stdout] = help: if the empty line is unintentional, remove it [INFO] [stdout] help: if the comment should document the parent module use an inner doc comment [INFO] [stdout] | [INFO] [stdout] 28 ~ //! # Solutions [INFO] [stdout] 29 ~ //! [INFO] [stdout] 30 ~ //! # Approach 1: Dynamic Programming [INFO] [stdout] 31 ~ //! [INFO] [stdout] 32 ~ //! * Time complexity: O(n) [INFO] [stdout] 33 ~ //! [INFO] [stdout] 34 ~ //! * Space complexity: O(n) [INFO] [stdout] 35 ~ //! [INFO] [stdout] 36 ~ //! * Runtime: 8 ms [INFO] [stdout] 37 ~ //! * Memory: 3.7 MB [INFO] [stdout] 38 ~ //! [INFO] [stdout] 39 ~ //! ```rust [INFO] [stdout] 40 ~ //! use std::cmp::max; [INFO] [stdout] 41 ~ //! [INFO] [stdout] 42 ~ //! impl Solution { [INFO] [stdout] 43 ~ //! pub fn max_profit(prices: Vec, fee: i32) -> i32 { [INFO] [stdout] 44 ~ //! if prices.len() < 2 || fee >= 50000 { return 0; } [INFO] [stdout] 45 ~ //! [INFO] [stdout] 46 ~ //! let mut profits = vec![0; prices.len()]; [INFO] [stdout] 47 ~ //! let mut max_profit = 0; [INFO] [stdout] 48 ~ //! let mut tmp_max = profits[0] - prices[0]; [INFO] [stdout] 49 ~ //! [INFO] [stdout] 50 ~ //! for i in 1..prices.len() { [INFO] [stdout] 51 ~ //! profits[i] = max(profits[i - 1], tmp_max + prices[i] - fee); [INFO] [stdout] 52 ~ //! tmp_max = max(tmp_max, profits[i - 1] - prices[i]); [INFO] [stdout] 53 ~ //! max_profit = max(max_profit, profits[i]); [INFO] [stdout] 54 ~ //! } [INFO] [stdout] 55 ~ //! max_profit [INFO] [stdout] 56 ~ //! } [INFO] [stdout] 57 ~ //! } [INFO] [stdout] 58 ~ //! ``` [INFO] [stdout] 59 ~ //! [INFO] [stdout] 60 ~ //! # Approach 2: Dynamic Programming [INFO] [stdout] 61 ~ //! [INFO] [stdout] 62 ~ //! * Time complexity: O(n) [INFO] [stdout] 63 ~ //! [INFO] [stdout] 64 ~ //! * Space complexity: O(n) [INFO] [stdout] 65 ~ //! [INFO] [stdout] 66 ~ //! * Runtime: 8 ms [INFO] [stdout] 67 ~ //! * Memory: 3.6 MB [INFO] [stdout] 68 ~ //! [INFO] [stdout] 69 ~ //! ```rust [INFO] [stdout] 70 ~ //!use std::cmp::max; [INFO] [stdout] 71 ~ //! [INFO] [stdout] 72 ~ //!impl Solution { [INFO] [stdout] 73 ~ //! pub fn max_profit(prices: Vec, fee: i32) -> i32 { [INFO] [stdout] 74 ~ //! if prices.len() < 2 || fee >= 50000 { return 0; } [INFO] [stdout] 75 ~ //! [INFO] [stdout] 76 ~ //! let mut sell = vec![0; prices.len()]; [INFO] [stdout] 77 ~ //! let mut buy = vec![0; prices.len()]; [INFO] [stdout] 78 ~ //! buy[0] = -prices[0]; [INFO] [stdout] 79 ~ //! [INFO] [stdout] 80 ~ //! for i in 1..prices.len() { [INFO] [stdout] 81 ~ //! sell[i] = max(sell[i - 1], buy[i - 1] + prices[i] - fee); [INFO] [stdout] 82 ~ //! buy[i] = max(buy[i - 1], sell[i - 1] - prices[i]); [INFO] [stdout] 83 ~ //! } [INFO] [stdout] 84 ~ //! sell[prices.len() - 1] [INFO] [stdout] 85 ~ //! } [INFO] [stdout] 86 ~ //!} [INFO] [stdout] 87 ~ //! ``` [INFO] [stdout] 88 ~ //! [INFO] [stdout] 89 ~ //! # Approach 3: Dynamic Programming [INFO] [stdout] 90 ~ //! [INFO] [stdout] 91 ~ //! * Time complexity: O(n) [INFO] [stdout] 92 ~ //! [INFO] [stdout] 93 ~ //! * Space complexity: O(n) [INFO] [stdout] 94 ~ //! [INFO] [stdout] 95 ~ //! * Runtime: 12 ms [INFO] [stdout] 96 ~ //! * Memory: 3.7 MB [INFO] [stdout] 97 ~ //! [INFO] [stdout] 98 ~ //! ```rust [INFO] [stdout] 99 ~ //! use std::cmp::max; [INFO] [stdout] 100 ~ //! [INFO] [stdout] 101 ~ //! impl Solution { [INFO] [stdout] 102 ~ //! pub fn max_profit(prices: Vec, fee: i32) -> i32 { [INFO] [stdout] 103 ~ //! if prices.len() < 2 || fee >= 50000 { return 0; } [INFO] [stdout] 104 ~ //! [INFO] [stdout] 105 ~ //! let mut cash = 0; [INFO] [stdout] 106 ~ //! let mut hold = -prices[0]; [INFO] [stdout] 107 ~ //! for i in 1..prices.len() { [INFO] [stdout] 108 ~ //! cash = max(cash, hold + prices[i] - fee); [INFO] [stdout] 109 ~ //! hold = max(hold, cash - prices[i]); [INFO] [stdout] 110 ~ //! } [INFO] [stdout] 111 ~ //! cash [INFO] [stdout] 112 ~ //! } [INFO] [stdout] 113 ~ //! } [INFO] [stdout] 114 ~ //! ``` [INFO] [stdout] 115 ~ //! [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0001_two_sum/mod.rs:92:5 [INFO] [stdout] | [INFO] [stdout] 92 | return vec![]; [INFO] [stdout] | ^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] = note: `#[warn(clippy::needless_return)]` on by default [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 92 - return vec![]; [INFO] [stdout] 92 + vec![] [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: manual implementation of an assign operation [INFO] [stdout] --> src/cd0002_add_two_numbers/mod.rs:93:17 [INFO] [stdout] | [INFO] [stdout] 93 | sum = sum % 10; [INFO] [stdout] | ^^^^^^^^^^^^^^ help: replace it with: `sum %= 10` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern [INFO] [stdout] = note: `#[warn(clippy::assign_op_pattern)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: usage of a legacy numeric constant [INFO] [stdout] --> src/cd0004_median_of_two_sorted_arrays/mod.rs:110:45 [INFO] [stdout] | [INFO] [stdout] 110 | let first_left = if mid_first == 0 { std::i32::MIN } else { first[mid_first - 1] }; [INFO] [stdout] | ^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants [INFO] [stdout] = note: `#[warn(clippy::legacy_numeric_constants)]` on by default [INFO] [stdout] help: use the associated constant instead [INFO] [stdout] | [INFO] [stdout] 110 - let first_left = if mid_first == 0 { std::i32::MIN } else { first[mid_first - 1] }; [INFO] [stdout] 110 + let first_left = if mid_first == 0 { i32::MIN } else { first[mid_first - 1] }; [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: usage of a legacy numeric constant [INFO] [stdout] --> src/cd0004_median_of_two_sorted_arrays/mod.rs:111:46 [INFO] [stdout] | [INFO] [stdout] 111 | let first_right = if mid_first == m { std::i32::MAX } else { first[mid_first] }; [INFO] [stdout] | ^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants [INFO] [stdout] help: use the associated constant instead [INFO] [stdout] | [INFO] [stdout] 111 - let first_right = if mid_first == m { std::i32::MAX } else { first[mid_first] }; [INFO] [stdout] 111 + let first_right = if mid_first == m { i32::MAX } else { first[mid_first] }; [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: usage of a legacy numeric constant [INFO] [stdout] --> src/cd0004_median_of_two_sorted_arrays/mod.rs:112:47 [INFO] [stdout] | [INFO] [stdout] 112 | let second_left = if mid_second == 0 { std::i32::MIN } else { second[mid_second - 1] }; [INFO] [stdout] | ^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants [INFO] [stdout] help: use the associated constant instead [INFO] [stdout] | [INFO] [stdout] 112 - let second_left = if mid_second == 0 { std::i32::MIN } else { second[mid_second - 1] }; [INFO] [stdout] 112 + let second_left = if mid_second == 0 { i32::MIN } else { second[mid_second - 1] }; [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: usage of a legacy numeric constant [INFO] [stdout] --> src/cd0004_median_of_two_sorted_arrays/mod.rs:113:48 [INFO] [stdout] | [INFO] [stdout] 113 | let second_right = if mid_second == n { std::i32::MAX } else { second[mid_second] }; [INFO] [stdout] | ^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants [INFO] [stdout] help: use the associated constant instead [INFO] [stdout] | [INFO] [stdout] 113 - let second_right = if mid_second == n { std::i32::MAX } else { second[mid_second] }; [INFO] [stdout] 113 + let second_right = if mid_second == n { i32::MAX } else { second[mid_second] }; [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this looks like you are swapping `left_max` and `right_min` manually [INFO] [stdout] --> src/cd0004_median_of_two_sorted_arrays/mod.rs:121:20 [INFO] [stdout] | [INFO] [stdout] 121 | / let tmp = left_max; [INFO] [stdout] 122 | | left_max = right_min; [INFO] [stdout] 123 | | right_min = tmp; [INFO] [stdout] | |___________________________________^ help: try: `std::mem::swap(&mut left_max, &mut right_min);` [INFO] [stdout] | [INFO] [stdout] = note: or maybe you should use `std::mem::replace`? [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap [INFO] [stdout] = note: `#[warn(clippy::manual_swap)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0024_swap_nodes_in_pairs/mod.rs:64:19 [INFO] [stdout] | [INFO] [stdout] 64 | None => { return None; }, [INFO] [stdout] | ^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 64 - None => { return None; }, [INFO] [stdout] 64 + None => { None}, [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0024_swap_nodes_in_pairs/mod.rs:66:23 [INFO] [stdout] | [INFO] [stdout] 66 | None => { return Some(inner_h); }, [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 66 - None => { return Some(inner_h); }, [INFO] [stdout] 66 + None => { Some(inner_h)}, [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0037_sudoku_solver/mod.rs:184:5 [INFO] [stdout] | [INFO] [stdout] 184 | return true; [INFO] [stdout] | ^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 184 - return true; [INFO] [stdout] 184 + true [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this expression creates a reference which is immediately dereferenced by the compiler [INFO] [stdout] --> src/cd0037_sudoku_solver/mod.rs:172:30 [INFO] [stdout] | [INFO] [stdout] 172 | if !is_valid(&board, row, col, c) { continue; } [INFO] [stdout] | ^^^^^^ help: change this to: `board` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow [INFO] [stdout] = note: `#[warn(clippy::needless_borrow)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do [INFO] [stdout] --> src/cd0037_sudoku_solver/mod.rs:187:24 [INFO] [stdout] | [INFO] [stdout] 187 | pub fn is_valid(board: &Vec>, row: usize, col: usize, c: char) -> bool { [INFO] [stdout] | ^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg [INFO] [stdout] = note: `#[warn(clippy::ptr_arg)]` on by default [INFO] [stdout] help: change this to [INFO] [stdout] | [INFO] [stdout] 187 - pub fn is_valid(board: &Vec>, row: usize, col: usize, c: char) -> bool { [INFO] [stdout] 187 + pub fn is_valid(board: &[Vec], row: usize, col: usize, c: char) -> bool { [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0050_powx_n/mod.rs:96:9 [INFO] [stdout] | [INFO] [stdout] 96 | return half * half; [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 96 - return half * half; [INFO] [stdout] 96 + half * half [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0050_powx_n/mod.rs:98:9 [INFO] [stdout] | [INFO] [stdout] 98 | return half * half * x; [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 98 - return half * half * x; [INFO] [stdout] 98 + half * half * x [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this OR pattern can be rewritten using a range [INFO] [stdout] --> src/cd0070_climbing_stairs/mod.rs:104:9 [INFO] [stdout] | [INFO] [stdout] 104 | 0 | 1 | 2 => n, [INFO] [stdout] | ^^^^^^^^^ help: try: `0..=2` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_patterns [INFO] [stdout] = note: `#[warn(clippy::manual_range_patterns)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: the loop variable `i` is used to index `dp` [INFO] [stdout] --> src/cd0072_edit_distance/mod.rs:126:14 [INFO] [stdout] | [INFO] [stdout] 126 | for i in 0..=m { dp[i][0] = i; } [INFO] [stdout] | ^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop [INFO] [stdout] = note: `#[warn(clippy::needless_range_loop)]` on by default [INFO] [stdout] help: consider using an iterator and enumerate() [INFO] [stdout] | [INFO] [stdout] 126 - for i in 0..=m { dp[i][0] = i; } [INFO] [stdout] 126 + for (i, ) in dp.iter_mut().enumerate().take(m + 1) { dp[i][0] = i; } [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: the loop variable `j` is used to index `dp` [INFO] [stdout] --> src/cd0072_edit_distance/mod.rs:128:14 [INFO] [stdout] | [INFO] [stdout] 128 | for j in 0..=n { dp[0][j] = j; } [INFO] [stdout] | ^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop [INFO] [stdout] help: consider using an iterator and enumerate() [INFO] [stdout] | [INFO] [stdout] 128 - for j in 0..=n { dp[0][j] = j; } [INFO] [stdout] 128 + for (j, ) in dp.iter_mut().enumerate().take(n + 1) { dp[0][j] = j; } [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0001_two_sum/mod.rs:92:5 [INFO] [stdout] | [INFO] [stdout] 92 | return vec![]; [INFO] [stdout] | ^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] = note: `#[warn(clippy::needless_return)]` on by default [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 92 - return vec![]; [INFO] [stdout] 92 + vec![] [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: manual implementation of an assign operation [INFO] [stdout] --> src/cd0002_add_two_numbers/mod.rs:93:17 [INFO] [stdout] | [INFO] [stdout] 93 | sum = sum % 10; [INFO] [stdout] | ^^^^^^^^^^^^^^ help: replace it with: `sum %= 10` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern [INFO] [stdout] = note: `#[warn(clippy::assign_op_pattern)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0098_validate_binary_search_tree/mod.rs:177:17 [INFO] [stdout] | [INFO] [stdout] 177 | return valid(&n.left, min_limit, Some(n.val)) && valid(&n.right, Some(n.val), max_limit); [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 177 - return valid(&n.left, min_limit, Some(n.val)) && valid(&n.right, Some(n.val), max_limit); [INFO] [stdout] 177 + valid(&n.left, min_limit, Some(n.val)) && valid(&n.right, Some(n.val), max_limit) [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this boolean expression can be simplified [INFO] [stdout] --> src/cd0102_binary_tree_level_order_traversal/mod.rs:163:20 [INFO] [stdout] | [INFO] [stdout] 163 | if !node.borrow().left.is_none() { deque.push_back(node.borrow().left.clone()); } [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `node.borrow().left.is_some()` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool [INFO] [stdout] = note: `#[warn(clippy::nonminimal_bool)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this boolean expression can be simplified [INFO] [stdout] --> src/cd0102_binary_tree_level_order_traversal/mod.rs:164:20 [INFO] [stdout] | [INFO] [stdout] 164 | if !node.borrow().right.is_none() { deque.push_back(node.borrow().right.clone()); } [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `node.borrow().right.is_some()` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: usage of a legacy numeric constant [INFO] [stdout] --> src/cd0004_median_of_two_sorted_arrays/mod.rs:110:45 [INFO] [stdout] | [INFO] [stdout] 110 | let first_left = if mid_first == 0 { std::i32::MIN } else { first[mid_first - 1] }; [INFO] [stdout] | ^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants [INFO] [stdout] = note: `#[warn(clippy::legacy_numeric_constants)]` on by default [INFO] [stdout] help: use the associated constant instead [INFO] [stdout] | [INFO] [stdout] 110 - let first_left = if mid_first == 0 { std::i32::MIN } else { first[mid_first - 1] }; [INFO] [stdout] 110 + let first_left = if mid_first == 0 { i32::MIN } else { first[mid_first - 1] }; [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: usage of a legacy numeric constant [INFO] [stdout] --> src/cd0004_median_of_two_sorted_arrays/mod.rs:111:46 [INFO] [stdout] | [INFO] [stdout] 111 | let first_right = if mid_first == m { std::i32::MAX } else { first[mid_first] }; [INFO] [stdout] | ^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants [INFO] [stdout] help: use the associated constant instead [INFO] [stdout] | [INFO] [stdout] 111 - let first_right = if mid_first == m { std::i32::MAX } else { first[mid_first] }; [INFO] [stdout] 111 + let first_right = if mid_first == m { i32::MAX } else { first[mid_first] }; [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: usage of a legacy numeric constant [INFO] [stdout] --> src/cd0004_median_of_two_sorted_arrays/mod.rs:112:47 [INFO] [stdout] | [INFO] [stdout] 112 | let second_left = if mid_second == 0 { std::i32::MIN } else { second[mid_second - 1] }; [INFO] [stdout] | ^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants [INFO] [stdout] help: use the associated constant instead [INFO] [stdout] | [INFO] [stdout] 112 - let second_left = if mid_second == 0 { std::i32::MIN } else { second[mid_second - 1] }; [INFO] [stdout] 112 + let second_left = if mid_second == 0 { i32::MIN } else { second[mid_second - 1] }; [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: usage of a legacy numeric constant [INFO] [stdout] --> src/cd0004_median_of_two_sorted_arrays/mod.rs:113:48 [INFO] [stdout] | [INFO] [stdout] 113 | let second_right = if mid_second == n { std::i32::MAX } else { second[mid_second] }; [INFO] [stdout] | ^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants [INFO] [stdout] help: use the associated constant instead [INFO] [stdout] | [INFO] [stdout] 113 - let second_right = if mid_second == n { std::i32::MAX } else { second[mid_second] }; [INFO] [stdout] 113 + let second_right = if mid_second == n { i32::MAX } else { second[mid_second] }; [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this looks like you are swapping `left_max` and `right_min` manually [INFO] [stdout] --> src/cd0004_median_of_two_sorted_arrays/mod.rs:121:20 [INFO] [stdout] | [INFO] [stdout] 121 | / let tmp = left_max; [INFO] [stdout] 122 | | left_max = right_min; [INFO] [stdout] 123 | | right_min = tmp; [INFO] [stdout] | |___________________________________^ help: try: `std::mem::swap(&mut left_max, &mut right_min);` [INFO] [stdout] | [INFO] [stdout] = note: or maybe you should use `std::mem::replace`? [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap [INFO] [stdout] = note: `#[warn(clippy::manual_swap)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: length comparison to zero [INFO] [stdout] --> src/cd0120_triangle/mod.rs:74:8 [INFO] [stdout] | [INFO] [stdout] 74 | if triangle.len() == 0 { return 0; } [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `triangle.is_empty()` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero [INFO] [stdout] = note: `#[warn(clippy::len_zero)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: doc list item without indentation [INFO] [stdout] --> src/cd0123_best_time_to_buy_and_sell_stock_iii/mod.rs:110:5 [INFO] [stdout] | [INFO] [stdout] 110 | /// transactions](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/discuss/39608/a-clean-dp-solution-which-general... [INFO] [stdout] | ^ [INFO] [stdout] | [INFO] [stdout] = help: if this is supposed to be its own paragraph, add a blank line [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation [INFO] [stdout] = note: `#[warn(clippy::doc_lazy_continuation)]` on by default [INFO] [stdout] help: indent this line [INFO] [stdout] | [INFO] [stdout] 110 | /// transactions](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/discuss/39608/a-clean-dp-solution-which-generalizes-to-k-transactions) [INFO] [stdout] | ++ [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: doc list item without indentation [INFO] [stdout] --> src/cd0123_best_time_to_buy_and_sell_stock_iii/mod.rs:112:5 [INFO] [stdout] | [INFO] [stdout] 112 | /// 中文注释](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/discuss/238936/Rust-generic-K-transactions-solution... [INFO] [stdout] | ^ [INFO] [stdout] | [INFO] [stdout] = help: if this is supposed to be its own paragraph, add a blank line [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation [INFO] [stdout] help: indent this line [INFO] [stdout] | [INFO] [stdout] 112 | /// 中文注释](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/discuss/238936/Rust-generic-K-transactions-solution-with-O(N)-time-and-O(N)-space) [INFO] [stdout] | ++ [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0024_swap_nodes_in_pairs/mod.rs:64:19 [INFO] [stdout] | [INFO] [stdout] 64 | None => { return None; }, [INFO] [stdout] | ^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 64 - None => { return None; }, [INFO] [stdout] 64 + None => { None}, [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0024_swap_nodes_in_pairs/mod.rs:66:23 [INFO] [stdout] | [INFO] [stdout] 66 | None => { return Some(inner_h); }, [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 66 - None => { return Some(inner_h); }, [INFO] [stdout] 66 + None => { Some(inner_h)}, [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` [INFO] [stdout] --> src/cd0152_maximum_product_subarray/mod.rs:145:27 [INFO] [stdout] | [INFO] [stdout] 145 | for &num in nums[1..].into_iter() { [INFO] [stdout] | ^^^^^^^^^ help: call directly: `iter` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref [INFO] [stdout] = note: `#[warn(clippy::into_iter_on_ref)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0037_sudoku_solver/mod.rs:184:5 [INFO] [stdout] | [INFO] [stdout] 184 | return true; [INFO] [stdout] | ^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 184 - return true; [INFO] [stdout] 184 + true [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this expression creates a reference which is immediately dereferenced by the compiler [INFO] [stdout] --> src/cd0037_sudoku_solver/mod.rs:172:30 [INFO] [stdout] | [INFO] [stdout] 172 | if !is_valid(&board, row, col, c) { continue; } [INFO] [stdout] | ^^^^^^ help: change this to: `board` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow [INFO] [stdout] = note: `#[warn(clippy::needless_borrow)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do [INFO] [stdout] --> src/cd0037_sudoku_solver/mod.rs:187:24 [INFO] [stdout] | [INFO] [stdout] 187 | pub fn is_valid(board: &Vec>, row: usize, col: usize, c: char) -> bool { [INFO] [stdout] | ^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg [INFO] [stdout] = note: `#[warn(clippy::ptr_arg)]` on by default [INFO] [stdout] help: change this to [INFO] [stdout] | [INFO] [stdout] 187 - pub fn is_valid(board: &Vec>, row: usize, col: usize, c: char) -> bool { [INFO] [stdout] 187 + pub fn is_valid(board: &[Vec], row: usize, col: usize, c: char) -> bool { [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0050_powx_n/mod.rs:96:9 [INFO] [stdout] | [INFO] [stdout] 96 | return half * half; [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 96 - return half * half; [INFO] [stdout] 96 + half * half [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do [INFO] [stdout] --> src/cd0200_number_of_islands/mod.rs:205:18 [INFO] [stdout] | [INFO] [stdout] 205 | fn new(grid: &Vec>) -> Self { [INFO] [stdout] | ^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg [INFO] [stdout] help: change this to [INFO] [stdout] | [INFO] [stdout] 205 - fn new(grid: &Vec>) -> Self { [INFO] [stdout] 205 + fn new(grid: &[Vec]) -> Self { [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0050_powx_n/mod.rs:98:9 [INFO] [stdout] | [INFO] [stdout] 98 | return half * half * x; [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 98 - return half * half * x; [INFO] [stdout] 98 + half * half * x [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this block may be rewritten with the `?` operator [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:63:5 [INFO] [stdout] | [INFO] [stdout] 63 | if head.is_none() { return None; } [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `head.as_ref()?;` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark [INFO] [stdout] = note: `#[warn(clippy::question_mark)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: length comparison to zero [INFO] [stdout] --> src/cd0212_word_search_ii/mod.rs:116:34 [INFO] [stdout] | [INFO] [stdout] 116 | if rows == 0 || cols == 0 || words.len() == 0 { return vec![]; } [INFO] [stdout] | ^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `words.is_empty()` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting a character literal to `u8` truncates [INFO] [stdout] --> src/cd0212_word_search_ii/mod.rs:139:61 [INFO] [stdout] | [INFO] [stdout] 139 | if let Some(node) = trie.nodes[(board[row][col] as u8 - 'a' as u8) as usize].as_ref() { [INFO] [stdout] | ^^^^^^^^^ help: use a byte literal instead: `b'a'` [INFO] [stdout] | [INFO] [stdout] = note: `char` is four bytes wide, but `u8` is a single byte [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#char_lit_as_u8 [INFO] [stdout] = note: `#[warn(clippy::char_lit_as_u8)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this OR pattern can be rewritten using a range [INFO] [stdout] --> src/cd0070_climbing_stairs/mod.rs:104:9 [INFO] [stdout] | [INFO] [stdout] 104 | 0 | 1 | 2 => n, [INFO] [stdout] | ^^^^^^^^^ help: try: `0..=2` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_patterns [INFO] [stdout] = note: `#[warn(clippy::manual_range_patterns)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: the loop variable `i` is used to index `dp` [INFO] [stdout] --> src/cd0072_edit_distance/mod.rs:126:14 [INFO] [stdout] | [INFO] [stdout] 126 | for i in 0..=m { dp[i][0] = i; } [INFO] [stdout] | ^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop [INFO] [stdout] = note: `#[warn(clippy::needless_range_loop)]` on by default [INFO] [stdout] help: consider using an iterator and enumerate() [INFO] [stdout] | [INFO] [stdout] 126 - for i in 0..=m { dp[i][0] = i; } [INFO] [stdout] 126 + for (i, ) in dp.iter_mut().enumerate().take(m + 1) { dp[i][0] = i; } [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: the loop variable `j` is used to index `dp` [INFO] [stdout] --> src/cd0072_edit_distance/mod.rs:128:14 [INFO] [stdout] | [INFO] [stdout] 128 | for j in 0..=n { dp[0][j] = j; } [INFO] [stdout] | ^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop [INFO] [stdout] help: consider using an iterator and enumerate() [INFO] [stdout] | [INFO] [stdout] 128 - for j in 0..=n { dp[0][j] = j; } [INFO] [stdout] 128 + for (j, ) in dp.iter_mut().enumerate().take(n + 1) { dp[0][j] = j; } [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting a character literal to `u8` truncates [INFO] [stdout] --> src/cd0212_word_search_ii/mod.rs:170:56 [INFO] [stdout] | [INFO] [stdout] 170 | for i in word.chars().map(|char| (char as u8 - 'a' as u8) as usize) { [INFO] [stdout] | ^^^^^^^^^ help: use a byte literal instead: `b'a'` [INFO] [stdout] | [INFO] [stdout] = note: `char` is four bytes wide, but `u8` is a single byte [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#char_lit_as_u8 [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting a character literal to `u8` truncates [INFO] [stdout] --> src/cd0224_basic_calculator/mod.rs:89:54 [INFO] [stdout] | [INFO] [stdout] 89 | operand = 10 * operand + (ch as u8 - '0' as u8) as i32; [INFO] [stdout] | ^^^^^^^^^ help: use a byte literal instead: `b'0'` [INFO] [stdout] | [INFO] [stdout] = note: `char` is four bytes wide, but `u8` is a single byte [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#char_lit_as_u8 [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this if-then-else expression returns a bool literal [INFO] [stdout] --> src/cd0231_power_of_two/mod.rs:48:5 [INFO] [stdout] | [INFO] [stdout] 48 | if n > 0 && (n & (n - 1) == 0) { true } else { false } [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `n > 0 && (n & (n - 1) == 0)` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_bool [INFO] [stdout] = note: `#[warn(clippy::needless_bool)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0098_validate_binary_search_tree/mod.rs:177:17 [INFO] [stdout] | [INFO] [stdout] 177 | return valid(&n.left, min_limit, Some(n.val)) && valid(&n.right, Some(n.val), max_limit); [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 177 - return valid(&n.left, min_limit, Some(n.val)) && valid(&n.right, Some(n.val), max_limit); [INFO] [stdout] 177 + valid(&n.left, min_limit, Some(n.val)) && valid(&n.right, Some(n.val), max_limit) [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this boolean expression can be simplified [INFO] [stdout] --> src/cd0239_sliding_window_maximum/mod.rs:105:15 [INFO] [stdout] | [INFO] [stdout] 105 | while !deque.get(start).is_none() && nums[*deque.back().unwrap()] < nums[index] { [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `deque.get(start).is_some()` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this boolean expression can be simplified [INFO] [stdout] --> src/cd0102_binary_tree_level_order_traversal/mod.rs:163:20 [INFO] [stdout] | [INFO] [stdout] 163 | if !node.borrow().left.is_none() { deque.push_back(node.borrow().left.clone()); } [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `node.borrow().left.is_some()` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool [INFO] [stdout] = note: `#[warn(clippy::nonminimal_bool)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this boolean expression can be simplified [INFO] [stdout] --> src/cd0102_binary_tree_level_order_traversal/mod.rs:164:20 [INFO] [stdout] | [INFO] [stdout] 164 | if !node.borrow().right.is_none() { deque.push_back(node.borrow().right.clone()); } [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `node.borrow().right.is_some()` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting to the same type is unnecessary (`usize` -> `usize`) [INFO] [stdout] --> src/cd0239_sliding_window_maximum/mod.rs:104:21 [INFO] [stdout] | [INFO] [stdout] 104 | for index in 0..nums.len() as usize { [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^ help: try: `nums.len()` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast [INFO] [stdout] = note: `#[warn(clippy::unnecessary_cast)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: length comparison to zero [INFO] [stdout] --> src/cd0120_triangle/mod.rs:74:8 [INFO] [stdout] | [INFO] [stdout] 74 | if triangle.len() == 0 { return 0; } [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `triangle.is_empty()` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero [INFO] [stdout] = note: `#[warn(clippy::len_zero)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0322_coin_change/mod.rs:96:24 [INFO] [stdout] | [INFO] [stdout] 96 | if last > amount { return -1; } else { return last; } [INFO] [stdout] | ^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 96 - if last > amount { return -1; } else { return last; } [INFO] [stdout] 96 + if last > amount { -1} else { return last; } [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0322_coin_change/mod.rs:96:44 [INFO] [stdout] | [INFO] [stdout] 96 | if last > amount { return -1; } else { return last; } [INFO] [stdout] | ^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 96 - if last > amount { return -1; } else { return last; } [INFO] [stdout] 96 + if last > amount { return -1; } else { last} [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting integer literal to `usize` is unnecessary [INFO] [stdout] --> src/cd0367_valid_perfect_square/mod.rs:54:20 [INFO] [stdout] | [INFO] [stdout] 54 | let mut left = 1 as usize; [INFO] [stdout] | ^^^^^^^^^^ help: try: `1_usize` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: doc list item without indentation [INFO] [stdout] --> src/cd0123_best_time_to_buy_and_sell_stock_iii/mod.rs:110:5 [INFO] [stdout] | [INFO] [stdout] 110 | /// transactions](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/discuss/39608/a-clean-dp-solution-which-general... [INFO] [stdout] | ^ [INFO] [stdout] | [INFO] [stdout] = help: if this is supposed to be its own paragraph, add a blank line [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation [INFO] [stdout] = note: `#[warn(clippy::doc_lazy_continuation)]` on by default [INFO] [stdout] help: indent this line [INFO] [stdout] | [INFO] [stdout] 110 | /// transactions](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/discuss/39608/a-clean-dp-solution-which-generalizes-to-k-transactions) [INFO] [stdout] | ++ [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: doc list item without indentation [INFO] [stdout] --> src/cd0123_best_time_to_buy_and_sell_stock_iii/mod.rs:112:5 [INFO] [stdout] | [INFO] [stdout] 112 | /// 中文注释](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/discuss/238936/Rust-generic-K-transactions-solution... [INFO] [stdout] | ^ [INFO] [stdout] | [INFO] [stdout] = help: if this is supposed to be its own paragraph, add a blank line [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation [INFO] [stdout] help: indent this line [INFO] [stdout] | [INFO] [stdout] 112 | /// 中文注释](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/discuss/238936/Rust-generic-K-transactions-solution-with-O(N)-time-and-O(N)-space) [INFO] [stdout] | ++ [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting integer literal to `usize` is unnecessary [INFO] [stdout] --> src/cd0367_valid_perfect_square/mod.rs:58:36 [INFO] [stdout] | [INFO] [stdout] 58 | let mid = (right - left) / 2 as usize + left; [INFO] [stdout] | ^^^^^^^^^^ help: try: `2_usize` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting integer literal to `usize` is unnecessary [INFO] [stdout] --> src/cd0367_valid_perfect_square/mod.rs:60:44 [INFO] [stdout] | [INFO] [stdout] 60 | if mid * mid > num { right = mid - 1 as usize; } else { left = mid + 1 as usize; } [INFO] [stdout] | ^^^^^^^^^^ help: try: `1_usize` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting integer literal to `usize` is unnecessary [INFO] [stdout] --> src/cd0367_valid_perfect_square/mod.rs:60:78 [INFO] [stdout] | [INFO] [stdout] 60 | if mid * mid > num { right = mid - 1 as usize; } else { left = mid + 1 as usize; } [INFO] [stdout] | ^^^^^^^^^^ help: try: `1_usize` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: the loop variable `i` is used to index `m` [INFO] [stdout] --> src/cd0547_friend_circles/mod.rs:144:14 [INFO] [stdout] | [INFO] [stdout] 144 | for i in 0..n { [INFO] [stdout] | ^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop [INFO] [stdout] help: consider using an iterator and enumerate() [INFO] [stdout] | [INFO] [stdout] 144 - for i in 0..n { [INFO] [stdout] 144 + for (i, ) in m.iter().enumerate().take(n) { [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: the loop variable `j` is used to index `m` [INFO] [stdout] --> src/cd0547_friend_circles/mod.rs:145:18 [INFO] [stdout] | [INFO] [stdout] 145 | for j in 0..n { [INFO] [stdout] | ^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop [INFO] [stdout] help: consider using an iterator and enumerate() [INFO] [stdout] | [INFO] [stdout] 145 - for j in 0..n { [INFO] [stdout] 145 + for (j, ) in m.iter().enumerate().take(n) { [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do [INFO] [stdout] --> src/cd0547_friend_circles/mod.rs:159:18 [INFO] [stdout] | [INFO] [stdout] 159 | fn new(grid: &Vec>) -> Self { [INFO] [stdout] | ^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg [INFO] [stdout] help: change this to [INFO] [stdout] | [INFO] [stdout] 159 - fn new(grid: &Vec>) -> Self { [INFO] [stdout] 159 + fn new(grid: &[Vec]) -> Self { [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` [INFO] [stdout] --> src/cd0152_maximum_product_subarray/mod.rs:145:27 [INFO] [stdout] | [INFO] [stdout] 145 | for &num in nums[1..].into_iter() { [INFO] [stdout] | ^^^^^^^^^ help: call directly: `iter` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref [INFO] [stdout] = note: `#[warn(clippy::into_iter_on_ref)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: the loop variable `i` is only used to index `prices` [INFO] [stdout] --> src/cd0714_best_time_to_buy_and_sell_stock_with_transaction_fee/mod.rs:122:14 [INFO] [stdout] | [INFO] [stdout] 122 | for i in 1..prices.len() { [INFO] [stdout] | ^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop [INFO] [stdout] help: consider using an iterator [INFO] [stdout] | [INFO] [stdout] 122 - for i in 1..prices.len() { [INFO] [stdout] 122 + for in prices.iter().skip(1) { [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do [INFO] [stdout] --> src/cd0200_number_of_islands/mod.rs:205:18 [INFO] [stdout] | [INFO] [stdout] 205 | fn new(grid: &Vec>) -> Self { [INFO] [stdout] | ^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg [INFO] [stdout] help: change this to [INFO] [stdout] | [INFO] [stdout] 205 - fn new(grid: &Vec>) -> Self { [INFO] [stdout] 205 + fn new(grid: &[Vec]) -> Self { [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this block may be rewritten with the `?` operator [INFO] [stdout] --> src/cd0206_reverse_linked_list/mod.rs:63:5 [INFO] [stdout] | [INFO] [stdout] 63 | if head.is_none() { return None; } [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `head.as_ref()?;` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark [INFO] [stdout] = note: `#[warn(clippy::question_mark)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: length comparison to zero [INFO] [stdout] --> src/cd0212_word_search_ii/mod.rs:116:34 [INFO] [stdout] | [INFO] [stdout] 116 | if rows == 0 || cols == 0 || words.len() == 0 { return vec![]; } [INFO] [stdout] | ^^^^^^^^^^^^^^^^ help: using `is_empty` is clearer and more explicit: `words.is_empty()` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting a character literal to `u8` truncates [INFO] [stdout] --> src/cd0212_word_search_ii/mod.rs:139:61 [INFO] [stdout] | [INFO] [stdout] 139 | if let Some(node) = trie.nodes[(board[row][col] as u8 - 'a' as u8) as usize].as_ref() { [INFO] [stdout] | ^^^^^^^^^ help: use a byte literal instead: `b'a'` [INFO] [stdout] | [INFO] [stdout] = note: `char` is four bytes wide, but `u8` is a single byte [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#char_lit_as_u8 [INFO] [stdout] = note: `#[warn(clippy::char_lit_as_u8)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting a character literal to `u8` truncates [INFO] [stdout] --> src/cd0212_word_search_ii/mod.rs:170:56 [INFO] [stdout] | [INFO] [stdout] 170 | for i in word.chars().map(|char| (char as u8 - 'a' as u8) as usize) { [INFO] [stdout] | ^^^^^^^^^ help: use a byte literal instead: `b'a'` [INFO] [stdout] | [INFO] [stdout] = note: `char` is four bytes wide, but `u8` is a single byte [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#char_lit_as_u8 [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting a character literal to `u8` truncates [INFO] [stdout] --> src/cd0224_basic_calculator/mod.rs:89:54 [INFO] [stdout] | [INFO] [stdout] 89 | operand = 10 * operand + (ch as u8 - '0' as u8) as i32; [INFO] [stdout] | ^^^^^^^^^ help: use a byte literal instead: `b'0'` [INFO] [stdout] | [INFO] [stdout] = note: `char` is four bytes wide, but `u8` is a single byte [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#char_lit_as_u8 [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this if-then-else expression returns a bool literal [INFO] [stdout] --> src/cd0231_power_of_two/mod.rs:48:5 [INFO] [stdout] | [INFO] [stdout] 48 | if n > 0 && (n & (n - 1) == 0) { true } else { false } [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can reduce it to: `n > 0 && (n & (n - 1) == 0)` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_bool [INFO] [stdout] = note: `#[warn(clippy::needless_bool)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: this boolean expression can be simplified [INFO] [stdout] --> src/cd0239_sliding_window_maximum/mod.rs:105:15 [INFO] [stdout] | [INFO] [stdout] 105 | while !deque.get(start).is_none() && nums[*deque.back().unwrap()] < nums[index] { [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `deque.get(start).is_some()` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#nonminimal_bool [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting to the same type is unnecessary (`usize` -> `usize`) [INFO] [stdout] --> src/cd0239_sliding_window_maximum/mod.rs:104:21 [INFO] [stdout] | [INFO] [stdout] 104 | for index in 0..nums.len() as usize { [INFO] [stdout] | ^^^^^^^^^^^^^^^^^^^ help: try: `nums.len()` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast [INFO] [stdout] = note: `#[warn(clippy::unnecessary_cast)]` on by default [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0322_coin_change/mod.rs:96:24 [INFO] [stdout] | [INFO] [stdout] 96 | if last > amount { return -1; } else { return last; } [INFO] [stdout] | ^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 96 - if last > amount { return -1; } else { return last; } [INFO] [stdout] 96 + if last > amount { -1} else { return last; } [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: unneeded `return` statement [INFO] [stdout] --> src/cd0322_coin_change/mod.rs:96:44 [INFO] [stdout] | [INFO] [stdout] 96 | if last > amount { return -1; } else { return last; } [INFO] [stdout] | ^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_return [INFO] [stdout] help: remove `return` [INFO] [stdout] | [INFO] [stdout] 96 - if last > amount { return -1; } else { return last; } [INFO] [stdout] 96 + if last > amount { return -1; } else { last} [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting integer literal to `usize` is unnecessary [INFO] [stdout] --> src/cd0367_valid_perfect_square/mod.rs:54:20 [INFO] [stdout] | [INFO] [stdout] 54 | let mut left = 1 as usize; [INFO] [stdout] | ^^^^^^^^^^ help: try: `1_usize` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting integer literal to `usize` is unnecessary [INFO] [stdout] --> src/cd0367_valid_perfect_square/mod.rs:58:36 [INFO] [stdout] | [INFO] [stdout] 58 | let mid = (right - left) / 2 as usize + left; [INFO] [stdout] | ^^^^^^^^^^ help: try: `2_usize` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting integer literal to `usize` is unnecessary [INFO] [stdout] --> src/cd0367_valid_perfect_square/mod.rs:60:44 [INFO] [stdout] | [INFO] [stdout] 60 | if mid * mid > num { right = mid - 1 as usize; } else { left = mid + 1 as usize; } [INFO] [stdout] | ^^^^^^^^^^ help: try: `1_usize` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: casting integer literal to `usize` is unnecessary [INFO] [stdout] --> src/cd0367_valid_perfect_square/mod.rs:60:78 [INFO] [stdout] | [INFO] [stdout] 60 | if mid * mid > num { right = mid - 1 as usize; } else { left = mid + 1 as usize; } [INFO] [stdout] | ^^^^^^^^^^ help: try: `1_usize` [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: the loop variable `i` is used to index `m` [INFO] [stdout] --> src/cd0547_friend_circles/mod.rs:144:14 [INFO] [stdout] | [INFO] [stdout] 144 | for i in 0..n { [INFO] [stdout] | ^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop [INFO] [stdout] help: consider using an iterator and enumerate() [INFO] [stdout] | [INFO] [stdout] 144 - for i in 0..n { [INFO] [stdout] 144 + for (i, ) in m.iter().enumerate().take(n) { [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: the loop variable `j` is used to index `m` [INFO] [stdout] --> src/cd0547_friend_circles/mod.rs:145:18 [INFO] [stdout] | [INFO] [stdout] 145 | for j in 0..n { [INFO] [stdout] | ^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop [INFO] [stdout] help: consider using an iterator and enumerate() [INFO] [stdout] | [INFO] [stdout] 145 - for j in 0..n { [INFO] [stdout] 145 + for (j, ) in m.iter().enumerate().take(n) { [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do [INFO] [stdout] --> src/cd0547_friend_circles/mod.rs:159:18 [INFO] [stdout] | [INFO] [stdout] 159 | fn new(grid: &Vec>) -> Self { [INFO] [stdout] | ^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg [INFO] [stdout] help: change this to [INFO] [stdout] | [INFO] [stdout] 159 - fn new(grid: &Vec>) -> Self { [INFO] [stdout] 159 + fn new(grid: &[Vec]) -> Self { [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stdout] warning: the loop variable `i` is only used to index `prices` [INFO] [stdout] --> src/cd0714_best_time_to_buy_and_sell_stock_with_transaction_fee/mod.rs:122:14 [INFO] [stdout] | [INFO] [stdout] 122 | for i in 1..prices.len() { [INFO] [stdout] | ^^^^^^^^^^^^^^^ [INFO] [stdout] | [INFO] [stdout] = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop [INFO] [stdout] help: consider using an iterator [INFO] [stdout] | [INFO] [stdout] 122 - for i in 1..prices.len() { [INFO] [stdout] 122 + for in prices.iter().skip(1) { [INFO] [stdout] | [INFO] [stdout] [INFO] [stdout] [INFO] [stderr] Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.63s [INFO] running `Command { std: "docker" "inspect" "9e78ffba6e47a9c558413cde3abe0ab19910451730ac119325cb59f75d25168b", kill_on_drop: false }` [INFO] running `Command { std: "docker" "rm" "-f" "9e78ffba6e47a9c558413cde3abe0ab19910451730ac119325cb59f75d25168b", kill_on_drop: false }` [INFO] [stdout] 9e78ffba6e47a9c558413cde3abe0ab19910451730ac119325cb59f75d25168b