Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lcp/main.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"scripts": {
"postinstall": "pip install -r requirements.txt",
"prepare": "husky"
},
"devDependencies": {
Expand All @@ -14,7 +15,7 @@
},
"lint-staged": {
"*.{js,ts,php,sql,md}": "prettier --write",
"*.py": "black -S",
"*.py": "py -m black -S",
"*.rs": "rustfmt"
},
"packageManager": "pnpm@10.25.0"
Expand Down
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
black==26.3.1
Requests==2.33.0
black
PyYAML
Requests
urllib3
6 changes: 5 additions & 1 deletion solution/0000-0099/0085.Maximal Rectangle/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ impl Solution {
break;
}
}
left[i] = if stk.is_empty() { -1 } else { stk[stk.len() - 1] as i32 };
left[i] = if stk.is_empty() {
-1
} else {
stk[stk.len() - 1] as i32
};
stk.push(i);
}

Expand Down
2 changes: 1 addition & 1 deletion solution/0700-0799/0799.Champagne Tower/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ impl Solution {
}
f[query_row as usize][query_glass as usize]
}
}
}
2 changes: 1 addition & 1 deletion solution/0700-0799/0799.Champagne Tower/Solution2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ impl Solution {
}
f[query_glass as usize].min(1.0)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ impl Solution {
pub fn subtree_with_all_deepest(
root: Option<Rc<RefCell<TreeNode>>>,
) -> Option<Rc<RefCell<TreeNode>>> {
fn dfs(
root: Option<Rc<RefCell<TreeNode>>>,
) -> (Option<Rc<RefCell<TreeNode>>>, i32) {
fn dfs(root: Option<Rc<RefCell<TreeNode>>>) -> (Option<Rc<RefCell<TreeNode>>>, i32) {
if let Some(node) = root {
let left = node.borrow().left.clone();
let right = node.borrow().right.clone();
Expand Down
5 changes: 2 additions & 3 deletions solution/0800-0899/0877.Stone Game/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ impl Solution {

fn dfs(i: usize, j: usize, piles: &Vec<i32>, f: &mut Vec<Vec<i32>>) -> i32 {
if i == j {
return piles[i]
return piles[i];
}
if f[i][j] != 0 {
return f[i][j];
}

let res = (piles[i] - dfs(i + 1, j, piles, f))
.max(piles[j] - dfs(i, j - 1, piles, f));
let res = (piles[i] - dfs(i + 1, j, piles, f)).max(piles[j] - dfs(i, j - 1, piles, f));

f[i][j] = res;
res
Expand Down
3 changes: 1 addition & 2 deletions solution/0800-0899/0877.Stone Game/Solution2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ impl Solution {

for i in (0..n - 1).rev() {
for j in i + 1..n {
f[i][j] = (piles[i] - f[i + 1][j])
.max(piles[j] - f[i][j - 1]);
f[i][j] = (piles[i] - f[i + 1][j]).max(piles[j] - f[i][j - 1]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// }
// }
// }
use std::rc::Rc;
use std::cell::RefCell;
use std::rc::Rc;

impl Solution {
pub fn sum_root_to_leaf(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
// }
// }
use std::cell::RefCell;
use std::rc::Rc;
use std::collections::VecDeque;
use std::rc::Rc;
impl Solution {
pub fn max_level_sum(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
let mut q = VecDeque::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ impl Hashing {
}

fn query(&self, l: usize, r: usize) -> u64 {
let mut res =
self.h[r + 1] + self.modv - (self.h[l] * self.p[r - l + 1] % self.modv);
let mut res = self.h[r + 1] + self.modv - (self.h[l] * self.p[r - l + 1] % self.modv);
res %= self.modv;
res
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// }
// }
// }
use std::rc::Rc;
use std::cell::RefCell;
use std::rc::Rc;

impl Solution {
pub fn max_product(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
Expand All @@ -33,9 +33,7 @@ impl Solution {
return 0;
}
let node = root.as_ref().unwrap().borrow();
let t = node.val as i64
+ Self::dfs(&node.left, s, ans)
+ Self::dfs(&node.right, s, ans);
let t = node.val as i64 + Self::dfs(&node.left, s, ans) + Self::dfs(&node.right, s, ans);
if t < s {
*ans = (*ans).max(t * (s - t));
}
Expand Down
6 changes: 5 additions & 1 deletion solution/1300-1399/1390.Four Divisors/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ impl Solution {
}
i += 1;
}
if cnt == 4 { s } else { 0 }
if cnt == 4 {
s
} else {
0
}
};
let mut ans = 0;
for x in nums {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashSet, HashMap};
use std::collections::{HashMap, HashSet};

impl Solution {
pub fn num_of_ways(n: i32) -> i32 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ impl Solution {
}
}

if dfs(n, k) == 0 { '0' } else { '1' }
if dfs(n, k) == 0 {
'0'
} else {
'1'
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
impl Solution {
pub fn min_partitions(n: String) -> i32 {
n.as_bytes().iter().fold(0, |ans, &c| ans.max((c - b'0') as i32))
n.as_bytes()
.iter()
.fold(0, |ans, &c| ans.max((c - b'0') as i32))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ impl Solution {

for i in 1..=m {
for j in 1..=n {
let l = (i - 1)
.min(m - i)
.min(j - 1)
.min(n - j);
let l = (i - 1).min(m - i).min(j - 1).min(n - j);

ss.insert(grid[i - 1][j - 1]);

Expand All @@ -32,9 +29,7 @@ impl Solution {
let c = s2[i][j - k] - s2[i - k][j];
let d = s2[i + k][j] - s2[i][j + k];

let v = a + b + c + d
- grid[i + k - 1][j - 1]
+ grid[i - k - 1][j - 1];
let v = a + b + c + d - grid[i + k - 1][j - 1] + grid[i - k - 1][j - 1];

ss.insert(v);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ impl Solution {
ans = ans.min(t.min(n - t));
}
}
if ans == n { -1 } else { ans }
if ans == n {
-1
} else {
ans
}
}
}
2 changes: 1 addition & 1 deletion solution/2700-2799/2751.Robot Collisions/Solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ impl Solution {
pub fn survived_robots_healths(
positions: Vec<i32>,
mut healths: Vec<i32>,
directions: String
directions: String,
) -> Vec<i32> {
let n = positions.len();
let mut idx: Vec<usize> = (0..n).collect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ impl Solution {
}

let ans = dfs(0, &nums, target, &mut f);
if ans < 0 { -1 } else { ans }
if ans < 0 {
-1
} else {
ans
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
impl Solution {
pub fn max_k_divisible_components(n: i32, edges: Vec<Vec<i32>>, values: Vec<i32>, k: i32) -> i32 {
pub fn max_k_divisible_components(
n: i32,
edges: Vec<Vec<i32>>,
values: Vec<i32>,
k: i32,
) -> i32 {
let n = n as usize;
let mut g = vec![vec![]; n];
for e in edges {
Expand All @@ -11,7 +16,14 @@ impl Solution {

let mut ans = 0;

fn dfs(i: usize, fa: i32, g: &Vec<Vec<usize>>, values: &Vec<i32>, k: i32, ans: &mut i32) -> i64 {
fn dfs(
i: usize,
fa: i32,
g: &Vec<Vec<usize>>,
values: &Vec<i32>,
k: i32,
ans: &mut i32,
) -> i64 {
let mut s = values[i] as i64;
for &j in &g[i] {
if j as i32 != fa {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ impl Solution {
}

let ans = dfs(0, &s, &t, &root, &g, &mut f, inf);
if ans >= inf { -1 } else { ans }
if ans >= inf {
-1
} else {
ans
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ impl Solution {
}
}

fn l2r(
l: &mut BTreeMap<i32, i32>,
r: &mut BTreeMap<i32, i32>,
s: &mut i64,
size: &mut usize,
) {
fn l2r(l: &mut BTreeMap<i32, i32>, r: &mut BTreeMap<i32, i32>, s: &mut i64, size: &mut usize) {
let x = *l.iter().next_back().unwrap().0;
*s -= x as i64;

Expand All @@ -85,12 +80,7 @@ fn l2r(
*r.entry(x).or_insert(0) += 1;
}

fn r2l(
l: &mut BTreeMap<i32, i32>,
r: &mut BTreeMap<i32, i32>,
s: &mut i64,
size: &mut usize,
) {
fn r2l(l: &mut BTreeMap<i32, i32>, r: &mut BTreeMap<i32, i32>, s: &mut i64, size: &mut usize) {
let x = *r.iter().next().unwrap().0;

if let Some(v) = r.get_mut(&x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ impl Solution {
for i in 1..=m {
for j in 1..=n {
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + grid[i - 1][j - 1];
if s[i][j] <= k { ans += 1; }
if s[i][j] <= k {
ans += 1;
}
}
}
ans
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ impl Solution {
pub fn number_of_stable_arrays(zero: i32, one: i32, limit: i32) -> i32 {
const MOD: i64 = 1_000_000_007;

fn dfs(
i: i32,
j: i32,
k: usize,
limit: i32,
f: &mut Vec<Vec<[i64; 2]>>,
) -> i64 {
fn dfs(i: i32, j: i32, k: usize, limit: i32, f: &mut Vec<Vec<[i64; 2]>>) -> i64 {
if i < 0 || j < 0 {
return 0;
}
Expand All @@ -28,19 +22,15 @@ impl Solution {
}

let res = if k == 0 {
(
dfs(i - 1, j, 0, limit, f)
+ dfs(i - 1, j, 1, limit, f)
(dfs(i - 1, j, 0, limit, f) + dfs(i - 1, j, 1, limit, f)
- dfs(i - limit - 1, j, 1, limit, f)
+ MOD
) % MOD
+ MOD)
% MOD
} else {
(
dfs(i, j - 1, 0, limit, f)
+ dfs(i, j - 1, 1, limit, f)
(dfs(i, j - 1, 0, limit, f) + dfs(i, j - 1, 1, limit, f)
- dfs(i, j - limit - 1, 0, limit, f)
+ MOD
) % MOD
+ MOD)
% MOD
};

f[iu][ju][k] = res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ impl Solution {
pub fn number_of_stable_arrays(zero: i32, one: i32, limit: i32) -> i32 {
const MOD: i64 = 1_000_000_007;

fn dfs(
i: i32,
j: i32,
k: usize,
limit: i32,
f: &mut Vec<Vec<[i64; 2]>>,
) -> i64 {
fn dfs(i: i32, j: i32, k: usize, limit: i32, f: &mut Vec<Vec<[i64; 2]>>) -> i64 {
if i < 0 || j < 0 {
return 0;
}
Expand All @@ -28,19 +22,15 @@ impl Solution {
}

let res = if k == 0 {
(
dfs(i - 1, j, 0, limit, f)
+ dfs(i - 1, j, 1, limit, f)
(dfs(i - 1, j, 0, limit, f) + dfs(i - 1, j, 1, limit, f)
- dfs(i - limit - 1, j, 1, limit, f)
+ MOD
) % MOD
+ MOD)
% MOD
} else {
(
dfs(i, j - 1, 0, limit, f)
+ dfs(i, j - 1, 1, limit, f)
(dfs(i, j - 1, 0, limit, f) + dfs(i, j - 1, 1, limit, f)
- dfs(i, j - limit - 1, 0, limit, f)
+ MOD
) % MOD
+ MOD)
% MOD
};

f[iu][ju][k] = res;
Expand Down
Loading