Compare commits

...
96 Commits
Author SHA1 Message Date
li_chx 551db6decf 72. 编辑距离 2026-08-13 11:16:29 +08:00
li_chx c1fe8fd658 215. 数组中的第K个最大元素 2026-08-13 10:29:17 +08:00
li_chx 23a4622f11 1510. 石子游戏 IV 2026-08-13 10:29:03 +08:00
li_chx ebd3f9445c 1406. 石子游戏 III 2026-08-13 10:28:46 +08:00
li_chx 50fba25511 877. 石子游戏 2026-08-13 10:28:19 +08:00
li_chx ece3af5149 2996. 大于等于顺序前缀和的最小缺失整数 2026-08-13 10:27:10 +08:00
li_chx a19c7573a7 2958. 最多 K 个重复元素的最长子数组 2026-08-13 10:27:08 +08:00
li_chx fe0577dd06 3739. 统计主要元素子数组数目 II 2026-08-12 11:08:31 +08:00
li_chx fcf3f21a52 93. 复原 IP 地址 2026-08-03 21:44:25 +08:00
li_chx cb73a780cf 3501. 操作后最大活跃区段数 II 2026-07-29 13:03:47 +08:00
li_chx 86ec2ee252 3499. 操作后最大活跃区段数 I 2026-07-28 18:35:53 +08:00
li_chx fc8857537e 3517. 最小回文排列 I 2026-07-28 17:25:58 +08:00
li_chx 8cc7ce864c 1331. 数组序号转换 2026-07-12 19:25:21 +08:00
li_chx b88bfb137b 3120. 统计特殊字母的数量 I 2026-05-26 08:40:54 +08:00
li_chx 985c978958 1871. 跳跃游戏 VII 2026-05-25 09:55:22 +08:00
li_chx 25645920ff 3043. 最长公共前缀的长度 2026-05-21 09:42:33 +08:00
li_chx 44ce8b9fd4 2540. 最小公共值 2026-05-19 11:44:18 +08:00
li_chx afa91fe380 1306. 跳跃游戏 III 2026-05-18 17:00:02 +08:00
li_chx 6e59cabd84 1345. 跳跃游戏 IV 2026-05-18 16:46:04 +08:00
li_chx 00bc762b5e 2553. 分割数组中数字的数位 2026-05-18 16:22:37 +08:00
li_chx 9452c4e658 3629. 通过质数传送到达终点的最少跳跃次数 2026-05-09 16:52:51 +08:00
li_chx a9da2f1227 788. 旋转数字 2026-05-02 17:45:45 +08:00
li_chx fa937a142f 3742. 网格中得分最大的路径 2026-04-30 08:58:35 +08:00
li_chx 6213d83856 2033. 获取单值网格的最小操作数 2026-04-28 09:33:19 +08:00
li_chx d0da066c58 1391. 检查网格中是否存在有效路径 2026-04-27 09:39:39 +08:00
li_chx 4460a2f028 2833. 距离原点最远的点 2026-04-24 08:50:07 +08:00
li_chx 4ee2acd245 2615. 等值距离和 2026-04-23 08:53:17 +08:00
li_chx 6074be16ce 2452. 距离字典两次编辑以内的单词 2026-04-22 08:46:21 +08:00
li_chx 11a7d6775d 1722. 执行交换操作后的最小汉明距离 2026-04-21 15:00:19 +08:00
li_chx 93d4b712d5 3761. 镜像对之间最小绝对距离 2026-04-20 12:02:39 +08:00
li_chx a467de459b 2078. 两栋颜色不同且距离最远的房子 2026-04-20 09:20:43 +08:00
li_chx 653e68c8f1 1855. 下标对中的最大距离 2026-04-20 09:18:53 +08:00
li_chx 671347dfde 2515. 到目标字符串的最短距离 2026-04-16 15:44:15 +08:00
li_chx 023fe9ec14 3488. 距离最小相等元素查询 2026-04-16 15:24:09 +08:00
li_chx a6ca63686a 2463. 最小移动总距离 2026-04-14 14:05:56 +08:00
li_chx 283b4c1518 1848. 到目标元素的最小距离 2026-04-13 08:49:21 +08:00
li_chx 444863b22d 3741. 三个相等元素之间的最小距离 II 2026-04-10 11:11:11 +08:00
li_chx 8cac824082 3655. 区间乘法查询后的异或 II 2026-04-10 10:34:20 +08:00
li_chx 8cc2ab780c 2069. 模拟行走机器人 II 2026-04-07 09:23:00 +08:00
li_chx 98eafcac0e 3661. 可以被机器人摧毁的最大墙壁数目 2026-04-03 11:24:27 +08:00
li_chx ecb53e3f3a 3418. 机器人可以获得的最大金币数 2026-04-02 09:20:31 +08:00
li_chx cca3dc4a88 3548. 等和矩阵分割 II 2026-03-26 11:44:36 +08:00
li_chx 8a381984c9 3546. 等和矩阵分割 I 2026-03-25 08:54:24 +08:00
li_chx d7f5b98838 2906. 构造乘积矩阵 2026-03-24 11:10:10 +08:00
li_chx f1f47604f8 1594. 矩阵的最大非负积 2026-03-23 09:31:50 +08:00
li_chx 60447f6bf8 1886. 判断矩阵经轮转后是否一致 2026-03-22 12:52:17 +08:00
li_chx b0641080b5 3567. 子矩阵的最小绝对差 2026-03-20 08:44:00 +08:00
li_chx bb6a7dc773 3212. 统计 X 和 Y 频数相等的子矩阵数量 2026-03-19 09:25:38 +08:00
li_chx bb640829ee 3070. 元素和小于等于 k 的子矩阵的数目 2026-03-18 08:51:45 +08:00
li_chx 6c8fa06ce1 1727. 重新排列后的最大子矩阵 2026-03-17 16:39:07 +08:00
li_chx 143ff15f87 1878. 矩阵中最大的三个菱形和 2026-03-16 09:27:43 +08:00
li_chx d5eafc86f4 1415. 长度为 n 的开心字符串中字典序第 k 小的字符串 2026-03-14 13:10:14 +08:00
li_chx f91a4b2fe6 3296. 移山所需的最少秒数 2026-03-13 09:46:43 +08:00
li_chx 3d72b848d2 3600. 升级后最大生成树稳定性 2026-03-12 10:40:48 +08:00
li_chx bde9d0f8b2 476. 数字的补数 2026-03-11 08:54:18 +08:00
li_chx e615d4f611 1009. 十进制整数的反码 2026-03-11 08:47:20 +08:00
li_chx f80a39e514 3130. 找出所有稳定的二进制数组 II 2026-03-10 09:52:40 +08:00
li_chx bd8207767a 3129. 找出所有稳定的二进制数组 I 2026-03-10 09:51:11 +08:00
li_chx c18ad8c1b0 1888. 使二进制字符串字符交替的最少反转次数 2026-03-07 17:27:23 +08:00
li_chx 566c6a8414 1758. 生成交替二进制字符串的最少操作数 2026-03-05 08:45:56 +08:00
li_chx f8fd02dcb8 1582. 二进制矩阵中的特殊位置 2026-03-04 09:10:28 +08:00
li_chx 563c0b3589 1545. 找出第 N 个二进制字符串中的第 K 位 2026-03-03 09:32:00 +08:00
li_chx 1772ba6c99 1536. 排布二进制网格的最少交换次数 2026-03-02 14:26:28 +08:00
li_chx 495075eef2 1356. 根据数字二进制下 1 的数目排序 2026-02-25 15:35:37 +08:00
li_chx 0f894b29a8 761. 特殊的二进制字符串 2026-02-20 16:22:44 +08:00
li_chx 54bea679f0 744. 寻找比目标字母大的最小字母 2026-01-31 10:45:07 +08:00
li_chx 873bf741e6 3315. 构造最小位运算数组 II 2026-01-22 15:20:33 +08:00
li_chx 7efe4d98bb 3507. 移除最小数对使数组有序 I 2026-01-22 15:07:36 +08:00
li_chx 0f8400d0c9 3573. 买卖股票的最佳时机 V 2025-12-17 18:37:52 +08:00
li_chx 9a82ec82f7 3583. 统计特殊三元组 2025-12-10 15:49:39 +08:00
li_chx 376065acb6 3577. 统计计算机解锁顺序排列数 2025-12-10 15:15:27 +08:00
li-chx cd8b2b31e3 1590. 使数组和能被 P 整除 2025-12-01 13:42:45 +08:00
li-chx 08f6ce4581 2872. 可以被 K 整除连通块的最大数目 2025-11-28 08:59:57 +08:00
li-chx 702b016368 3381. 长度可被 K 整除的子数组的最大元素和 2025-11-27 08:49:45 +08:00
li-chx 1da8b6b735 2435. 矩阵中和能被 K 整除的路径 2025-11-26 08:56:35 +08:00
li-chx 0babcf1472 474. 一和零 2025-11-21 11:41:21 +08:00
li-chx 9648737245 2654. 使数组所有元素变成 1 的最少操作次数 2025-11-21 09:55:06 +08:00
li-chx 93577c7ff2 3228. 将 1 移动到末尾的最大操作次数 2025-11-21 09:38:40 +08:00
li-chx 4b8594e8e3 1930. 长度为 3 的不同回文子序列 2025-11-21 09:34:48 +08:00
li-chx 67d79e3553 757. 设置交集大小至少为2 2025-11-20 21:57:12 +08:00
li-chx 30e2df43c4 2589. 完成所有任务的最少时间 2025-11-20 21:55:57 +08:00
li-chx 8c281d865f 3234. 统计 1 显著的字符串的数量 2025-11-20 16:41:31 +08:00
li-chx 742a5b6137 2154. 将找到的值乘以 2 2025-11-19 09:25:06 +08:00
li-chx fc7f57b9ca 3217. 从链表中移除在数组中存在的节点 ps: Rust写数据结构还是太权威了 2025-11-04 21:13:02 +08:00
li-chx 941d05d9ee 3318. 计算子数组的 x-sum I 2025-11-04 16:23:28 +08:00
li-chx c54a750759 2043. 简易银行系统 2025-10-31 17:28:40 +08:00
li-chx 4f601269e8 2125. 银行中的激光束数量 2025-10-31 17:09:19 +08:00
li-chx 292f597d2b 3289. 数字小镇中的捣蛋鬼 2025-10-31 16:52:13 +08:00
li-chx 8a581be8b5 1526. 形成目标数组的子数组最少增加次数 2025-10-30 17:12:52 +08:00
li-chx b8cc12db71 2048. 下一个更大的数值平衡数 2025-10-24 08:40:05 +08:00
li-chx f0bfce2ee6 3461. 判断操作后字符串中的数字是否相等 I 2025-10-23 15:26:58 +08:00
li-chx 6d6b8f6f3d 3346. 执行操作后元素的最高频率 I 2025-10-21 09:01:59 +08:00
li-chx 60f0b5cd02 3147. 从魔法师身上吸取的最大能量 2025-10-10 08:37:58 +08:00
li-chx aa1f5ac8c1 417. 太平洋大西洋水流问题 2025-10-05 02:41:06 +08:00
li-chx ea455b5577 3100. 换水问题 II 2025-10-02 17:03:18 +08:00
li-chx 625be9225d 2221. 数组的三角和 2025-09-30 10:27:27 +08:00
3 changed files with 240 additions and 28 deletions
+186 -7
View File
@@ -1,3 +1,9 @@
pub fn make_string_arr(s: &str) -> Vec<String> {
s.trim_matches(&['[', ']'][..])
.split(',')
.map(|s| s.trim_matches(&['"',' ']).to_string())
.collect()
}
pub fn make_arr(s: &str) -> Vec<i32> { pub fn make_arr(s: &str) -> Vec<i32> {
s.trim_matches(&['[', ']'][..]) s.trim_matches(&['[', ']'][..])
.split(',') .split(',')
@@ -13,13 +19,186 @@ pub fn make_arr(s: &str) -> Vec<i32> {
} }
pub fn make_matrix(s: &str) -> Vec<Vec<i32>> { pub fn make_matrix(s: &str) -> Vec<Vec<i32>> {
s.trim_matches(&['[', ']'][..]) let s = s.trim();
.split("],[")
.map(|row| { // Remove only the outermost pair of brackets if present, e.g. "[[1,2],[3,4]]" -> "[1,2],[3,4]"
row.trim_matches(&['[', ']'][..]) let inner = if s.len() >= 2 && s.starts_with('[') && s.ends_with(']') {
&s[1..s.len() - 1]
} else {
s
}
.trim();
if inner.is_empty() {
return Vec::new();
}
let bytes = inner.as_bytes();
let mut i = 0usize;
let mut rows: Vec<Vec<i32>> = Vec::new();
while i < bytes.len() {
// find next '['
while i < bytes.len() && bytes[i] != b'[' {
i += 1;
}
if i >= bytes.len() {
break;
}
let start = i + 1; // byte index after '['
i = start;
// find matching ']'
while i < bytes.len() && bytes[i] != b']' {
i += 1;
}
let end = i; // exclusive
// move i past ']' for next iteration (if in bounds)
if i < bytes.len() {
i += 1;
}
if end <= start {
// empty row like []
rows.push(Vec::new());
continue;
}
let row_str = &inner[start..end];
let row_vec: Vec<i32> = row_str
.split(',') .split(',')
.map(|x| x.trim().parse::<i32>().unwrap()) .map(|x| {
.collect() let x = x.trim();
if x == "null" || x.is_empty() {
-1
} else {
x.parse::<i32>().unwrap()
}
}) })
.collect() .collect();
rows.push(row_vec);
}
rows
}
pub fn make_char_matrix(s: &str) -> Vec<Vec<char>> {
let s = s.trim();
// Remove only the outermost pair of brackets if present, e.g. "[[1,2],[3,4]]" -> "[1,2],[3,4]"
let inner = if s.len() >= 2 && s.starts_with('[') && s.ends_with(']') {
&s[1..s.len() - 1]
} else {
s
}
.trim();
if inner.is_empty() {
return Vec::new();
}
let bytes = inner.as_bytes();
let mut i = 0usize;
let mut rows: Vec<Vec<char>> = Vec::new();
while i < bytes.len() {
// find next '['
while i < bytes.len() && bytes[i] != b'[' {
i += 1;
}
if i >= bytes.len() {
break;
}
let start = i + 1; // byte index after '['
i = start;
// find matching ']'
while i < bytes.len() && bytes[i] != b']' {
i += 1;
}
let end = i; // exclusive
// move i past ']' for next iteration (if in bounds)
if i < bytes.len() {
i += 1;
}
if end <= start {
// empty row like []
rows.push(Vec::new());
continue;
}
let row_str = &inner[start..end];
let row_vec: Vec<char> = row_str
.split(',')
.map(|x| {
let x = x.trim().trim_matches('"');
if x == "null" || x.is_empty() {
' '
} else {
x.to_string().chars().nth(0).unwrap()
}
})
.collect();
rows.push(row_vec);
}
rows
}
pub fn make_string_matrix(s: &str) -> Vec<Vec<String>> {
let s = s.trim();
// Remove only the outermost pair of brackets if present, e.g. "[[1,2],[3,4]]" -> "[1,2],[3,4]"
let inner = if s.len() >= 2 && s.starts_with('[') && s.ends_with(']') {
&s[1..s.len() - 1]
} else {
s
}
.trim();
if inner.is_empty() {
return Vec::new();
}
let bytes = inner.as_bytes();
let mut i = 0usize;
let mut rows: Vec<Vec<String>> = Vec::new();
while i < bytes.len() {
// find next '['
while i < bytes.len() && bytes[i] != b'[' {
i += 1;
}
if i >= bytes.len() {
break;
}
let start = i + 1; // byte index after '['
i = start;
// find matching ']'
while i < bytes.len() && bytes[i] != b']' {
i += 1;
}
let end = i; // exclusive
// move i past ']' for next iteration (if in bounds)
if i < bytes.len() {
i += 1;
}
if end <= start {
// empty row like []
rows.push(Vec::new());
continue;
}
let row_str = &inner[start..end];
let row_vec: Vec<String> = row_str
.split(',')
.map(|x| {
let x = x.trim().trim_matches('"');
if x == "null" || x.is_empty() {
"".to_string()
} else {
x.to_string()
}
})
.collect();
rows.push(row_vec);
}
rows
} }
+33
View File
@@ -0,0 +1,33 @@
// Definition for singly-linked list.
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct ListNode {
pub val: i32,
pub next: Option<Box<ListNode>>
}
impl ListNode {
#[inline]
fn new(val: i32) -> Self {
ListNode {
next: None,
val
}
}
}
pub fn make_list(arr: Vec<i32>) -> Option<Box<ListNode>> {
let mut head: Option<Box<ListNode>> = None;
let mut current = &mut head;
for &value in arr.iter() {
let new_node = Box::new(ListNode::new(value));
if current.is_none() {
*current = Some(new_node);
} else {
current.as_mut().unwrap().next = Some(new_node);
current = &mut current.as_mut().unwrap().next;
}
}
head
}
+18 -18
View File
@@ -1,29 +1,29 @@
mod arr; mod arr;
struct Solution {} struct Solution {}
impl Solution { impl Solution {
pub fn triangle_number(nums: Vec<i32>) -> i32 { pub fn min_distance(word1: String, word2: String) -> i32 {
if nums.len() < 3 { let mut dp = vec![vec![0; word2.len() + 1]; word1.len() + 1];
return 0; let word1 = word1.chars().collect::<Vec<char>>();
let word2 = word2.chars().collect::<Vec<char>>();
for i in 1..=word1.len() {
dp[i][0] = dp[i - 1][0] + 1;
} }
let mut nums = nums; for i in 1..=word2.len() {
nums.sort(); dp[0][i] = dp[0][i - 1] + 1;
let mut ans = 0;
for i in 0..nums.len() - 2 {
let mut r = i + 2;
for l in i + 1..nums.len() - 1 {
while r < nums.len() && nums[i] + nums[l] > nums[r] {
r += 1;
} }
for i in 0..word1.len() {
ans += ((r - l) as i32 - 1).max(0); for j in 0..word2.len() {
dp[i + 1][j + 1] = (dp[i][j] + if word1[i] != word2[j] { 1 } else { 0 })
.min(dp[i][j + 1] + 1)
.min(dp[i + 1][j] + 1);
} }
} }
ans dp[word1.len()][word2.len()]
} }
} }
fn main() { fn main() {
let arr = vec![7, 0, 0, 0]; println!(
println!("{}", Solution::triangle_number(arr)); "{:?}",
Solution::min_distance("intention".to_string(), "execution".to_string())
);
} }