From 360176615f4454fb92be23335f8c0bd8198bf484 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 16 Jul 2021 22:21:40 +0800 Subject: [PATCH 0001/1556] src/bin/h-index.rs --- src/bin/h-index.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/h-index.rs diff --git a/src/bin/h-index.rs b/src/bin/h-index.rs new file mode 100644 index 00000000..6cee39de --- /dev/null +++ b/src/bin/h-index.rs @@ -0,0 +1,23 @@ +fn main() { + println!("{}", Solution::h_index(vec![3, 0, 6, 1, 5])); + println!("{}", Solution::h_index(vec![1])); +} + +struct Solution; + +impl Solution { + pub fn h_index(citations: Vec) -> i32 { + let mut citations = citations; + citations.sort(); + + let mut h = 0; + + for i in (0..citations.len()).rev() { + if citations[i] > h { + h += 1; + } + } + + return h; + } +} From 440b746419c6172fd21c6a976166fe1c3eb29458 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 16 Jul 2021 22:21:40 +0800 Subject: [PATCH 0002/1556] README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a554598..3117bdf8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # leetcode -当前已刷:238 +当前已刷:239 ### 题目 - 1:两数之和 @@ -441,6 +441,9 @@ - 268:丢失的数字 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) - [leetcode](https://leetcode-cn.com/problems/missing-number/) +- 274:H 指数 + - [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) + - [leetcode](https://leetcode-cn.com/problems/h-index/) - 290:单词规律 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) - [leetcode](https://leetcode-cn.com/problems/word-pattern/) From 5f9c14c96675fba0f72ca9ebf5d548f5b5aafcf4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 18 Jul 2021 23:37:40 +0800 Subject: [PATCH 0003/1556] src/bin/first-bad-version.rs --- src/bin/first-bad-version.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/first-bad-version.rs diff --git a/src/bin/first-bad-version.rs b/src/bin/first-bad-version.rs new file mode 100644 index 00000000..d778940a --- /dev/null +++ b/src/bin/first-bad-version.rs @@ -0,0 +1,35 @@ +fn main() { + // println!("{}", Solution::new(1702766719).first_bad_version(2126753390)); + // println!("{}", Solution::new(1).first_bad_version(1)); + println!("{}", Solution::new(2).first_bad_version(2)); +} + +struct Solution { + n: i32 +} + +// The API isBadVersion is defined for you. +// isBadVersion(versions:i32)-> bool; +// to call it use self.isBadVersion(versions) + +impl Solution { + fn new(n: i32) -> Self { Self { n } } + + pub fn first_bad_version(&self, n: i32) -> i32 { + let mut good: i64 = 0; + let mut bad: i64 = n as i64; + while bad - good > 1 { + let mid = (good + bad + 1) / 2; + if self.isBadVersion(mid as i32) { + bad = mid; + } else { + good = mid; + } + } + bad as i32 + } + + fn isBadVersion(&self, versions: i32) -> bool { + self.n <= versions + } +} From 22845f52be6420fcd3d23e17f0f957fa59341ec3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 18 Jul 2021 23:37:40 +0800 Subject: [PATCH 0004/1556] README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3117bdf8..85c42c41 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # leetcode -当前已刷:239 +当前已刷:240 ### 题目 - 1:两数之和 @@ -444,6 +444,9 @@ - 274:H 指数 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) - [leetcode](https://leetcode-cn.com/problems/h-index/) +- 278:第一个错误的版本 + - [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) + - [leetcode](https://leetcode-cn.com/problems/first-bad-version/) - 290:单词规律 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) - [leetcode](https://leetcode-cn.com/problems/word-pattern/) From a2aea480352bee48a83a0ef6125aad1ada714f4a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 19 Jul 2021 21:16:58 +0800 Subject: [PATCH 0005/1556] src/bin/range-sum-query-immutable.rs --- src/bin/range-sum-query-immutable.rs | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/bin/range-sum-query-immutable.rs diff --git a/src/bin/range-sum-query-immutable.rs b/src/bin/range-sum-query-immutable.rs new file mode 100644 index 00000000..80e321d0 --- /dev/null +++ b/src/bin/range-sum-query-immutable.rs @@ -0,0 +1,42 @@ +fn main() {} + +struct Solution; + + +/** + * Your NumArray object will be instantiated and called as such: + * let obj = NumArray::new(nums); + * let ret_1: i32 = obj.sum_range(left, right); + */ +struct NumArray { + sums: Vec +} + + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl NumArray { + fn new(nums: Vec) -> Self { + let mut sums = Vec::with_capacity(nums.len()); + + for i in 0..=nums.len() { + if i == 0 { + sums.push(0); + } else { + sums.push(nums[i] + sums[i - 1]); + } + } + + Self { sums } + } + + fn sum_range(&self, left: i32, right: i32) -> i32 { + if left == 0 { + self.sums[right as usize] + } else { + self.sums[right as usize] - self.sums[left as usize - 1usize] + } + } +} From 86b69825ba6e86c5c12cf4f941ee5868a9adcdec Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 19 Jul 2021 21:16:58 +0800 Subject: [PATCH 0006/1556] README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 85c42c41..6b2b3353 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # leetcode -当前已刷:240 +当前已刷:241 ### 题目 - 1:两数之和 @@ -450,6 +450,9 @@ - 290:单词规律 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) - [leetcode](https://leetcode-cn.com/problems/word-pattern/) +- 303:区域和检索 - 数组不可变 + - [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) + - [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) - 349:两个数组的交集 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) - [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) From 9372e4d2c7341fa1168c0963f4e546b0e1e68d1e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 20 Jul 2021 23:47:40 +0800 Subject: [PATCH 0007/1556] src/bin/maximum-product-of-word-lengths.rs --- src/bin/maximum-product-of-word-lengths.rs | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/maximum-product-of-word-lengths.rs diff --git a/src/bin/maximum-product-of-word-lengths.rs b/src/bin/maximum-product-of-word-lengths.rs new file mode 100644 index 00000000..f4222d3d --- /dev/null +++ b/src/bin/maximum-product-of-word-lengths.rs @@ -0,0 +1,27 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_product(words: Vec) -> i32 { + let mut v = vec![0i32; words.len()]; + + for i in 0..words.len() { + for &j in words[i].as_bytes() { + v[i] |= (1 << (j - b'a')); + } + } + + let mut r = 0; + + for i in 0..words.len() { + for j in i + 1..words.len() { + if (v[i] & v[j]) == 0 { + r = r.max(words[i].len() * words[j].len()) + } + } + } + + r as i32 + } +} From e7e34ab86c32e34f8a64fb452bb465538eafd505 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 20 Jul 2021 23:47:40 +0800 Subject: [PATCH 0008/1556] README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b2b3353..825ad66d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # leetcode -当前已刷:241 +当前已刷:242 ### 题目 - 1:两数之和 @@ -453,6 +453,9 @@ - 303:区域和检索 - 数组不可变 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) - [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) +- 318:最大单词长度乘积 + - [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) + - [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) - 349:两个数组的交集 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) - [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) From dbf0d640feab684c26ed4ddab59ced6bcfb8cbd2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 21 Jul 2021 21:28:37 +0800 Subject: [PATCH 0009/1556] src/bin/bulb-switcher.rs --- src/bin/bulb-switcher.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/bin/bulb-switcher.rs diff --git a/src/bin/bulb-switcher.rs b/src/bin/bulb-switcher.rs new file mode 100644 index 00000000..1211d912 --- /dev/null +++ b/src/bin/bulb-switcher.rs @@ -0,0 +1,9 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn bulb_switch(n: i32) -> i32 { + (n as f64).sqrt() as i32 + } +} From d9cb362d6235a6515eab2cf08a030b4caff0bfc8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 21 Jul 2021 21:28:37 +0800 Subject: [PATCH 0010/1556] README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 825ad66d..60efc7b3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # leetcode -当前已刷:242 +当前已刷:243 ### 题目 - 1:两数之和 @@ -456,6 +456,9 @@ - 318:最大单词长度乘积 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) - [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) +- 319:灯泡开关 + - [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) + - [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) - 349:两个数组的交集 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) - [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) From 148c85cd26830b80a9088f894a2b3c0d6e66eaad Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 22 Jul 2021 21:26:34 +0800 Subject: [PATCH 0011/1556] src/bin/count-numbers-with-unique-digits.rs --- src/bin/count-numbers-with-unique-digits.rs | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/count-numbers-with-unique-digits.rs diff --git a/src/bin/count-numbers-with-unique-digits.rs b/src/bin/count-numbers-with-unique-digits.rs new file mode 100644 index 00000000..cd5c4b62 --- /dev/null +++ b/src/bin/count-numbers-with-unique-digits.rs @@ -0,0 +1,27 @@ +fn main() { + println!("{}", Solution::count_numbers_with_unique_digits(2)); + println!("{}", Solution::count_numbers_with_unique_digits(8)); + println!("{}", Solution::count_numbers_with_unique_digits(7)); +} + +struct Solution; + +impl Solution { + pub fn count_numbers_with_unique_digits(n: i32) -> i32 { + if n == 0 { + return 1; + } + + if n == 1 { + return 10; + } + + let mut sum =9; + + for i in 0..n - 1 { + sum *= 9 - i; + } + + sum + Self::count_numbers_with_unique_digits(n - 1) + } +} From 9503e16cbed3a8ce801d05e145e39a62182ae74f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 22 Jul 2021 21:26:34 +0800 Subject: [PATCH 0012/1556] README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 60efc7b3..7564f466 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # leetcode -当前已刷:243 +当前已刷:244 ### 题目 - 1:两数之和 @@ -462,6 +462,9 @@ - 349:两个数组的交集 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) - [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) +- 357:计算各个位数不同的数字个数 + - [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) + - [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) - 367:有效的完全平方数 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) - [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) From f1fb129a2f14a24147a00a5326eb2b146f9fcc2e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 23 Jul 2021 23:39:39 +0800 Subject: [PATCH 0013/1556] src/bin/power-of-three.rs --- src/bin/power-of-three.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/bin/power-of-three.rs diff --git a/src/bin/power-of-three.rs b/src/bin/power-of-three.rs new file mode 100644 index 00000000..1d36d59d --- /dev/null +++ b/src/bin/power-of-three.rs @@ -0,0 +1,19 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn is_power_of_three(n: i32) -> bool { + let mut n = n; + + while n > 1 || n < -1 { + if n % 3 == 0 { + n /= 3; + } else { + return false; + } + } + + n == 1 + } +} From 091cd17f765c66bae88208ca97be49d121ba78b5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 23 Jul 2021 23:39:39 +0800 Subject: [PATCH 0014/1556] README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7564f466..b9535f74 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # leetcode -当前已刷:244 +当前已刷:245 ### 题目 - 1:两数之和 @@ -459,6 +459,9 @@ - 319:灯泡开关 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) - [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) +- 326:3的幂 + - [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) + - [leetcode](https://leetcode-cn.com/problems/power-of-three/) - 349:两个数组的交集 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) - [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) From 19de7fef9214fc4d06e5844f518f7e2a4c237a63 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 24 Jul 2021 23:53:33 +0800 Subject: [PATCH 0015/1556] src/bin/perfect-squares.rs --- src/bin/perfect-squares.rs | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bin/perfect-squares.rs diff --git a/src/bin/perfect-squares.rs b/src/bin/perfect-squares.rs new file mode 100644 index 00000000..4f5c2003 --- /dev/null +++ b/src/bin/perfect-squares.rs @@ -0,0 +1,40 @@ +fn main() { + println!("{}", Solution::num_squares(12)); + println!("{}", Solution::num_squares(13)); +} + +struct Solution; + +impl Solution { + pub fn num_squares(n: i32) -> i32 { + let mut h = std::collections::HashMap::new(); + Self::f(n, &mut h) + } + + fn f(n: i32, h: &mut std::collections::HashMap) -> i32 { + if n == 0 { + return 0; + } + + if let Some(&x) = h.get(&n) { + return x; + } + + let mut s = 0; + + let mut m = 1; + while m * m <= n { + let s1 = 1 + Self::f(n - m * m, h); + if s == 0 { + s = s1; + } else { + s = s.min(s1) + } + m += 1; + } + + h.insert(n, s); + + s + } +} From 265ac9c61fabbd579009f482e915fe1968462ab2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 24 Jul 2021 23:53:33 +0800 Subject: [PATCH 0016/1556] README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b9535f74..cd3d92f0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # leetcode -当前已刷:245 +当前已刷:246 ### 题目 - 1:两数之和 @@ -447,6 +447,9 @@ - 278:第一个错误的版本 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) - [leetcode](https://leetcode-cn.com/problems/first-bad-version/) +- 279:完全平方数 + - [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) + - [leetcode](https://leetcode-cn.com/problems/perfect-squares/) - 290:单词规律 - [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) - [leetcode](https://leetcode-cn.com/problems/word-pattern/) From afda6049fe76d98e361161784617a4648c412d05 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 17:27:18 +0800 Subject: [PATCH 0017/1556] word-rectangle-lcci --- src/{lib.rs => lib_bak.rs} | 0 src/{main.rs => main_bak.rs} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/{lib.rs => lib_bak.rs} (100%) rename src/{main.rs => main_bak.rs} (100%) diff --git a/src/lib.rs b/src/lib_bak.rs similarity index 100% rename from src/lib.rs rename to src/lib_bak.rs diff --git a/src/main.rs b/src/main_bak.rs similarity index 100% rename from src/main.rs rename to src/main_bak.rs From fbb25bb8c75f58ba0f349429c49b8e42c0274912 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 21:03:25 +0800 Subject: [PATCH 0018/1556] README.md --- README.md | 945 ++++++++++++------------------------------------------ 1 file changed, 206 insertions(+), 739 deletions(-) diff --git a/README.md b/README.md index cd3d92f0..1604d9a8 100644 --- a/README.md +++ b/README.md @@ -1,743 +1,210 @@ # leetcode -当前已刷:246 +当前已刷:202 ### 题目 -- 1:两数之和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) - - [leetcode](https://leetcode-cn.com/problems/two-sum/) -- 2:两数相加 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) - - [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) -- 3:无重复字符的最长子串 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) - - [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) -- 4:寻找两个正序数组的中位数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) - - [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) -- 6:Z 字形变换 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) - - [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) -- 7:整数反转 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) - - [leetcode](https://leetcode-cn.com/problems/reverse-integer/) -- 8:字符串转换整数 (atoi) - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) - - [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) -- 9:回文数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) - - [leetcode](https://leetcode-cn.com/problems/palindrome-number/) -- 11:盛最多水的容器 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) - - [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) -- 12:整数转罗马数字 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) - - [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) -- 13:罗马数字转整数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) - - [leetcode](https://leetcode-cn.com/problems/roman-to-integer/) -- 14:最长公共前缀 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) - - [leetcode](https://leetcode-cn.com/problems/longest-common-prefix/) -- 15:三数之和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) - - [leetcode](https://leetcode-cn.com/problems/3sum/) -- 16:最接近的三数之和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) - - [leetcode](https://leetcode-cn.com/problems/3sum-closest/) -- 17:电话号码的字母组合 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) - - [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) -- 18:四数之和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) - - [leetcode](https://leetcode-cn.com/problems/4sum/) -- 19:删除链表的倒数第 N 个结点 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) - - [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) -- 20:有效的括号 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) - - [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) -- 21:合并两个有序链表 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) - - [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) -- 23:合并K个升序链表 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) - - [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) -- 24:两两交换链表中的节点 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) - - [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) -- 25:K 个一组翻转链表 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) - - [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) -- 26:删除有序数组中的重复项 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) - - [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) -- 27:移除元素 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) - - [leetcode](https://leetcode-cn.com/problems/remove-element/) -- 28:实现 strStr() - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) - - [leetcode](https://leetcode-cn.com/problems/implement-strstr/) -- 31:下一个排列 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) - - [leetcode](https://leetcode-cn.com/problems/next-permutation/) -- 33:搜索旋转排序数组 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) - - [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) -- 34:在排序数组中查找元素的第一个和最后一个位置 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) - - [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) -- 35:搜索插入位置 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) - - [leetcode](https://leetcode-cn.com/problems/search-insert-position/) -- 36:有效的数独 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) - - [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) -- 38:外观数列 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) - - [leetcode](https://leetcode-cn.com/problems/count-and-say/) -- 39:组合总和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) - - [leetcode](https://leetcode-cn.com/problems/combination-sum/) -- 41:缺失的第一个正数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) - - [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) -- 43:字符串相乘 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) - - [leetcode](https://leetcode-cn.com/problems/multiply-strings/) -- 45:跳跃游戏 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) -- 46:全排列 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) - - [leetcode](https://leetcode-cn.com/problems/permutations/) -- 48:旋转图像 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) - - [leetcode](https://leetcode-cn.com/problems/rotate-image/) -- 49:字母异位词分组 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) - - [leetcode](https://leetcode-cn.com/problems/group-anagrams/) -- 50:Pow(x, n) - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) - - [leetcode](https://leetcode-cn.com/problems/powx-n/) -- 51:N 皇后 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) - - [leetcode](https://leetcode-cn.com/problems/n-queens/) -- 52:N皇后 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) -- 53:最大子序和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) - - [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) -- 55:跳跃游戏 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) - - [leetcode](https://leetcode-cn.com/problems/jump-game/) -- 56:合并区间 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) - - [leetcode](https://leetcode-cn.com/problems/merge-intervals/) -- 57:插入区间 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) - - [leetcode](https://leetcode-cn.com/problems/insert-interval/) -- 58:最后一个单词的长度 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) - - [leetcode](https://leetcode-cn.com/problems/length-of-last-word/) -- 62:不同路径 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) - - [leetcode](https://leetcode-cn.com/problems/unique-paths/) -- 63:不同路径 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) -- 64:最小路径和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) - - [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) -- 66:加一 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) - - [leetcode](https://leetcode-cn.com/problems/plus-one/) -- 67:二进制求和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) - - [leetcode](https://leetcode-cn.com/problems/add-binary/) -- 69:x 的平方根 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) - - [leetcode](https://leetcode-cn.com/problems/sqrtx/) -- 70:爬楼梯 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) - - [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) -- 71:简化路径 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) - - [leetcode](https://leetcode-cn.com/problems/simplify-path/) -- 73:矩阵置零 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) - - [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) -- 74:搜索二维矩阵 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) - - [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) -- 75:颜色分类 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) - - [leetcode](https://leetcode-cn.com/problems/sort-colors/) -- 77:组合 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) - - [leetcode](https://leetcode-cn.com/problems/combinations/) -- 78:子集 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) - - [leetcode](https://leetcode-cn.com/problems/subsets/) -- 79:单词搜索 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) - - [leetcode](https://leetcode-cn.com/problems/word-search/) -- 80:删除有序数组中的重复项 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) -- 81:搜索旋转排序数组 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) -- 82:删除排序链表中的重复元素 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) -- 83:删除排序链表中的重复元素 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) - - [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) -- 88:合并两个有序数组 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) - - [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) -- 89:格雷编码 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) - - [leetcode](https://leetcode-cn.com/problems/gray-code/) -- 91:解码方法 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) - - [leetcode](https://leetcode-cn.com/problems/decode-ways/) -- 93:复原 IP 地址 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) - - [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) -- 94:二叉树的中序遍历 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) - - [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) -- 95:不同的二叉搜索树 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) -- 96:不同的二叉搜索树 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) - - [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) -- 98:验证二叉搜索树 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) - - [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) -- 100:相同的树 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) - - [leetcode](https://leetcode-cn.com/problems/same-tree/) -- 101:对称二叉树 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) - - [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) -- 102:二叉树的层序遍历 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) - - [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) -- 103:二叉树的锯齿形层序遍历 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) - - [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) -- 104:二叉树的最大深度 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) - - [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) -- 105:从前序与中序遍历序列构造二叉树 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) - - [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) -- 106:从中序与后序遍历序列构造二叉树 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) - - [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) -- 107:二叉树的层序遍历 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) -- 108:将有序数组转换为二叉搜索树 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) - - [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) -- 110:平衡二叉树 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) - - [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree/) -- 111:二叉树的最小深度 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) - - [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) -- 112:路径总和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) - - [leetcode](https://leetcode-cn.com/problems/path-sum/) -- 113:路径总和 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) -- 118:杨辉三角 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) - - [leetcode](https://leetcode-cn.com/problems/pascals-triangle/) -- 119:杨辉三角 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii/) -- 120:三角形最小路径和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) - - [leetcode](https://leetcode-cn.com/problems/triangle/) -- 121:买卖股票的最佳时机 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) - - [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/) -- 122:买卖股票的最佳时机 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) -- 125:验证回文串 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) - - [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) -- 129:求根节点到叶节点数字之和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) - - [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) -- 136:只出现一次的数字 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) - - [leetcode](https://leetcode-cn.com/problems/single-number/) -- 137:只出现一次的数字 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/single-number-ii/) -- 144:二叉树的前序遍历 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) - - [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) -- 145:二叉树的后序遍历 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) - - [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) -- 150:逆波兰表达式求值 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) - - [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) -- 151:翻转字符串里的单词 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) - - [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) -- 152:乘积最大子数组 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) - - [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) -- 153:寻找旋转排序数组中的最小值 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) - - [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) -- 155:最小栈 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) - - [leetcode](https://leetcode-cn.com/problems/min-stack/) -- 162:寻找峰值 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) - - [leetcode](https://leetcode-cn.com/problems/find-peak-element/) -- 165:比较版本号 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) - - [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) -- 166:分数到小数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) - - [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) -- 167:两数之和 II - 输入有序数组 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) - - [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) -- 168:Excel表列名称 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) - - [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) -- 169:多数元素 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) - - [leetcode](https://leetcode-cn.com/problems/majority-element/) -- 171:Excel表列序号 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) - - [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) -- 172:阶乘后的零 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) - - [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) -- 173:二叉搜索树迭代器 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) - - [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) -- 187:重复的DNA序列 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) - - [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) -- 190:颠倒二进制位 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) - - [leetcode](https://leetcode-cn.com/problems/reverse-bits/) -- 191:位1的个数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) - - [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) -- 198:打家劫舍 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) - - [leetcode](https://leetcode-cn.com/problems/house-robber/) -- 199:二叉树的右视图 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) - - [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) -- 200:岛屿数量 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) - - [leetcode](https://leetcode-cn.com/problems/number-of-islands/) -- 201:数字范围按位与 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) - - [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) -- 202:快乐数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) - - [leetcode](https://leetcode-cn.com/problems/happy-number/) -- 203:移除链表元素 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) - - [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) -- 204:计数质数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) - - [leetcode](https://leetcode-cn.com/problems/count-primes/) -- 205:同构字符串 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) - - [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) -- 206:反转链表 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) - - [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) -- 208:实现 Trie (前缀树) - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) - - [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) -- 211:添加与搜索单词 - 数据结构设计 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) - - [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) -- 213:打家劫舍 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) -- 215:数组中的第K个最大元素 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) - - [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) -- 216:组合总和 III - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) - - [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) -- 217:存在重复元素 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) - - [leetcode](https://leetcode-cn.com/problems/contains-duplicate/) -- 219:存在重复元素 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii/) -- 222:完全二叉树的节点个数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) - - [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) -- 223:矩形面积 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) - - [leetcode](https://leetcode-cn.com/problems/rectangle-area/) -- 225:用队列实现栈 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) - - [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues/) -- 226:翻转二叉树 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) - - [leetcode](https://leetcode-cn.com/problems/invert-binary-tree/) -- 228:汇总区间 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) - - [leetcode](https://leetcode-cn.com/problems/summary-ranges/) -- 229:求众数 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) -- 230:二叉搜索树中第K小的元素 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) - - [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) -- 231:2 的幂 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) - - [leetcode](https://leetcode-cn.com/problems/power-of-two/) -- 232:用栈实现队列 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) - - [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks/) -- 234:回文链表 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) - - [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) -- 235:二叉搜索树的最近公共祖先 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) - - [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) -- 238:除自身以外数组的乘积 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) - - [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) -- 242:有效的字母异位词 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) - - [leetcode](https://leetcode-cn.com/problems/valid-anagram/) -- 257:二叉树的所有路径 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) - - [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) -- 258:各位相加 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) - - [leetcode](https://leetcode-cn.com/problems/add-digits/) -- 263:丑数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) - - [leetcode](https://leetcode-cn.com/problems/ugly-number/) -- 268:丢失的数字 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) - - [leetcode](https://leetcode-cn.com/problems/missing-number/) -- 274:H 指数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) - - [leetcode](https://leetcode-cn.com/problems/h-index/) -- 278:第一个错误的版本 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) - - [leetcode](https://leetcode-cn.com/problems/first-bad-version/) -- 279:完全平方数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) - - [leetcode](https://leetcode-cn.com/problems/perfect-squares/) -- 290:单词规律 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) - - [leetcode](https://leetcode-cn.com/problems/word-pattern/) -- 303:区域和检索 - 数组不可变 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) - - [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) -- 318:最大单词长度乘积 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) - - [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) -- 319:灯泡开关 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) - - [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) -- 326:3的幂 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) - - [leetcode](https://leetcode-cn.com/problems/power-of-three/) -- 349:两个数组的交集 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) - - [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) -- 357:计算各个位数不同的数字个数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) - - [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) -- 367:有效的完全平方数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) - - [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) -- 371:两整数之和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) - - [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) -- 374:猜数字大小 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) - - [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) -- 387:字符串中的第一个唯一字符 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) - - [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) -- 404:左叶子之和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) - - [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) -- 419:甲板上的战舰 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) - - [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) -- 423:从英文中重建数字 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) - - [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) -- 434:字符串中的单词数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) - - [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) -- 476:数字的补数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) - - [leetcode](https://leetcode-cn.com/problems/number-complement/) -- 481:神奇字符串 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) - - [leetcode](https://leetcode-cn.com/problems/magical-string/) -- 500:键盘行 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) - - [leetcode](https://leetcode-cn.com/problems/keyboard-row/) -- 520:检测大写字母 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) - - [leetcode](https://leetcode-cn.com/problems/detect-capital/) -- 528:交换链表中的节点 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) - - [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) -- 551:学生出勤记录 I - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) - - [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) -- 560:和为K的子数组 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) - - [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) -- 565:数组嵌套 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) - - [leetcode](https://leetcode-cn.com/problems/array-nesting/) -- 594:最长和谐子序列 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) - - [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) -- 617:合并二叉树 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) - - [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) -- 649:Dota2 参议院 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) - - [leetcode](https://leetcode-cn.com/problems/dota2-senate/) -- 650:只有两个键的键盘 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) - - [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) -- 653:两数之和 IV - 输入 BST - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) - - [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) -- 658:找到 K 个最接近的元素 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) - - [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) -- 674:最长连续递增序列 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) - - [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) -- 800:字母大小写全排列 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) - - [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) -- 825:保持城市天际线 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) - - [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) -- 829:子域名访问计数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) - - [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) -- 857:较大分组的位置 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) - - [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) -- 868:推多米诺 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) - - [leetcode](https://leetcode-cn.com/problems/push-dominoes/) -- 917:救生艇 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) - - [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) -- 921:螺旋矩阵 III - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) - - [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) -- 924:公平的糖果棒交换 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) - - [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) -- 925:根据前序和后序遍历构造二叉树 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) - - [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) -- 932:单调数列 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) - - [leetcode](https://leetcode-cn.com/problems/monotonic-array/) -- 979:增减字符串匹配 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) - - [leetcode](https://leetcode-cn.com/problems/di-string-match/) -- 981:删列造序 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) - - [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) -- 982:使数组唯一的最小增量 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) - - [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) -- 1002:最大宽度坡 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) - - [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) -- 1005:单值二叉树 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) - - [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) -- 1007:连续差相同的数字 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) - - [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) -- 1046:最大连续1的个数 III - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) - - [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) -- 1050:前序遍历构造二叉搜索树 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) - - [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) -- 1054:十进制整数的反码 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) - - [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) -- 1072:链表中的下一个更大节点 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) - - [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) -- 1119:困于环中的机器人 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) - - [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) -- 1128:删除字符串中的所有相邻重复项 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) - - [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) -- 1157:根到叶路径上的不足节点 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) - - [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) -- 1210:删除某些元素后的数组均值 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) - - [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) -- 1238:字母板上的路径 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) - - [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) -- 1287:公交站间的距离 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) - - [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) -- 1320:删除字符串中的所有相邻重复项 II - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) - - [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) -- 1341:分割平衡字符串 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) - - [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) -- 1362:飞机座位分配概率 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) - - [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) -- 1370:统计「优美子数组」 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) - - [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) -- 1371:移除无效的括号 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) - - [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) -- 1379:重构 2 行二进制矩阵 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) - - [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) -- 1387:在受污染的二叉树中查找元素 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) - - [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) -- 1411:二进制链表转整数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) - - [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) -- 1426:和为零的N个唯一整数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) - - [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) -- 1428:跳跃游戏 III - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) - - [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) -- 1434:解码字母到整数映射 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) - - [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) -- 1441:或运算的最小翻转次数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) - - [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) -- 1468:检查整数及其两倍数是否存在 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) - - [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) -- 1537:分割字符串的最大得分 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) - - [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) -- 1538:可获得的最大点数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) - - [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) -- 1552:用栈操作构建数组 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) - - [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) -- 1566:检查单词是否为句中其他单词的前缀 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) - - [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) -- 1567:定长子串中元音的最大数目 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) - - [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) -- 1603:一维数组的动态和 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) - - [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) -- 1604:不同整数的最少数目 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) - - [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) -- 1620:检查数组对是否可以被 k 整除 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) - - [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) -- 1642:换酒问题 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) - - [leetcode](https://leetcode-cn.com/problems/water-bottles/) -- 1656:统计好三元组 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) - - [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) -- 1660:千位分隔数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) - - [leetcode](https://leetcode-cn.com/problems/thousand-separator/) -- 1666:整理字符串 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) - - [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) -- 1791:最富有客户的资产总量 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) - - [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) -- 1797:设计 Goal 解析器 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) - - [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) -- 1806:比赛中的配对次数 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) - - [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) -- 1807:十-二进制数的最少数目 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) - - [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) -- 100273:用两个栈实现队列 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) - - [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) -- 100274:斐波那契数列 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) - - [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) -- 100299:删除链表的节点 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) - - [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) -- 100316:第一个只出现一次的字符 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) - - [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) -- 100325:把数字翻译成字符串 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) - - [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) -- 100333:二叉搜索树的第k大节点 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) - - [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) -- 100344:股票的最大利润 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) - - [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) -- 100345:求1+2+…+n - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) - - [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) -- 100349:最大数值 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) - - [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) -- 100352:跳水板 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) - - [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) -- 100353:平分正方形 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) - - [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) -- 1000063:传递信息 - - [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) - - [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) + +| 编号 | 题目 | 描述 | 代码 | +| ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | +|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year) | +|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | From c6c1271a85d79f300e179aed3cc372679e7332a9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 21:06:12 +0800 Subject: [PATCH 0019/1556] src/bin/maximum-population-year.rs --- src/bin/maximum-population-year.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/maximum-population-year.rs diff --git a/src/bin/maximum-population-year.rs b/src/bin/maximum-population-year.rs new file mode 100644 index 00000000..c6ac123d --- /dev/null +++ b/src/bin/maximum-population-year.rs @@ -0,0 +1,27 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_population(logs: Vec>) -> i32 { + let mut v = vec![0; 1000]; + + for i in logs { + for x in (i[0] - 1950) as usize..(i[1] - 1950) as usize { + v[x] += 1; + } + } + + let mut max = 0; + + for i in 1..v.len() { + max = if v[i] > v[max] { + i + } else { + max + } + } + + max as i32 + 1950 + } +} From 665fe5a8e59e32e38d5491a2a27846b894f9fb4a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 21:06:13 +0800 Subject: [PATCH 0020/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1604d9a8..6b2a1030 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # leetcode -当前已刷:202 +当前已刷:203 ### 题目 @@ -196,6 +196,7 @@ |1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year) | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | From e197726b936fb452b2775d06efa897c27413caca Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 21:07:13 +0800 Subject: [PATCH 0021/1556] README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b2a1030..664b7927 100644 --- a/README.md +++ b/README.md @@ -197,7 +197,7 @@ |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year) | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | From d9e20a5773d3382fe6b1e7c43b7903c018609fe2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 21:10:43 +0800 Subject: [PATCH 0022/1556] feature:new script --- Cargo.toml | 7 +++- src/all.rs | 40 +++++++++++++++++++ src/file.rs | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/git.rs | 62 +++++++++++++++++++++++++++++ src/http.rs | 77 ++++++++++++++++++++++++++++++++++++ src/lib.rs | 34 ++++++++++++++++ src/main.rs | 5 +++ src/new.rs | 8 ++++ src/render.rs | 62 +++++++++++++++++++++++++++++ 9 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 src/all.rs create mode 100644 src/file.rs create mode 100644 src/git.rs create mode 100644 src/http.rs create mode 100644 src/lib.rs create mode 100644 src/main.rs create mode 100644 src/new.rs create mode 100644 src/render.rs diff --git a/Cargo.toml b/Cargo.toml index 48dc63af..dd4342f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,12 @@ git2 = "0.13.15" reqwest = { version = "0.10", features = ["blocking", "json"] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } +clap = "3.0.0-beta.2" +tera = "1.12.1" +lazy_static = "1.4.0" +regex = "1" + [[bin]] name ="leetcode" -path ="src/main.rs" +path = "src/main.rs" diff --git a/src/all.rs b/src/all.rs new file mode 100644 index 00000000..32ced734 --- /dev/null +++ b/src/all.rs @@ -0,0 +1,40 @@ +use crate::file; + +use std::sync::{Arc, Mutex}; +use std::thread; +use crate::http::Resp; + + +/// 重新格式化 +pub fn all() { + let files = file::get_all_bin_file(); + + let mut v = Vec::::with_capacity(files.len()); + + let x = Arc::new(Mutex::new(v)); + let mut handlers = vec![]; + + for i in 0..=files.len() / 10 { + // 把files分块,分成10个文件一块 + let files = if i * 10 + 10 > files.len() { + files[i * 10..files.len()].to_vec() + } else { + files[i * 10..i * 10 + 10].to_vec() + }; + + let x = x.clone(); + + handlers.push(thread::spawn(move || { + for i in files { + let resp = crate::http::get_question_info(&i); + x.lock().unwrap().push(resp); + } + })) + } + + for i in handlers { + i.join(); + } + + crate::file::write_readme(&mut *x.lock().unwrap()); +} diff --git a/src/file.rs b/src/file.rs new file mode 100644 index 00000000..c7a15ab2 --- /dev/null +++ b/src/file.rs @@ -0,0 +1,107 @@ +use std::fs::{self, File}; +use std::io::Write; +use lazy_static::lazy_static; +use regex::Regex; + +use crate::http::{Resp, Data, Ques}; + +lazy_static!( + static ref RE: Regex = Regex::new(r"\|\s*([0-9]*)\s*\|\s*(\w*)\s*\|.*?bin/(.*?).rs.*?\|.*?\|").unwrap(); +); + +/// 将结果写入README.md中 +pub fn write_readme(r: &mut Vec) { + // 先按id排序 + r.sort_by(|x, y| { + let x_id = x.data.question.question_id.parse::().unwrap(); + let y_id = y.data.question.question_id.parse::().unwrap(); + x_id.cmp(&y_id) + }); + let s = crate::render::render(r).unwrap(); + + match std::fs::write("README.md", s) { + Ok(_) => (), + Err(e) => println!("写入 README.md 失败,err{}", e.to_string()) + } +} + +/// 获取 src/bin 目录下所有文件的名称 +pub fn get_all_bin_file() -> Vec { + let dir = fs::read_dir("src/bin/").unwrap(); + dir. + into_iter(). + map(|x| { + x.unwrap().file_name().to_str().unwrap().trim_end_matches(".rs").to_string() + }). + collect() +} + + +/// 创建 bin/{quest_name}.rs 文件 +pub fn write_question(resp: Resp) { + let file = format!("src/bin/{}.rs", resp.data.question.title_slug); + if std::path::Path::new(file.as_str()).exists() { + println!("{} exists", file); + return; + } + + let mut f = File::create(file.as_str()).unwrap(); + let mut s = String::new(); + s.push_str("fn main() {}\n\nstruct Solution;\n\n"); + + for i in resp.data.question.code_snippets { + if i.lang == "Rust" { + s.push_str(i.code.replace("↵", "\n").as_str()); + s.push_str("\n"); + break; + } + } + + f.write_all(s.as_bytes()).unwrap(); +} + +/// 解析README.md +pub fn parse_readme() -> Vec { + let contents = fs::read_to_string("README.md").unwrap(); + parse(&contents) +} + +fn parse(contents: &str) -> Vec { + let mut v = vec![]; + for content in contents.split('\n') { + for i in RE.captures_iter(content.trim()) { + v.push(Resp { + data: Data { + question: Ques { + question_id: i.get(1).unwrap().as_str().to_string(), + translated_title: i.get(2).unwrap().as_str().to_string(), + title_slug: String::new(), + code_snippets: vec![], + difficulty: String::new() + } + }, + }) + } + } + + v +} + +#[cfg(test)] +mod tests { + use crate::file::{parse, get_all_bin_file}; + + #[test] + fn test_parse_readme() { + let content = r"| 1111 | 两数之和| [src](https://github.com/rustors/leetcode/blob/main/src/bin/two_sum.rs) | [leetcode](https://leetcode-cn.com/problems/two_sum/) | + | 1112 | 两数之和| [src](https://github.com/rustors/leetcode/blob/main/src/bin/two_sum.rs) | [leetcode](https://leetcode-cn.com/problems/two_sum/) | + "; + + println!("{:?}", parse(content)); + } + + #[test] + fn test_get_all_bin_file() { + println!("{:?}", get_all_bin_file()); + } +} \ No newline at end of file diff --git a/src/git.rs b/src/git.rs new file mode 100644 index 00000000..fb9591b8 --- /dev/null +++ b/src/git.rs @@ -0,0 +1,62 @@ +use git2::{Repository, StatusOptions}; + +use std::process::Command; + +/// 把新文件加入到git中 +pub fn push() { + // 解析readme.md文件 + let mut r = crate::file::parse_readme(); + let new_file = get_uncommit_files(); + for i in new_file.iter() { + let x = i.trim_end_matches(".rs"); // 去掉后缀 + let x = x.trim_start_matches("src/bin/"); // 去掉路径 + git_add(i); + r.push(crate::http::get_question_info(x)); + } + + crate::file::write_readme(&mut r); + git_add("README.md"); + push_to_origin(); +} + + +fn get_uncommit_files() -> Vec { + let mut options = StatusOptions::new(); + options.pathspec("src/bin"); + options.include_untracked(true); + let repo = Repository::open(".").unwrap(); + let statuses = repo.statuses(Some(&mut options)).unwrap(); + + statuses + .iter() + .map(|x| String::from(x.path().unwrap())) + .collect() +} + +fn git_add(file: &str) { + Command::new("git").arg("add").arg(file).output().unwrap(); + let output = Command::new("git") + .arg("commit") + .arg("-m") + .arg(file) + .output() + .unwrap(); + + println!("{}", String::from_utf8(output.stdout).unwrap()); +} + +pub fn push_to_origin() { + let output = Command::new("git").arg("push").output().unwrap(); + println!("{}", String::from_utf8(output.stdout).unwrap()); +} + + +#[cfg(test)] +mod tests { + use crate::git::get_uncommit_files; + + #[test] + fn test_get_uncommit_files() { + println!("{:?}", get_uncommit_files()); + } +} \ No newline at end of file diff --git a/src/http.rs b/src/http.rs new file mode 100644 index 00000000..e7945e9f --- /dev/null +++ b/src/http.rs @@ -0,0 +1,77 @@ +use lazy_static::lazy_static; +use regex::Regex; +use reqwest::blocking::Client; +use serde::{Serialize, Deserialize}; + + +lazy_static! { + static ref RE: Regex = Regex::new(r".*?/problems/(.*?)/").unwrap(); +} + +const URL: &'static str = "https://leetcode-cn.com/graphql/"; + +#[derive(Deserialize, Serialize, Debug)] +pub struct Ques { + #[serde(rename = "questionId")] + pub question_id: String, + #[serde(rename = "titleSlug")] + pub title_slug: String, + #[serde(rename = "translatedTitle")] + pub translated_title: String, + #[serde(rename = "codeSnippets")] + pub code_snippets: Vec, + #[serde(rename = "difficulty")] + pub difficulty: String, +} + +#[derive(Deserialize, Serialize, Debug)] +pub struct CodeSnippets { + #[serde(rename = "code")] + pub code: String, + #[serde(rename = "lang")] + pub lang: String, + #[serde(rename = "langSlug")] + pub lang_slug: String, + #[serde(rename = "__typename")] + pub typename: String, +} + +#[derive(Deserialize, Serialize, Debug)] +pub struct Data { + pub question: Ques, +} + +#[derive(Deserialize, Serialize, Debug)] +pub struct Resp { + pub data: Data, +} + +pub fn get_question_info(mut ques: &str) -> Resp { + if ques.starts_with("http") { + ques = RE.captures_iter(ques).next().unwrap().get(1).unwrap().as_str(); + } + + let data_fmt = r#"{"operationName":"questionData","variables":{"titleSlug":"{}"}, + "query":"query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n boundTopicId\n title\n titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n contributors {\n username\n profileUrl\n avatarUrl\n __typename\n }\n langToValidPlayground\n topicTags {\n name\n slug\n translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n lang\n langSlug\n code\n __typename\n }\n stats\n hints\n solution {\n id\n canSeeDetail\n __typename\n }\n status\n sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n enableRunCode\n envInfo\n book {\n id\n bookName\n pressName\n source\n shortDescription\n fullDescription\n bookImgUrl\n pressImgUrl\n productUrl\n __typename\n }\n isSubscribed\n isDailyQuestion\n dailyRecordStatus\n editorType\n ugcQuestionId\n style\n __typename\n }\n}\n"}"#; + let data = data_fmt.replace("{}", ques); + + Client::new() + .post(URL) + .header("content-type", "application/json") + .body(data) + .send() + .unwrap() + .json::() + .unwrap() +} + +#[cfg(test)] +mod tests { + use crate::http::get_question_info; + + #[test] + fn test_get_question_info() { + println!("{:?}", get_question_info("container-with-most-water")); + println!("{:?}", get_question_info("https://leetcode-cn.com/problems/container-with-most-water/")); + } +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 00000000..6cba206c --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,34 @@ +mod new; +mod http; +mod file; +mod git; +mod render; +mod all; + +use clap::{App, Arg}; + +pub fn run() { + let matches = App::new("leetcode") + .version("0.0.1") + .author("bestgopher <84328409@qq.com>") + .about("a helper for leetcode") + .subcommand(App::new("new") + .about("get a new leetcode question") + .arg(Arg::new("question_name") + .about("The configuration file to use") + .index(1))) + .subcommand(App::new("all") + .about("get all questions' info and rewrite README.md")) + .get_matches(); + + if let Some(matches) = matches.subcommand_matches("new") { + match matches.value_of_t::("question_name") { + Ok(x) => new::new(x), + Err(_) => println!("please input the name of question") + } + } else if let Some(_) = matches.subcommand_matches("all") { + all::all(); + } else { + git::push(); + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 00000000..53eb0abd --- /dev/null +++ b/src/main.rs @@ -0,0 +1,5 @@ +use leetcode; + +fn main() { + leetcode::run() +} diff --git a/src/new.rs b/src/new.rs new file mode 100644 index 00000000..9b1599ac --- /dev/null +++ b/src/new.rs @@ -0,0 +1,8 @@ +/// 1.获取question name +/// 2.如果name是url,就不需要拼装,不是就需要拼装 +/// 3.请求结构,获取数据 +/// 4.将数据写入bin/{question_name}.rs文件中 +pub fn new(ques: String) { + let r = crate::http::get_question_info(ques.as_str()); + crate::file::write_question(r); +} diff --git a/src/render.rs b/src/render.rs new file mode 100644 index 00000000..5afff45e --- /dev/null +++ b/src/render.rs @@ -0,0 +1,62 @@ +use lazy_static::lazy_static; +use tera::{Tera, Context, Error as TeraError, ErrorKind, Result as TeraResult}; + +/// 模板内容 +const TEMPLATE_STR: &'static str = r"# leetcode + +当前已刷:{{ datas | length }} + +### 题目 + +| 编号 | 题目 | 描述 | 代码 | +| ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | +{% for t in datas %}|{{ t.data.question.questionId }} | {{ t.data.question.translatedTitle }} | [src](https://github.com/rustors/leetcode/blob/main/src/bin/{{ t.data.question.titleSlug }}.rs) | [leetcode](https://leetcode-cn.com/problems/{{ t.data.question.titleSlug }}) | +{% endfor %}"; + +static A: &str = ""; + +/// 模板名字 +const TEMPLATE_NAME: &'static str = "leetcode"; + +lazy_static!( + /// 用于渲染的模板 + pub static ref TEMPLATE: Tera = { + let mut tera = Tera::default(); + tera.add_raw_template(TEMPLATE_NAME, TEMPLATE_STR).unwrap(); + tera + }; +); + + +/// 把传入的内容渲染为模板内容 +pub fn render(data: &Vec) -> TeraResult { + let mut ctx = Context::new(); + ctx.insert("datas", data); + + TEMPLATE.render(TEMPLATE_NAME, &ctx) +} + +#[cfg(test)] +mod tests { + use crate::http::{Resp, Ques, Data}; + use crate::render::render; + + #[test] + fn test_render() { + let data = vec![ + Resp { + data: Data { + question: Ques { + question_id: "111".to_string(), + title_slug: "aaa".to_string(), + translated_title: "中国".to_string(), + code_snippets: vec![], + difficulty: String::new(); + } + }, + }, + ]; + + println!("{:?}", render(&data).unwrap().to_string()); + } +} \ No newline at end of file From f5fdb992fef0060d8980d3289ec99f50d4e350b5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 21:15:27 +0800 Subject: [PATCH 0023/1556] remove file --- src/lib_bak.rs | 295 ------------------------------------------------ src/main_bak.rs | 66 ----------- 2 files changed, 361 deletions(-) delete mode 100644 src/lib_bak.rs delete mode 100644 src/main_bak.rs diff --git a/src/lib_bak.rs b/src/lib_bak.rs deleted file mode 100644 index 914ce1c3..00000000 --- a/src/lib_bak.rs +++ /dev/null @@ -1,295 +0,0 @@ -#[cfg(test)] -mod tests { - use super::*; - use crate::{get_new_file_in_bin, get_question_msg, get_question_num}; - - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } - - #[test] - fn test_get_new_file_in_bin() { - println!("{:?}", get_new_file_in_bin()); - } - - #[test] - fn test_get_question_num() { - assert_eq!(13usize, get_question_num()); - } - - #[test] - fn test_write_to_readme() { - let resp = get_question_msg("maximum-points-you-can-obtain-from-cards"); - write_to_readme(resp); - } - - #[test] - fn test_get_question_no() { - assert_eq!(374, get_question_no("- 374:猜数字大小")); - assert_eq!(367, get_question_no("- 367:有效的完全平方数")); - } - - #[test] - fn test_get_question_msg() { - println!( - "{:?}", - get_question_msg("maximum-points-you-can-obtain-from-cards") - ); - } - - #[test] - fn test_make_new_file() { - make_new_file(get_question_msg("shu-de-zi-jie-gou-lcof")); - } -} - -extern crate reqwest; - -use git2::{Repository, StatusOptions}; -use serde::Deserialize; -use std::fs::{self, File}; -use std::io::Write; -use std::process::Command; - -/// 获取bin目录下新加的文件 -pub fn get_new_file_in_bin() -> Vec { - let mut options = StatusOptions::new(); - options.include_untracked(true); - let repo = Repository::open(".").unwrap(); - let statuses = repo.statuses(Some(&mut options)).unwrap(); - - statuses - .iter() - .filter(|x| x.path().unwrap().starts_with("src/bin/")) - .map(|x| String::from(x.path().unwrap())) - .map(|x| { - let x = x.trim_end_matches(".rs"); // 去掉路径 - let x = x.trim_start_matches("src/bin/"); // 去掉后缀 - x.to_string() - }) - .collect() -} - -#[derive(Deserialize, Debug)] -pub struct Ques { - #[serde(rename = "questionId")] - question_id: String, - #[serde(rename = "titleSlug")] - title_slug: String, - #[serde(rename = "translatedTitle")] - pub translated_title: String, - #[serde(rename = "codeSnippets")] - code_snippets: Vec, -} - -#[derive(Deserialize, Debug)] -pub struct CodeSnippets { - #[serde(rename = "code")] - code: String, - #[serde(rename = "lang")] - lang: String, - #[serde(rename = "langSlug")] - lang_slug: String, - #[serde(rename = "__typename")] - typename: String, -} - -#[derive(Deserialize, Debug)] -pub struct Data { - pub question: Ques, -} - -#[derive(Deserialize, Debug)] -pub struct Resp { - pub data: Data, -} - -/// 通过名字获取题目的ID -pub fn get_question_msg(name: &str) -> Resp { - let url = "https://leetcode-cn.com/graphql/"; - let data_fmt = r#"{"operationName":"questionData","variables":{"titleSlug":"{}"},"query":"query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n boundTopicId\n title\n titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n contributors {\n username\n profileUrl\n avatarUrl\n __typename\n }\n langToValidPlayground\n topicTags {\n name\n slug\n translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n lang\n langSlug\n code\n __typename\n }\n stats\n hints\n solution {\n id\n canSeeDetail\n __typename\n }\n status\n sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n enableRunCode\n envInfo\n book {\n id\n bookName\n pressName\n source\n shortDescription\n fullDescription\n bookImgUrl\n pressImgUrl\n productUrl\n __typename\n }\n isSubscribed\n isDailyQuestion\n dailyRecordStatus\n editorType\n ugcQuestionId\n style\n __typename\n }\n}\n"}"#; - let data = data_fmt.replace("{}", name); - reqwest::blocking::Client::new() - .post(url) - .header("content-type", "application/json") - .body(data) - .send() - .unwrap() - .json::() - .unwrap() -} - -/// 把问题写到README.md中 -pub fn write_to_readme(question_info: Resp) { - let readme = fs::read_to_string("README.md").unwrap(); - let mut write_string = String::new(); - write_string.push_str("# leetcode\n\n"); - write_string.push_str(format!("当前已刷:{}\n\n", get_question_num()).as_str()); - write_string.push_str("### 题目\n"); - - let mut f = File::create("README.md").unwrap(); - - let mut index = 0usize; - let split = readme.split('\n').into_iter().collect::>(); - let mut flag = false; - let mut flag1 = false; - let no = question_info - .data - .question - .question_id - .parse::() - .unwrap(); - while index + 3 < split.len() { - if !flag { - if split[index] == "### 题目" { - flag = true; - } - index += 1; - continue; - } - - let i1 = get_question_no(split[index]); - - if i1 == no { - continue; - } - - if !flag1 && i1 > no { - flag1 = true; - write_string.push_str( - format!( - "- {}:{}\n", - no, question_info.data.question.translated_title - ) - .as_str(), - ); - write_string.push_str( - format!( - " - [src](https://github.com/rustors/leetcode/blob/main/src/bin/{}.rs)\n", - question_info.data.question.title_slug - ) - .as_str(), - ); - write_string.push_str( - format!( - " - [leetcode](https://leetcode-cn.com/problems/{}/)\n", - question_info.data.question.title_slug - ) - .as_str(), - ); - } - - write_string.push_str( - format!( - "{}\n{}\n{}\n", - split[index], - split[index + 1], - split[index + 2] - ) - .as_str(), - ); - index += 3; - } - - if !flag1 { - write_string.push_str( - format!( - "- {}:{}\n", - no, question_info.data.question.translated_title - ) - .as_str(), - ); - write_string.push_str( - format!( - " - [src](https://github.com/rustors/leetcode/blob/main/src/bin/{}.rs)\n", - question_info.data.question.title_slug - ) - .as_str(), - ); - write_string.push_str( - format!( - " - [leetcode](https://leetcode-cn.com/problems/{}/)\n", - question_info.data.question.title_slug - ) - .as_str(), - ); - } - - let _ = f.write(write_string.as_bytes()); -} - -/// 获取题目总数 -fn get_question_num() -> usize { - let dir = fs::read_dir("src/bin/").unwrap(); - - dir.into_iter() - .filter(|x| { - if let Ok(f) = x { - f.file_name().to_str().unwrap().ends_with(".rs") - } else { - false - } - }) - .count() -} - -/// 获取题目的编号 -fn get_question_no(s: &str) -> i32 { - s.split(':').into_iter().collect::>()[0] - .trim_end_matches(':') - .trim_start_matches('-') - .trim_start() - .parse::() - .unwrap() -} - -/// git add -pub fn git_add_commit_files(files: Vec) { - for file in files.iter() { - add_and_commit(format!("src/bin/{}.rs", file).as_str()); // 将新加的文件提交到git仓库 - } - - add_and_commit("README.md"); // 将修改的README.md提交到git仓库 - push_to_origin(); // 将文件 -} - -pub fn add_and_commit(file: &str) { - Command::new("git").arg("add").arg(file).output().unwrap(); - let output = Command::new("git") - .arg("commit") - .arg("-m") - .arg(file) - .output() - .unwrap(); - - println!("{}", String::from_utf8(output.stdout).unwrap()); -} - -pub fn push_to_origin() { - let output = Command::new("git").arg("push").output().unwrap(); - println!("{}", String::from_utf8(output.stdout).unwrap()); -} - -/// 通过题目名获取rust答题模板 -pub fn make_new_file(resp: Resp) { - let file = format!("src/bin/{}.rs", resp.data.question.title_slug); - if std::path::Path::new(file.as_str()).exists() { - println!("{} exists", file); - return; - } - - let mut f = File::create(file.as_str()).unwrap(); - let mut s = String::new(); - s.push_str("fn main() {}\n\nstruct Solution;\n\n"); - - for i in resp.data.question.code_snippets { - if i.lang == "Rust" { - s.push_str(i.code.replace("↵", "\n").as_str()); - s.push_str("\n"); - break; - } - } - - f.write_all(s.as_bytes()).unwrap(); -} diff --git a/src/main_bak.rs b/src/main_bak.rs deleted file mode 100644 index 10aa678f..00000000 --- a/src/main_bak.rs +++ /dev/null @@ -1,66 +0,0 @@ -///! 根据src/bin中新加的题目生成相应的markdown文件 -use leetcode; -use leetcode::{get_question_msg, write_to_readme}; - -fn main() { - let args = std::env::args().collect::>(); - if args.len() == 1 { - git(); - } else if args.len() == 2 { - if args[1].as_str() == "-a" { - all(); - } else { - new(args[1].as_str()); - } - } else { - panic!("只能有一个参数"); - } -} - -fn git() { - // 获取新加的文件 - let files = leetcode::get_new_file_in_bin(); - - for i in files.iter() { - let res = leetcode::get_question_msg(i); - leetcode::write_to_readme(res); - } - - leetcode::git_add_commit_files(files); -} - -fn all() { - let files = std::fs::read_dir("./src/bin").unwrap(); - let files = files - .into_iter() - .filter(|x| { - if let Ok(f) = x { - f.file_name().to_str().unwrap().ends_with(".rs") - } else { - false - } - }) - .map(|x| { - x.unwrap() - .file_name() - .to_str() - .unwrap() - .trim_end_matches(".rs") - .trim_start_matches("src/bin/") - .to_string() - }) - .collect::>(); - files.iter().for_each(|x| { - println!("{} start", x); - let resp = get_question_msg(x); - write_to_readme(resp); - }); - - leetcode::add_and_commit("README.md"); - leetcode::push_to_origin(); -} - -fn new(filename: &str) { - let resp = leetcode::get_question_msg(filename); - leetcode::make_new_file(resp); -} From bf03c665c888baf2af21735f52dfc9c7fe67aa1f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 21:27:30 +0800 Subject: [PATCH 0024/1556] cargo clippy project --- README.md | 452 ++++++++++-------- src/all.rs | 5 +- src/bin/boats-to-save-people.rs | 2 +- src/bin/climbing-stairs.rs | 4 +- src/bin/combination-sum.rs | 2 +- ...ary-search-tree-from-preorder-traversal.rs | 2 +- src/bin/count-complete-tree-nodes.rs | 6 +- src/bin/fei-bo-na-qi-shu-lie-lcof.rs | 2 +- src/bin/find-k-closest-elements.rs | 2 +- src/bin/group-anagrams.rs | 4 +- src/bin/kth-largest-element-in-an-array.rs | 2 +- ...ber-of-unique-integers-after-k-removals.rs | 2 +- src/bin/letter-case-permutation.rs | 2 +- ...-substring-without-repeating-characters.rs | 2 +- src/bin/magical-string.rs | 2 +- src/bin/majority-element-ii.rs | 6 +- src/bin/maximum-product-of-word-lengths.rs | 2 +- src/bin/number-complement.rs | 2 +- src/bin/qiu-12n-lcof.rs | 5 +- src/bin/reverse-linked-list.rs | 2 +- src/bin/reverse-words-in-a-string.rs | 2 +- src/bin/robot-bounded-in-circle.rs | 2 +- src/bin/search-in-rotated-sorted-array.rs | 2 +- src/bin/sqrtx.rs | 2 +- src/bin/summary-ranges.rs | 2 +- src/bin/swapping-nodes-in-a-linked-list.rs | 4 +- src/file.rs | 2 +- src/http.rs | 2 +- src/lib.rs | 2 +- src/main.rs | 2 - src/render.rs | 12 +- 31 files changed, 293 insertions(+), 249 deletions(-) diff --git a/README.md b/README.md index 664b7927..ee9218fa 100644 --- a/README.md +++ b/README.md @@ -1,211 +1,255 @@ # leetcode -当前已刷:203 +当前已刷:247 ### 题目 | 编号 | 题目 | 描述 | 代码 | | ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | -|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum) | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers) | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters) | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays) | +|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion) | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer) | +|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi) | +|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number) | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water) | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman) | +|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer) | +|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix) | +|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum) | +|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest) | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number) | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum) | +|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list) | +|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses) | +|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists) | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists) | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs) | +|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group) | +|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array) | +|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element) | +|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr) | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation) | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array) | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array) | +|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position) | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku) | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say) | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum) | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive) | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings) | +|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii) | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations) | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image) | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams) | +|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n) | +|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens) | +|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii) | +|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray) | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game) | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals) | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval) | +|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word) | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths) | +|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii) | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum) | +|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one) | +|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary) | +|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx) | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs) | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path) | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes) | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix) | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors) | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations) | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets) | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search) | +|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii) | +|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii) | +|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii) | +|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list) | +|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array) | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code) | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways) | +|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses) | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal) | +|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii) | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees) | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree) | +|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree) | +|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree) | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal) | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal) | +|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree) | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | +|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii) | +|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree) | +|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree) | +|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree) | +|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum) | +|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii) | +|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle) | +|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii) | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle) | +|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock) | +|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii) | +|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome) | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers) | +|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number) | +|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii) | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal) | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal) | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation) | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string) | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray) | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array) | +|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack) | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element) | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers) | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal) | +|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted) | +|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title) | +|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element) | +|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number) | +|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes) | +|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator) | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences) | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits) | +|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits) | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber) | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view) | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands) | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range) | +|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number) | +|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements) | +|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes) | +|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings) | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list) | +|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree) | +|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure) | +|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii) | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array) | +|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii) | +|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate) | +|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii) | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes) | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area) | +|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues) | +|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree) | +|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges) | +|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii) | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst) | +|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two) | +|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks) | +|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list) | +|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self) | +|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram) | +|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths) | +|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits) | +|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number) | +|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number) | +|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index) | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version) | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares) | +|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern) | +|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable) | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths) | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher) | +|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three) | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays) | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits) | +|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square) | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers) | +|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower) | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string) | +|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves) | +|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board) | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english) | +|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string) | +|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement) | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string) | +|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row) | +|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital) | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list) | +|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i) | +|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k) | +|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting) | +|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence) | +|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees) | +|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate) | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard) | +|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst) | +|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements) | +|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence) | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation) | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline) | +|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count) | +|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups) | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes) | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people) | +|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii) | +|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap) | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal) | +|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array) | +|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match) | +|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted) | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique) | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp) | +|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree) | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences) | +|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii) | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal) | +|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer) | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list) | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle) | +|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string) | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths) | +|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements) | +|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path) | +|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops) | +|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii) | +|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings) | +|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability) | +|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays) | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses) | +|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix) | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree) | +|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer) | +|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero) | +|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii) | +|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c) | +|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist) | +|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string) | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards) | +|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations) | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length) | +|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array) | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals) | +|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k) | +|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles) | +|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets) | +|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator) | +|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great) | +|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth) | +|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation) | +|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament) | +|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers) | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year) | +|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof) | +|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof) | +|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof) | +|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof) | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof) | +|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof) | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof) | +|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof) | +|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci) | +|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci) | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci) | +|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi) | diff --git a/src/all.rs b/src/all.rs index 32ced734..31a783c2 100644 --- a/src/all.rs +++ b/src/all.rs @@ -9,7 +9,7 @@ use crate::http::Resp; pub fn all() { let files = file::get_all_bin_file(); - let mut v = Vec::::with_capacity(files.len()); + let v = Vec::::with_capacity(files.len()); let x = Arc::new(Mutex::new(v)); let mut handlers = vec![]; @@ -26,6 +26,7 @@ pub fn all() { handlers.push(thread::spawn(move || { for i in files { + println!("{} downloading", i); let resp = crate::http::get_question_info(&i); x.lock().unwrap().push(resp); } @@ -33,7 +34,7 @@ pub fn all() { } for i in handlers { - i.join(); + i.join().unwrap(); } crate::file::write_readme(&mut *x.lock().unwrap()); diff --git a/src/bin/boats-to-save-people.rs b/src/bin/boats-to-save-people.rs index 9f622e60..f1306380 100644 --- a/src/bin/boats-to-save-people.rs +++ b/src/bin/boats-to-save-people.rs @@ -44,7 +44,7 @@ impl Solution { count } - pub fn num_rescue_boats(mut people: Vec, limit: i32) -> i32 { + pub fn num_rescue_boats(people: Vec, limit: i32) -> i32 { let mut v = vec![0; (limit + 1) as usize]; for i in people { diff --git a/src/bin/climbing-stairs.rs b/src/bin/climbing-stairs.rs index f59f0560..e9c3e658 100644 --- a/src/bin/climbing-stairs.rs +++ b/src/bin/climbing-stairs.rs @@ -1,4 +1,4 @@ -use std::ptr::hash; + fn main() {} @@ -12,7 +12,7 @@ impl Solution { let (mut a, mut b) = (1, 2); - for i in 3..=n { + for _i in 3..=n { let a1 = a; a = b; b = a1 + b; diff --git a/src/bin/combination-sum.rs b/src/bin/combination-sum.rs index c3d7d6f3..42b0463e 100644 --- a/src/bin/combination-sum.rs +++ b/src/bin/combination-sum.rs @@ -22,7 +22,7 @@ impl Solution { v.push(i); r.push(v); } else if i < target { - let mut x = Self::calc(&candidates, target - i); + let x = Self::calc(&candidates, target - i); for mut m in x { if !m.is_empty() { if i >= *m.last().unwrap() { diff --git a/src/bin/construct-binary-search-tree-from-preorder-traversal.rs b/src/bin/construct-binary-search-tree-from-preorder-traversal.rs index f03dcc6d..8c505305 100644 --- a/src/bin/construct-binary-search-tree-from-preorder-traversal.rs +++ b/src/bin/construct-binary-search-tree-from-preorder-traversal.rs @@ -23,7 +23,7 @@ impl TreeNode { } use std::cell::RefCell; -use std::ops::Deref; + use std::rc::Rc; struct Solution; diff --git a/src/bin/count-complete-tree-nodes.rs b/src/bin/count-complete-tree-nodes.rs index be465592..c6a5e45f 100644 --- a/src/bin/count-complete-tree-nodes.rs +++ b/src/bin/count-complete-tree-nodes.rs @@ -21,9 +21,9 @@ impl TreeNode { } } -use std::arch::x86_64::_mm_xor_pd; + use std::cell::RefCell; -use std::cmp::{max, min}; + use std::rc::Rc; impl Solution { @@ -70,7 +70,7 @@ impl Solution { } while max_count - min_count > 1 { - let mut middle = (min_count + max_count) / 2; + let middle = (min_count + max_count) / 2; let e = exists(root.as_ref(), middle, level); if e { diff --git a/src/bin/fei-bo-na-qi-shu-lie-lcof.rs b/src/bin/fei-bo-na-qi-shu-lie-lcof.rs index b31eb2b8..d46a7f45 100644 --- a/src/bin/fei-bo-na-qi-shu-lie-lcof.rs +++ b/src/bin/fei-bo-na-qi-shu-lie-lcof.rs @@ -8,7 +8,7 @@ impl Solution { return n; } let (mut last, mut result) = (1, 1); - for i in 2..n { + for _i in 2..n { let result1 = result + last; last = result; result = result1 % 1000000007; diff --git a/src/bin/find-k-closest-elements.rs b/src/bin/find-k-closest-elements.rs index 400413a1..3cca7127 100644 --- a/src/bin/find-k-closest-elements.rs +++ b/src/bin/find-k-closest-elements.rs @@ -27,7 +27,7 @@ impl Solution { } let index = Self::split(&arr, x); - let (mut start, mut end, mut k) = (index, index, k as usize); + let (mut start, mut end, k) = (index, index, k as usize); while end - start < k - 1 { if start == 0 { end += 1; diff --git a/src/bin/group-anagrams.rs b/src/bin/group-anagrams.rs index 6930c5b7..2f8aa01f 100644 --- a/src/bin/group-anagrams.rs +++ b/src/bin/group-anagrams.rs @@ -16,7 +16,7 @@ impl Solution { .or_insert(vec![i]); } - hash.into_iter().map(|(x, y)| y).collect() + hash.into_iter().map(|(_x, y)| y).collect() } // 计算字母出现的个数 @@ -37,6 +37,6 @@ impl Solution { } } - hash.into_iter().map(|(x, y)| y).collect() + hash.into_iter().map(|(_x, y)| y).collect() } } diff --git a/src/bin/kth-largest-element-in-an-array.rs b/src/bin/kth-largest-element-in-an-array.rs index 2755ec33..a2d8b662 100644 --- a/src/bin/kth-largest-element-in-an-array.rs +++ b/src/bin/kth-largest-element-in-an-array.rs @@ -17,7 +17,7 @@ impl Solution { } fn heapify(nums: &mut [i32]) { - let mut index = (nums.len() - 1) / 2; + let index = (nums.len() - 1) / 2; for i in (0..=index).rev() { Self::down_heap(nums, i); diff --git a/src/bin/least-number-of-unique-integers-after-k-removals.rs b/src/bin/least-number-of-unique-integers-after-k-removals.rs index 8bb9061c..254eae6c 100644 --- a/src/bin/least-number-of-unique-integers-after-k-removals.rs +++ b/src/bin/least-number-of-unique-integers-after-k-removals.rs @@ -10,7 +10,7 @@ impl Solution { h.entry(i).and_modify(|x| *x += 1).or_insert(1); } - let mut s = h.iter().map(|(x, y)| *y).collect::>(); + let mut s = h.iter().map(|(_x, y)| *y).collect::>(); s.sort(); let (mut l, mut k) = (h.len(), k); diff --git a/src/bin/letter-case-permutation.rs b/src/bin/letter-case-permutation.rs index bfb06fc6..e64a96dd 100644 --- a/src/bin/letter-case-permutation.rs +++ b/src/bin/letter-case-permutation.rs @@ -11,7 +11,7 @@ impl Solution { fn func(s: String, v: &mut Vec, index: usize) { let mut new_s = s.clone(); - let mut new_s = unsafe { new_s.as_bytes_mut() }; + let new_s = unsafe { new_s.as_bytes_mut() }; v.push(s); if index == new_s.len() { return; diff --git a/src/bin/longest-substring-without-repeating-characters.rs b/src/bin/longest-substring-without-repeating-characters.rs index a97941a0..17074cb5 100644 --- a/src/bin/longest-substring-without-repeating-characters.rs +++ b/src/bin/longest-substring-without-repeating-characters.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; + fn main() { assert_eq!(2, Solution::length_of_longest_substring("aab".to_string())); diff --git a/src/bin/magical-string.rs b/src/bin/magical-string.rs index 9c0bb0de..78a2d31d 100644 --- a/src/bin/magical-string.rs +++ b/src/bin/magical-string.rs @@ -3,7 +3,7 @@ fn main() {} struct Solution; impl Solution { - pub fn magical_string(mut n: i32) -> i32 { + pub fn magical_string(n: i32) -> i32 { if n == 0 { return 0; } diff --git a/src/bin/majority-element-ii.rs b/src/bin/majority-element-ii.rs index ebd668a4..da595299 100644 --- a/src/bin/majority-element-ii.rs +++ b/src/bin/majority-element-ii.rs @@ -22,8 +22,8 @@ impl Solution { } m.iter() - .filter(|(&x, &y)| y > length) - .map(|(&x, &y)| x) + .filter(|(&_x, &y)| y > length) + .map(|(&x, &_y)| x) .collect() } @@ -106,7 +106,7 @@ impl Solution { None }) .filter(|x| x.is_some()) - .map(|mut x| x.unwrap()) + .map(|x| x.unwrap()) .collect() } } diff --git a/src/bin/maximum-product-of-word-lengths.rs b/src/bin/maximum-product-of-word-lengths.rs index f4222d3d..5a8a6686 100644 --- a/src/bin/maximum-product-of-word-lengths.rs +++ b/src/bin/maximum-product-of-word-lengths.rs @@ -8,7 +8,7 @@ impl Solution { for i in 0..words.len() { for &j in words[i].as_bytes() { - v[i] |= (1 << (j - b'a')); + v[i] |= 1 << (j - b'a'); } } diff --git a/src/bin/number-complement.rs b/src/bin/number-complement.rs index 4524a6bd..bd555552 100644 --- a/src/bin/number-complement.rs +++ b/src/bin/number-complement.rs @@ -8,7 +8,7 @@ fn main() { struct Solution; impl Solution { - pub fn find_complement(mut num: i32) -> i32 { + pub fn find_complement(num: i32) -> i32 { let lz = num.leading_zeros(); !num << lz >> lz } diff --git a/src/bin/qiu-12n-lcof.rs b/src/bin/qiu-12n-lcof.rs index 6e4f22ea..deecdbe5 100644 --- a/src/bin/qiu-12n-lcof.rs +++ b/src/bin/qiu-12n-lcof.rs @@ -6,7 +6,10 @@ impl Solution { pub fn sum_nums(n: i32) -> i32 { let mut n = n; // 利用布尔短路的思想,n == 0 时,不会允许&&后面的表达式 - n > 0 && (n += Self::sum_nums(n - 1)) == (); + if n > 0 { + n += Self::sum_nums(n - 1); + } + n } } diff --git a/src/bin/reverse-linked-list.rs b/src/bin/reverse-linked-list.rs index eed6ff9e..6d8f19f1 100644 --- a/src/bin/reverse-linked-list.rs +++ b/src/bin/reverse-linked-list.rs @@ -34,7 +34,7 @@ impl Solution { let mut root = v.pop().unwrap(); let mut s = &mut root; while !v.is_empty() { - let mut node = v.pop().unwrap(); + let node = v.pop().unwrap(); s.as_mut().unwrap().next = node; s = &mut s.as_mut().unwrap().next; } diff --git a/src/bin/reverse-words-in-a-string.rs b/src/bin/reverse-words-in-a-string.rs index b8ea1f8e..9d7b1982 100644 --- a/src/bin/reverse-words-in-a-string.rs +++ b/src/bin/reverse-words-in-a-string.rs @@ -7,7 +7,7 @@ impl Solution { if s.is_empty() { return s; } - let mut s = s.as_bytes(); + let s = s.as_bytes(); let (mut start, mut end) = (0, s.len() - 1); for i in 0..s.len() { diff --git a/src/bin/robot-bounded-in-circle.rs b/src/bin/robot-bounded-in-circle.rs index 36835226..22c9c478 100644 --- a/src/bin/robot-bounded-in-circle.rs +++ b/src/bin/robot-bounded-in-circle.rs @@ -6,7 +6,7 @@ struct Solution; impl Solution { /// 只有(x,y)不是原点,并且方向和原来的方向一致,最后才回不去 - pub fn is_robot_bounded(mut instructions: String) -> bool { + pub fn is_robot_bounded(instructions: String) -> bool { let mut start = (0, 0); let mut direction = 0u8; // 当前的方向,0为向前,1为向左,2为向后,3为向右 diff --git a/src/bin/search-in-rotated-sorted-array.rs b/src/bin/search-in-rotated-sorted-array.rs index c4aa4ee8..469d17ee 100644 --- a/src/bin/search-in-rotated-sorted-array.rs +++ b/src/bin/search-in-rotated-sorted-array.rs @@ -1,4 +1,4 @@ -use std::os::macos::raw::stat; + fn main() { assert_eq!(4, Solution::search(vec![4, 5, 6, 7, 8, 1, 2, 3], 8)); diff --git a/src/bin/sqrtx.rs b/src/bin/sqrtx.rs index d50cceeb..d0aa6ef9 100644 --- a/src/bin/sqrtx.rs +++ b/src/bin/sqrtx.rs @@ -4,7 +4,7 @@ struct Solution; impl Solution { pub fn my_sqrt(x: i32) -> i32 { - let mut s = x as f64; + let s = x as f64; let mut x1 = x as f64; while (s - x1 * x1).abs() > 0.1 { diff --git a/src/bin/summary-ranges.rs b/src/bin/summary-ranges.rs index bce0649f..263dfb5e 100644 --- a/src/bin/summary-ranges.rs +++ b/src/bin/summary-ranges.rs @@ -1,4 +1,4 @@ -use serde_json::ser::CharEscape::Solidus; + fn main() { println!("{:?}", Solution::summary_ranges(vec![0, 1, 2, 4, 5, 7])); diff --git a/src/bin/swapping-nodes-in-a-linked-list.rs b/src/bin/swapping-nodes-in-a-linked-list.rs index 9519281d..61d8f29e 100644 --- a/src/bin/swapping-nodes-in-a-linked-list.rs +++ b/src/bin/swapping-nodes-in-a-linked-list.rs @@ -58,8 +58,8 @@ impl Solution { index += 1; } - let f = k_node.unwrap().val; - let s = slow.unwrap().val; + let _f = k_node.unwrap().val; + let _s = slow.unwrap().val; head } diff --git a/src/file.rs b/src/file.rs index c7a15ab2..6bc7407d 100644 --- a/src/file.rs +++ b/src/file.rs @@ -52,7 +52,7 @@ pub fn write_question(resp: Resp) { for i in resp.data.question.code_snippets { if i.lang == "Rust" { s.push_str(i.code.replace("↵", "\n").as_str()); - s.push_str("\n"); + s.push('\n'); break; } } diff --git a/src/http.rs b/src/http.rs index e7945e9f..b8a45026 100644 --- a/src/http.rs +++ b/src/http.rs @@ -8,7 +8,7 @@ lazy_static! { static ref RE: Regex = Regex::new(r".*?/problems/(.*?)/").unwrap(); } -const URL: &'static str = "https://leetcode-cn.com/graphql/"; +const URL: &str = "https://leetcode-cn.com/graphql/"; #[derive(Deserialize, Serialize, Debug)] pub struct Ques { diff --git a/src/lib.rs b/src/lib.rs index 6cba206c..993a91c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,7 @@ pub fn run() { Ok(x) => new::new(x), Err(_) => println!("please input the name of question") } - } else if let Some(_) = matches.subcommand_matches("all") { + } else if matches.subcommand_matches("all").is_some() { all::all(); } else { git::push(); diff --git a/src/main.rs b/src/main.rs index 53eb0abd..449447a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,3 @@ -use leetcode; - fn main() { leetcode::run() } diff --git a/src/render.rs b/src/render.rs index 5afff45e..ceb39fda 100644 --- a/src/render.rs +++ b/src/render.rs @@ -1,8 +1,8 @@ use lazy_static::lazy_static; -use tera::{Tera, Context, Error as TeraError, ErrorKind, Result as TeraResult}; +use tera::{Tera, Context, Result as TeraResult}; /// 模板内容 -const TEMPLATE_STR: &'static str = r"# leetcode +const TEMPLATE_STR: &str = r"# leetcode 当前已刷:{{ datas | length }} @@ -13,10 +13,8 @@ const TEMPLATE_STR: &'static str = r"# leetcode {% for t in datas %}|{{ t.data.question.questionId }} | {{ t.data.question.translatedTitle }} | [src](https://github.com/rustors/leetcode/blob/main/src/bin/{{ t.data.question.titleSlug }}.rs) | [leetcode](https://leetcode-cn.com/problems/{{ t.data.question.titleSlug }}) | {% endfor %}"; -static A: &str = ""; - /// 模板名字 -const TEMPLATE_NAME: &'static str = "leetcode"; +const TEMPLATE_NAME: &str = "leetcode"; lazy_static!( /// 用于渲染的模板 @@ -29,7 +27,7 @@ lazy_static!( /// 把传入的内容渲染为模板内容 -pub fn render(data: &Vec) -> TeraResult { +pub fn render(data: &[crate::http::Resp]) -> TeraResult { let mut ctx = Context::new(); ctx.insert("datas", data); @@ -51,7 +49,7 @@ mod tests { title_slug: "aaa".to_string(), translated_title: "中国".to_string(), code_snippets: vec![], - difficulty: String::new(); + difficulty: String::new(), } }, }, From 6c448231daea31d70e8093eae8eb9ece6293867f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 21:27:38 +0800 Subject: [PATCH 0025/1556] README.md --- README.md | 451 ++++++++++++++++++++++++------------------------------ 1 file changed, 203 insertions(+), 248 deletions(-) diff --git a/README.md b/README.md index ee9218fa..a80e1463 100644 --- a/README.md +++ b/README.md @@ -1,255 +1,210 @@ # leetcode -当前已刷:247 +当前已刷:202 ### 题目 | 编号 | 题目 | 描述 | 代码 | | ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | -|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum) | -|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers) | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters) | -|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays) | -|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion) | -|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer) | -|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi) | -|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number) | -|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water) | -|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman) | -|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer) | -|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix) | -|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum) | -|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest) | -|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number) | -|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum) | -|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list) | -|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses) | -|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists) | -|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists) | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs) | -|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group) | -|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array) | -|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element) | -|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr) | -|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation) | -|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array) | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array) | -|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position) | -|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku) | -|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say) | -|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum) | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive) | -|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings) | -|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii) | -|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations) | -|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image) | -|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams) | -|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n) | -|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens) | -|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii) | -|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray) | -|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game) | -|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals) | -|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval) | -|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word) | -|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths) | -|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii) | -|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum) | -|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one) | -|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary) | -|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx) | -|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs) | -|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path) | -|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes) | -|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix) | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors) | -|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations) | -|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets) | -|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search) | -|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii) | -|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii) | -|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii) | -|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list) | -|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array) | -|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code) | -|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways) | -|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses) | -|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal) | -|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii) | -|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees) | -|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree) | -|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree) | -|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree) | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal) | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal) | -|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree) | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | -|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii) | -|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree) | -|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree) | -|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree) | -|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum) | -|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii) | -|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle) | -|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii) | -|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle) | -|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock) | -|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii) | -|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome) | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers) | -|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number) | -|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii) | -|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal) | -|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal) | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation) | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string) | -|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray) | -|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array) | -|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack) | -|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element) | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers) | -|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal) | -|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted) | -|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title) | -|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element) | -|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number) | -|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes) | -|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator) | -|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences) | -|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits) | -|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits) | -|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber) | -|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view) | -|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands) | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range) | -|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number) | -|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements) | -|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes) | -|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings) | -|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list) | -|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree) | -|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure) | -|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii) | -|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array) | -|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii) | -|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate) | -|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii) | -|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes) | -|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area) | -|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues) | -|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree) | -|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges) | -|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii) | -|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst) | -|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two) | -|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks) | -|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list) | -|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | -|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self) | -|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram) | -|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths) | -|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits) | -|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number) | -|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number) | -|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index) | -|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version) | -|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares) | -|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern) | -|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable) | -|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths) | -|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher) | -|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three) | -|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays) | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits) | -|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square) | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers) | -|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower) | -|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string) | -|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves) | -|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board) | -|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english) | -|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string) | -|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement) | -|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string) | -|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row) | -|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital) | -|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list) | -|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i) | -|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k) | -|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting) | -|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence) | -|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees) | -|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate) | -|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard) | -|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst) | -|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements) | -|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence) | -|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation) | -|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline) | -|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count) | -|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups) | -|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes) | -|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people) | -|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii) | -|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap) | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal) | -|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array) | -|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match) | -|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted) | -|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique) | -|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp) | -|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree) | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences) | -|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii) | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal) | -|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer) | -|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list) | -|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle) | -|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string) | -|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths) | -|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements) | -|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path) | -|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops) | -|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii) | -|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings) | -|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability) | -|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays) | -|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses) | -|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix) | -|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree) | -|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer) | -|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero) | -|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii) | -|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | -|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c) | -|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist) | -|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string) | -|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards) | -|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations) | -|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | -|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length) | -|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array) | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals) | -|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k) | -|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles) | -|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets) | -|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator) | -|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great) | -|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth) | -|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation) | -|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament) | -|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers) | -|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year) | -|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof) | -|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof) | -|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof) | -|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof) | -|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof) | -|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof) | -|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof) | -|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof) | -|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci) | -|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci) | -|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci) | -|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi) | +|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | From 5ae427acb58ce49b0e459cd2ba9ee0ef92f065c2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 22:47:26 +0800 Subject: [PATCH 0026/1556] fix regex expr error --- README.md | 451 +++++++++++++++++++++++++++----------------------- src/file.rs | 15 +- src/render.rs | 2 +- 3 files changed, 258 insertions(+), 210 deletions(-) diff --git a/README.md b/README.md index a80e1463..ee9218fa 100644 --- a/README.md +++ b/README.md @@ -1,210 +1,255 @@ # leetcode -当前已刷:202 +当前已刷:247 ### 题目 | 编号 | 题目 | 描述 | 代码 | | ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | -|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum) | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers) | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters) | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays) | +|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion) | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer) | +|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi) | +|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number) | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water) | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman) | +|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer) | +|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix) | +|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum) | +|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest) | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number) | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum) | +|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list) | +|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses) | +|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists) | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists) | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs) | +|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group) | +|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array) | +|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element) | +|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr) | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation) | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array) | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array) | +|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position) | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku) | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say) | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum) | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive) | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings) | +|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii) | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations) | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image) | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams) | +|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n) | +|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens) | +|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii) | +|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray) | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game) | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals) | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval) | +|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word) | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths) | +|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii) | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum) | +|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one) | +|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary) | +|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx) | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs) | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path) | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes) | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix) | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors) | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations) | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets) | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search) | +|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii) | +|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii) | +|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii) | +|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list) | +|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array) | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code) | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways) | +|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses) | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal) | +|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii) | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees) | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree) | +|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree) | +|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree) | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal) | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal) | +|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree) | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | +|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii) | +|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree) | +|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree) | +|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree) | +|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum) | +|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii) | +|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle) | +|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii) | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle) | +|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock) | +|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii) | +|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome) | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers) | +|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number) | +|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii) | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal) | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal) | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation) | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string) | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray) | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array) | +|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack) | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element) | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers) | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal) | +|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted) | +|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title) | +|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element) | +|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number) | +|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes) | +|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator) | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences) | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits) | +|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits) | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber) | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view) | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands) | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range) | +|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number) | +|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements) | +|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes) | +|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings) | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list) | +|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree) | +|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure) | +|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii) | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array) | +|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii) | +|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate) | +|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii) | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes) | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area) | +|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues) | +|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree) | +|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges) | +|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii) | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst) | +|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two) | +|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks) | +|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list) | +|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self) | +|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram) | +|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths) | +|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits) | +|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number) | +|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number) | +|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index) | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version) | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares) | +|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern) | +|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable) | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths) | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher) | +|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three) | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays) | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits) | +|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square) | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers) | +|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower) | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string) | +|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves) | +|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board) | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english) | +|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string) | +|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement) | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string) | +|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row) | +|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital) | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list) | +|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i) | +|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k) | +|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting) | +|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence) | +|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees) | +|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate) | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard) | +|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst) | +|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements) | +|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence) | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation) | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline) | +|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count) | +|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups) | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes) | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people) | +|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii) | +|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap) | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal) | +|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array) | +|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match) | +|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted) | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique) | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp) | +|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree) | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences) | +|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii) | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal) | +|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer) | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list) | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle) | +|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string) | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths) | +|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements) | +|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path) | +|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops) | +|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii) | +|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings) | +|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability) | +|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays) | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses) | +|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix) | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree) | +|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer) | +|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero) | +|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii) | +|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c) | +|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist) | +|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string) | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards) | +|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations) | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length) | +|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array) | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals) | +|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k) | +|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles) | +|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets) | +|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator) | +|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great) | +|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth) | +|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation) | +|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament) | +|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers) | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year) | +|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof) | +|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof) | +|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof) | +|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof) | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof) | +|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof) | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof) | +|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof) | +|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci) | +|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci) | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci) | +|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi) | diff --git a/src/file.rs b/src/file.rs index 6bc7407d..a1eb67e1 100644 --- a/src/file.rs +++ b/src/file.rs @@ -6,7 +6,7 @@ use regex::Regex; use crate::http::{Resp, Data, Ques}; lazy_static!( - static ref RE: Regex = Regex::new(r"\|\s*([0-9]*)\s*\|\s*(\w*)\s*\|.*?bin/(.*?).rs.*?\|.*?\|").unwrap(); + static ref RE: Regex = Regex::new(r"\|\s*([0-9]*)\s*\|\s*(.*?)\s*\|.*?bin/(.*?).rs.*?\|.*?\|").unwrap(); ); /// 将结果写入README.md中 @@ -77,7 +77,7 @@ fn parse(contents: &str) -> Vec { translated_title: i.get(2).unwrap().as_str().to_string(), title_slug: String::new(), code_snippets: vec![], - difficulty: String::new() + difficulty: String::new(), } }, }) @@ -93,11 +93,14 @@ mod tests { #[test] fn test_parse_readme() { - let content = r"| 1111 | 两数之和| [src](https://github.com/rustors/leetcode/blob/main/src/bin/two_sum.rs) | [leetcode](https://leetcode-cn.com/problems/two_sum/) | - | 1112 | 两数之和| [src](https://github.com/rustors/leetcode/blob/main/src/bin/two_sum.rs) | [leetcode](https://leetcode-cn.com/problems/two_sum/) | - "; + let contents = std::fs::read_to_string("README.md").unwrap(); + let x = parse(&contents); + println!("{:?}", x); + println!("{}", x.len()); - println!("{:?}", parse(content)); + for i in x { + println!("{}", i.data.question.translated_title); + } } #[test] diff --git a/src/render.rs b/src/render.rs index ceb39fda..05832b50 100644 --- a/src/render.rs +++ b/src/render.rs @@ -10,7 +10,7 @@ const TEMPLATE_STR: &str = r"# leetcode | 编号 | 题目 | 描述 | 代码 | | ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | -{% for t in datas %}|{{ t.data.question.questionId }} | {{ t.data.question.translatedTitle }} | [src](https://github.com/rustors/leetcode/blob/main/src/bin/{{ t.data.question.titleSlug }}.rs) | [leetcode](https://leetcode-cn.com/problems/{{ t.data.question.titleSlug }}) | +{% for t in datas %}|{{ t.data.question.questionId }} | {{ t.data.question.translatedTitle }} | [src](https://github.com/rustors/leetcode/blob/main/src/bin/{{ t.data.question.titleSlug }}.rs) | [leetcode](https://leetcode-cn.com/problems/{{ t.data.question.titleSlug }}/) | {% endfor %}"; /// 模板名字 From 9d0cc5386672ec184b745945f31fb64120cd6297 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 22:47:30 +0800 Subject: [PATCH 0027/1556] README.md --- README.md | 451 ++++++++++++++++++++++++------------------------------ 1 file changed, 203 insertions(+), 248 deletions(-) diff --git a/README.md b/README.md index ee9218fa..a80e1463 100644 --- a/README.md +++ b/README.md @@ -1,255 +1,210 @@ # leetcode -当前已刷:247 +当前已刷:202 ### 题目 | 编号 | 题目 | 描述 | 代码 | | ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | -|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum) | -|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers) | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters) | -|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays) | -|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion) | -|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer) | -|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi) | -|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number) | -|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water) | -|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman) | -|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer) | -|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix) | -|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum) | -|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest) | -|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number) | -|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum) | -|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list) | -|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses) | -|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists) | -|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists) | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs) | -|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group) | -|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array) | -|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element) | -|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr) | -|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation) | -|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array) | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array) | -|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position) | -|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku) | -|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say) | -|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum) | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive) | -|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings) | -|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii) | -|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations) | -|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image) | -|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams) | -|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n) | -|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens) | -|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii) | -|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray) | -|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game) | -|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals) | -|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval) | -|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word) | -|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths) | -|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii) | -|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum) | -|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one) | -|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary) | -|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx) | -|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs) | -|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path) | -|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes) | -|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix) | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors) | -|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations) | -|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets) | -|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search) | -|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii) | -|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii) | -|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii) | -|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list) | -|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array) | -|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code) | -|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways) | -|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses) | -|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal) | -|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii) | -|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees) | -|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree) | -|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree) | -|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree) | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal) | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal) | -|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree) | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | -|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii) | -|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree) | -|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree) | -|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree) | -|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum) | -|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii) | -|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle) | -|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii) | -|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle) | -|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock) | -|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii) | -|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome) | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers) | -|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number) | -|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii) | -|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal) | -|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal) | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation) | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string) | -|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray) | -|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array) | -|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack) | -|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element) | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers) | -|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal) | -|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted) | -|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title) | -|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element) | -|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number) | -|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes) | -|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator) | -|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences) | -|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits) | -|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits) | -|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber) | -|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view) | -|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands) | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range) | -|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number) | -|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements) | -|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes) | -|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings) | -|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list) | -|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree) | -|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure) | -|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii) | -|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array) | -|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii) | -|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate) | -|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii) | -|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes) | -|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area) | -|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues) | -|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree) | -|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges) | -|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii) | -|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst) | -|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two) | -|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks) | -|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list) | -|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | -|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self) | -|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram) | -|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths) | -|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits) | -|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number) | -|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number) | -|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index) | -|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version) | -|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares) | -|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern) | -|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable) | -|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths) | -|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher) | -|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three) | -|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays) | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits) | -|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square) | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers) | -|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower) | -|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string) | -|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves) | -|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board) | -|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english) | -|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string) | -|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement) | -|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string) | -|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row) | -|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital) | -|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list) | -|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i) | -|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k) | -|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting) | -|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence) | -|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees) | -|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate) | -|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard) | -|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst) | -|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements) | -|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence) | -|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation) | -|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline) | -|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count) | -|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups) | -|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes) | -|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people) | -|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii) | -|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap) | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal) | -|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array) | -|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match) | -|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted) | -|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique) | -|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp) | -|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree) | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences) | -|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii) | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal) | -|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer) | -|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list) | -|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle) | -|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string) | -|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths) | -|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements) | -|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path) | -|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops) | -|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii) | -|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings) | -|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability) | -|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays) | -|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses) | -|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix) | -|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree) | -|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer) | -|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero) | -|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii) | -|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | -|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c) | -|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist) | -|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string) | -|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards) | -|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations) | -|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | -|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length) | -|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array) | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals) | -|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k) | -|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles) | -|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets) | -|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator) | -|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great) | -|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth) | -|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation) | -|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament) | -|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers) | -|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year) | -|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof) | -|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof) | -|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof) | -|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof) | -|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof) | -|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof) | -|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof) | -|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof) | -|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci) | -|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci) | -|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci) | -|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi) | +|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | From 2c7df1bc555917359d1d030d0da07f1fc24f8e2f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 22:47:56 +0800 Subject: [PATCH 0028/1556] fix regex expr error --- README.md | 451 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 248 insertions(+), 203 deletions(-) diff --git a/README.md b/README.md index a80e1463..ee9218fa 100644 --- a/README.md +++ b/README.md @@ -1,210 +1,255 @@ # leetcode -当前已刷:202 +当前已刷:247 ### 题目 | 编号 | 题目 | 描述 | 代码 | | ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | -|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum) | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers) | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters) | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays) | +|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion) | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer) | +|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi) | +|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number) | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water) | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman) | +|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer) | +|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix) | +|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum) | +|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest) | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number) | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum) | +|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list) | +|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses) | +|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists) | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists) | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs) | +|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group) | +|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array) | +|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element) | +|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr) | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation) | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array) | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array) | +|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position) | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku) | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say) | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum) | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive) | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings) | +|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii) | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations) | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image) | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams) | +|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n) | +|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens) | +|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii) | +|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray) | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game) | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals) | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval) | +|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word) | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths) | +|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii) | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum) | +|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one) | +|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary) | +|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx) | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs) | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path) | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes) | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix) | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors) | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations) | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets) | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search) | +|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii) | +|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii) | +|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii) | +|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list) | +|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array) | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code) | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways) | +|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses) | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal) | +|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii) | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees) | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree) | +|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree) | +|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree) | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal) | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal) | +|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree) | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | +|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii) | +|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree) | +|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree) | +|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree) | +|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum) | +|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii) | +|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle) | +|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii) | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle) | +|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock) | +|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii) | +|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome) | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers) | +|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number) | +|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii) | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal) | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal) | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation) | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string) | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray) | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array) | +|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack) | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element) | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers) | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal) | +|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted) | +|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title) | +|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element) | +|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number) | +|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes) | +|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator) | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences) | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits) | +|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits) | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber) | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view) | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands) | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range) | +|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number) | +|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements) | +|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes) | +|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings) | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list) | +|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree) | +|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure) | +|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii) | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array) | +|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii) | +|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate) | +|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii) | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes) | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area) | +|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues) | +|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree) | +|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges) | +|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii) | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst) | +|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two) | +|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks) | +|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list) | +|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self) | +|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram) | +|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths) | +|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits) | +|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number) | +|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number) | +|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index) | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version) | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares) | +|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern) | +|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable) | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths) | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher) | +|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three) | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays) | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits) | +|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square) | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers) | +|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower) | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string) | +|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves) | +|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board) | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english) | +|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string) | +|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement) | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string) | +|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row) | +|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital) | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list) | +|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i) | +|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k) | +|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting) | +|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence) | +|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees) | +|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate) | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard) | +|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst) | +|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements) | +|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence) | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation) | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline) | +|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count) | +|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups) | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes) | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people) | +|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii) | +|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap) | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal) | +|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array) | +|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match) | +|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted) | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique) | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp) | +|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree) | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences) | +|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii) | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal) | +|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer) | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list) | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle) | +|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string) | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths) | +|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements) | +|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path) | +|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops) | +|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii) | +|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings) | +|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability) | +|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays) | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses) | +|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix) | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree) | +|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer) | +|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero) | +|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii) | +|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c) | +|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist) | +|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string) | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards) | +|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations) | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length) | +|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array) | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals) | +|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k) | +|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles) | +|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets) | +|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator) | +|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great) | +|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth) | +|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation) | +|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament) | +|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers) | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year) | +|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof) | +|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof) | +|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof) | +|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof) | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof) | +|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof) | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof) | +|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof) | +|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci) | +|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci) | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci) | +|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi) | From 7d3618108cc06a8983db8cd6fe7c32a07561ef36 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 22:49:51 +0800 Subject: [PATCH 0029/1556] README.md --- README.md | 451 ++++++++++++++++++++++++------------------------------ 1 file changed, 203 insertions(+), 248 deletions(-) diff --git a/README.md b/README.md index ee9218fa..a80e1463 100644 --- a/README.md +++ b/README.md @@ -1,255 +1,210 @@ # leetcode -当前已刷:247 +当前已刷:202 ### 题目 | 编号 | 题目 | 描述 | 代码 | | ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | -|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum) | -|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers) | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters) | -|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays) | -|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion) | -|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer) | -|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi) | -|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number) | -|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water) | -|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman) | -|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer) | -|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix) | -|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum) | -|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest) | -|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number) | -|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum) | -|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list) | -|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses) | -|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists) | -|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists) | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs) | -|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group) | -|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array) | -|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element) | -|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr) | -|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation) | -|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array) | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array) | -|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position) | -|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku) | -|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say) | -|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum) | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive) | -|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings) | -|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii) | -|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations) | -|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image) | -|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams) | -|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n) | -|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens) | -|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii) | -|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray) | -|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game) | -|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals) | -|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval) | -|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word) | -|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths) | -|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii) | -|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum) | -|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one) | -|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary) | -|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx) | -|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs) | -|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path) | -|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes) | -|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix) | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors) | -|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations) | -|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets) | -|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search) | -|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii) | -|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii) | -|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii) | -|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list) | -|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array) | -|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code) | -|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways) | -|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses) | -|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal) | -|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii) | -|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees) | -|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree) | -|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree) | -|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree) | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal) | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal) | -|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree) | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal) | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal) | -|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii) | -|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree) | -|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree) | -|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree) | -|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum) | -|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii) | -|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle) | -|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii) | -|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle) | -|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock) | -|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii) | -|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome) | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers) | -|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number) | -|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii) | -|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal) | -|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal) | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation) | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string) | -|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray) | -|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array) | -|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack) | -|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element) | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers) | -|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal) | -|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted) | -|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title) | -|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element) | -|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number) | -|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes) | -|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator) | -|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences) | -|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits) | -|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits) | -|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber) | -|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view) | -|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands) | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range) | -|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number) | -|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements) | -|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes) | -|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings) | -|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list) | -|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree) | -|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure) | -|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii) | -|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array) | -|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii) | -|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate) | -|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii) | -|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes) | -|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area) | -|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues) | -|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree) | -|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges) | -|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii) | -|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst) | -|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two) | -|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks) | -|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list) | -|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree) | -|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self) | -|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram) | -|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths) | -|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits) | -|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number) | -|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number) | -|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index) | -|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version) | -|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares) | -|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern) | -|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable) | -|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths) | -|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher) | -|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three) | -|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays) | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits) | -|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square) | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers) | -|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower) | -|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string) | -|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves) | -|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board) | -|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english) | -|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string) | -|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement) | -|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string) | -|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row) | -|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital) | -|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list) | -|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i) | -|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k) | -|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting) | -|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence) | -|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees) | -|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate) | -|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard) | -|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst) | -|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements) | -|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence) | -|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation) | -|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline) | -|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count) | -|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups) | -|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes) | -|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people) | -|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii) | -|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap) | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal) | -|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array) | -|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match) | -|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted) | -|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique) | -|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp) | -|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree) | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences) | -|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii) | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal) | -|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer) | -|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list) | -|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle) | -|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string) | -|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths) | -|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements) | -|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path) | -|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops) | -|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii) | -|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings) | -|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability) | -|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays) | -|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses) | -|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix) | -|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree) | -|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer) | -|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero) | -|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii) | -|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping) | -|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c) | -|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist) | -|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string) | -|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards) | -|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations) | -|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | -|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length) | -|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array) | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals) | -|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k) | -|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles) | -|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets) | -|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator) | -|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great) | -|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth) | -|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation) | -|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament) | -|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers) | -|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year) | -|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof) | -|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof) | -|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof) | -|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof) | -|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof) | -|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof) | -|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof) | -|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof) | -|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci) | -|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci) | -|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci) | -|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi) | +|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | From a7a17fa45767a75887aae2aae8b911176200902b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 22:50:36 +0800 Subject: [PATCH 0030/1556] README.md --- README.md | 404 +++++++++++++++++++++++++++--------------------------- 1 file changed, 202 insertions(+), 202 deletions(-) diff --git a/README.md b/README.md index a80e1463..e20db80f 100644 --- a/README.md +++ b/README.md @@ -6,205 +6,205 @@ | 编号 | 题目 | 描述 | 代码 | | ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | -|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | -|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems/) | +|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | From 4278214ecc41934cf3cc52d8bbf8f2b461c4e3bf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 22:52:00 +0800 Subject: [PATCH 0031/1556] README.md --- README.md | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e20db80f..1cc941f1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # leetcode -当前已刷:202 +当前已刷:247 ### 题目 @@ -10,7 +10,9 @@ |2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | @@ -20,12 +22,15 @@ |16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | @@ -35,18 +40,24 @@ |39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | @@ -55,11 +66,16 @@ |77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | @@ -69,16 +85,21 @@ |104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | @@ -89,6 +110,7 @@ |162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | @@ -106,14 +128,21 @@ |204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | @@ -123,9 +152,11 @@ |258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | @@ -144,11 +175,15 @@ |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | @@ -156,6 +191,7 @@ |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | @@ -165,6 +201,7 @@ |1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | @@ -174,12 +211,16 @@ |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | @@ -190,12 +231,15 @@ |1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | @@ -204,6 +248,7 @@ |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | |100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | From 5558149412105bc2a3f3614597e5eb467b94fa4f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 22:53:54 +0800 Subject: [PATCH 0032/1556] add \n --- src/render.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render.rs b/src/render.rs index 05832b50..6345ff84 100644 --- a/src/render.rs +++ b/src/render.rs @@ -57,4 +57,4 @@ mod tests { println!("{:?}", render(&data).unwrap().to_string()); } -} \ No newline at end of file +} From e167941fd7f94177a4f8652018baffd64c905d60 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 23:35:25 +0800 Subject: [PATCH 0033/1556] fix parse readme.md bug --- README.md | 494 ++++++++++++++++++++++++++-------------------------- src/file.rs | 4 +- 2 files changed, 249 insertions(+), 249 deletions(-) diff --git a/README.md b/README.md index 1cc941f1..314ebf08 100644 --- a/README.md +++ b/README.md @@ -6,250 +6,250 @@ | 编号 | 题目 | 描述 | 代码 | | ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | -|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | -|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/.rs) | [leetcode](https://leetcode-cn.com/problems//) | +|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | +|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | +|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | +|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number/) | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) | +|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer/) | +|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix/) | +|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum/) | +|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest/) | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | +|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | +|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | +|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | +|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | +|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | +|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | +|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | +|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | +|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | +|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | +|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | +|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | +|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | +|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word/) | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths/) | +|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) | +|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | +|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary/) | +|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | +|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) | +|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | +|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | +|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | +|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | +|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) | +|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | +|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree/) | +|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | +|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | +|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | +|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) | +|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree/) | +|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) | +|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum/) | +|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) | +|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle/) | +|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii/) | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | +|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/) | +|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | +|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | +|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | +|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | +|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | +|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | +|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | +|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element/) | +|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) | +|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | +|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | +|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | +|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number/) | +|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) | +|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | +|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | +|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | +|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | +|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) | +|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) | +|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate/) | +|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii/) | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area/) | +|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues/) | +|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree/) | +|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges/) | +|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) | +|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two/) | +|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks/) | +|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) | +|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | +|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | +|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | +|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits/) | +|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | +|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | +|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | +|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | +|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | +|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | +|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | +|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | +|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | +|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | +|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | +|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | +|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | +|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | +|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | +|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | +|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | +|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | +|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | +|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | +|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | +|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | +|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | +|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | +|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | +|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | +|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | +|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | +|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | +|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | +|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | +|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | +|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | +|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | +|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | +|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | +|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | +|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | +|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | +|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | +|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | +|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | +|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | +|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | +|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | +|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | +|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | +|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | +|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | +|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | +|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | +|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | +|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | +|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | +|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | +|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | +|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | +|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | +|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | +|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | +|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | +|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | +|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | +|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | +|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | +|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | +|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | +|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | diff --git a/src/file.rs b/src/file.rs index a1eb67e1..fb9b9908 100644 --- a/src/file.rs +++ b/src/file.rs @@ -75,7 +75,7 @@ fn parse(contents: &str) -> Vec { question: Ques { question_id: i.get(1).unwrap().as_str().to_string(), translated_title: i.get(2).unwrap().as_str().to_string(), - title_slug: String::new(), + title_slug: i.get(3).unwrap().as_str().to_string(), code_snippets: vec![], difficulty: String::new(), } @@ -99,7 +99,7 @@ mod tests { println!("{}", x.len()); for i in x { - println!("{}", i.data.question.translated_title); + println!("{}, {}, {}", i.data.question.translated_title, i.data.question.question_id, i.data.question.title_slug); } } From c8ae67c0ae1050a3cf44e6538a37cde8bb9b5175 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 23:35:41 +0800 Subject: [PATCH 0034/1556] README.md --- README.md | 80 +++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 314ebf08..74e43c56 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ | 编号 | 题目 | 描述 | 代码 | | ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | |1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | -|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numb.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numb/) | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-charact.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-charact/) | |4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | -|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | -|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | +|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conv.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conv/) | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rev.rs) | [leetcode](https://leetcode-cn.com/problems/rev/) | |8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | |9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number/) | |11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | @@ -26,19 +26,19 @@ |20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | |21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | |23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | -|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pa.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pa/) | +|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rev.rs) | [leetcode](https://leetcode-cn.com/problems/rev/) | |26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | |27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | -|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | +|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-s.rs) | [leetcode](https://leetcode-cn.com/problems/implement-s/) | |31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | |33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-f.rs) | [leetcode](https://leetcode-cn.com/problems/find-f/) | |35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | |36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | |38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | |39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/f.rs) | [leetcode](https://leetcode-cn.com/problems/f/) | |43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | |45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | |46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | @@ -58,11 +58,11 @@ |66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | |67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary/) | |69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | -|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-sta.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-sta/) | |71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | |73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | |74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-col.rs) | [leetcode](https://leetcode-cn.com/problems/sort-col/) | |77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | |78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | |79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | @@ -74,18 +74,18 @@ |89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | |91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | |93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | -|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-trav/) | |95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | |96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | |98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | |100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree/) | |101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-trav.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-trav/) | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-trav.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-trav/) | |104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | -|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-trav/) | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-trav/) | +|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-trav.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-trav/) | |108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) | |110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree/) | |111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) | @@ -97,18 +97,18 @@ |121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/) | |122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | |125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numb.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numb/) | |136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | |137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | -|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | -|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-trav/) | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-trav/) | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-rev.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-rev/) | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rev.rs) | [leetcode](https://leetcode-cn.com/problems/rev/) | |152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | |153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | |155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | |162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-v.rs) | [leetcode](https://leetcode-cn.com/problems/compare-v/) | |166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | |167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | |168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | @@ -117,17 +117,17 @@ |172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | |173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | |187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | -|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rev.rs) | [leetcode](https://leetcode-cn.com/problems/rev/) | |191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | |198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | |199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | |200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numb.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numb/) | |202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number/) | |203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) | |204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | |205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | -|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rev.rs) | [leetcode](https://leetcode-cn.com/problems/rev/) | |208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | |211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | |213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | @@ -153,19 +153,19 @@ |263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | |268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | |274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | -|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/f.rs) | [leetcode](https://leetcode-cn.com/problems/f/) | |279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | |290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | |303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | |318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | |319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | |326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | -|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/int.rs) | [leetcode](https://leetcode-cn.com/problems/int/) | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numb.rs) | [leetcode](https://leetcode-cn.com/problems/count-numb/) | |367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integ.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integ/) | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | -|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/f.rs) | [leetcode](https://leetcode-cn.com/problems/f/) | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | @@ -193,16 +193,16 @@ |917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | |921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | |924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-trav/) | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | |981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | |982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | |1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | |1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numb.rs) | [leetcode](https://leetcode-cn.com/problems/numb/) | |1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-trav/) | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | |1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | |1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | @@ -219,7 +219,7 @@ |1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | |1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | -|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | +|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integ.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integ/) | |1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | |1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | |1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | @@ -227,19 +227,19 @@ |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | |1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | |1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | -|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occ.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occ/) | |1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | -|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integ.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integ/) | +|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pa.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pa/) | |1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | |1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | |1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | |1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | -|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | +|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-p.rs) | [leetcode](https://leetcode-cn.com/problems/goal-p/) | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | -|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | +|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numb.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numb/) | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | From b771b0eac7c3bc8009b3a4c6df9fdb48df8c9ea3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 23:42:59 +0800 Subject: [PATCH 0035/1556] README.md --- README.md | 80 +++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 74e43c56..314ebf08 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ | 编号 | 题目 | 描述 | 代码 | | ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | |1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | -|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numb.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numb/) | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-charact.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-charact/) | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | |4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | -|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conv.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conv/) | -|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rev.rs) | [leetcode](https://leetcode-cn.com/problems/rev/) | +|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | |8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | |9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number/) | |11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | @@ -26,19 +26,19 @@ |20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | |21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | |23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pa.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pa/) | -|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rev.rs) | [leetcode](https://leetcode-cn.com/problems/rev/) | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | +|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | |26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | |27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | -|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-s.rs) | [leetcode](https://leetcode-cn.com/problems/implement-s/) | +|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | |31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | |33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-f.rs) | [leetcode](https://leetcode-cn.com/problems/find-f/) | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | |35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | |36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | |38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | |39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/f.rs) | [leetcode](https://leetcode-cn.com/problems/f/) | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | |43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | |45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | |46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | @@ -58,11 +58,11 @@ |66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | |67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary/) | |69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | -|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-sta.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-sta/) | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | |71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | |73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | |74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-col.rs) | [leetcode](https://leetcode-cn.com/problems/sort-col/) | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | |77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | |78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | |79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | @@ -74,18 +74,18 @@ |89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | |91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | |93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | -|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-trav/) | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) | |95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | |96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | |98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | |100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree/) | |101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-trav.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-trav/) | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-trav.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-trav/) | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | |104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-trav/) | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-trav/) | -|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-trav.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-trav/) | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | +|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | |108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) | |110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree/) | |111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) | @@ -97,18 +97,18 @@ |121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/) | |122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | |125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numb.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numb/) | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | |136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | |137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | -|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-trav/) | -|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-trav/) | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-rev.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-rev/) | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rev.rs) | [leetcode](https://leetcode-cn.com/problems/rev/) | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | |152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | |153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | |155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | |162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-v.rs) | [leetcode](https://leetcode-cn.com/problems/compare-v/) | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | |166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | |167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | |168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | @@ -117,17 +117,17 @@ |172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | |173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | |187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | -|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rev.rs) | [leetcode](https://leetcode-cn.com/problems/rev/) | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | |191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | |198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | |199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | |200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numb.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numb/) | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | |202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number/) | |203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) | |204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | |205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | -|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rev.rs) | [leetcode](https://leetcode-cn.com/problems/rev/) | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | |208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | |211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | |213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | @@ -153,19 +153,19 @@ |263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | |268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | |274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | -|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/f.rs) | [leetcode](https://leetcode-cn.com/problems/f/) | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | |279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | |290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | |303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | |318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | |319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | |326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | -|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/int.rs) | [leetcode](https://leetcode-cn.com/problems/int/) | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numb.rs) | [leetcode](https://leetcode-cn.com/problems/count-numb/) | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | |367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integ.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integ/) | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | -|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/f.rs) | [leetcode](https://leetcode-cn.com/problems/f/) | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | @@ -193,16 +193,16 @@ |917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | |921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | |924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-trav/) | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | |981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | |982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | |1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | |1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numb.rs) | [leetcode](https://leetcode-cn.com/problems/numb/) | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | |1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-trav.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-trav/) | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | |1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | |1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | @@ -219,7 +219,7 @@ |1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | |1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | -|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integ.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integ/) | +|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | |1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | |1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | |1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | @@ -227,19 +227,19 @@ |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | |1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | |1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | -|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occ.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occ/) | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | |1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integ.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integ/) | -|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pa.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pa/) | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | +|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | |1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | |1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | |1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | |1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | -|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-p.rs) | [leetcode](https://leetcode-cn.com/problems/goal-p/) | +|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | -|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numb.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numb/) | +|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | From d1ed822a40999ddf781db6fe76d4f89694e12082 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jul 2021 23:43:30 +0800 Subject: [PATCH 0036/1556] fix parse readme.md bug --- src/file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file.rs b/src/file.rs index fb9b9908..2e9ef324 100644 --- a/src/file.rs +++ b/src/file.rs @@ -6,7 +6,7 @@ use regex::Regex; use crate::http::{Resp, Data, Ques}; lazy_static!( - static ref RE: Regex = Regex::new(r"\|\s*([0-9]*)\s*\|\s*(.*?)\s*\|.*?bin/(.*?).rs.*?\|.*?\|").unwrap(); + static ref RE: Regex = Regex::new(r"\|\s*([0-9]*)\s*\|\s*(.*?)\s*\|.*?bin/(.*?)\.rs.*?\|.*?\|").unwrap(); ); /// 将结果写入README.md中 From 4a8a4c1f069948fe0fcc01e906f2783756b16315 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 26 Jul 2021 20:52:31 +0800 Subject: [PATCH 0037/1556] src/bin/intersection-of-two-arrays-ii.rs --- src/bin/intersection-of-two-arrays-ii.rs | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/intersection-of-two-arrays-ii.rs diff --git a/src/bin/intersection-of-two-arrays-ii.rs b/src/bin/intersection-of-two-arrays-ii.rs new file mode 100644 index 00000000..6074515f --- /dev/null +++ b/src/bin/intersection-of-two-arrays-ii.rs @@ -0,0 +1,27 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn intersect(nums1: Vec, nums2: Vec) -> Vec { + let mut v = vec![]; + let (mut nums1, mut nums2) = (nums1, nums2); + nums1.sort(); + nums2.sort(); + let (mut i, mut j) = (0, 0); + + while i < nums1.len() && j < nums2.len() { + if nums1[i] == nums2[j] { + v.push(nums2[j]); + i += 1; + j += 1; + } else if nums1[i] < nums2[j] { + i += 1; + } else { + j += 1; + } + } + + v + } +} From b8ea2d58ec075c628946ebb22bad0ccc42ccff59 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 26 Jul 2021 20:52:32 +0800 Subject: [PATCH 0038/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 314ebf08..51f5f25c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # leetcode -当前已刷:247 +当前已刷:248 ### 题目 @@ -161,6 +161,7 @@ |319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | |326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | |349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | +|350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | |357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | |367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | |371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | From 0174ec5d989bf9f1acd37d35d75a9637738aab92 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 26 Jul 2021 22:58:06 +0800 Subject: [PATCH 0039/1556] feature: add difficulty --- README.md | 504 +++++++++++++++++++++++++------------------------- src/file.rs | 4 +- src/http.rs | 58 +++++- src/render.rs | 26 ++- 4 files changed, 331 insertions(+), 261 deletions(-) diff --git a/README.md b/README.md index 51f5f25c..5167fd36 100644 --- a/README.md +++ b/README.md @@ -1,256 +1,258 @@ # leetcode -当前已刷:248 +| Total | Easy | Medium | Hard | +| :----: | :----: | :----: | :----: | +| 248 | 117 | 125 | 6 | ### 题目 -| 编号 | 题目 | 描述 | 代码 | -| ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | -|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | -|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | -|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | -|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | -|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | -|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | -|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number/) | -|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | -|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) | -|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer/) | -|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix/) | -|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum/) | -|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest/) | -|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | -|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | -|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | -|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | -|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | -|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | -|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | -|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | -|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | -|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | -|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | -|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | -|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | -|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | -|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | -|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | -|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | -|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | -|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | -|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | -|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | -|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | -|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | -|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | -|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) | -|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | -|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | -|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | -|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word/) | -|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths/) | -|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) | -|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) | -|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | -|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary/) | -|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | -|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | -|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | -|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | -|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | -|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | -|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | -|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | -|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) | -|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | -|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | -|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | -|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | -|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | -|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | -|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | -|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) | -|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | -|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | -|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | -|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree/) | -|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | -|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | -|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | -|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) | -|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree/) | -|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) | -|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum/) | -|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) | -|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle/) | -|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii/) | -|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | -|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/) | -|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | -|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | -|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | -|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | -|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | -|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | -|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | -|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | -|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | -|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | -|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | -|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | -|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | -|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element/) | -|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) | -|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | -|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | -|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | -|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | -|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | -|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | -|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | -|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | -|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number/) | -|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) | -|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | -|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | -|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | -|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | -|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | -|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | -|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) | -|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) | -|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate/) | -|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii/) | -|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) | -|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area/) | -|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues/) | -|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree/) | -|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges/) | -|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) | -|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) | -|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two/) | -|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks/) | -|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) | -|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | -|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | -|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | -|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | -|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits/) | -|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | -|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | -|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | -|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | -|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | -|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | -|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | -|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | -|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | -|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | -|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | -|350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | -|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | -|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | -|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | -|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | -|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | -|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | -|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | -|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | -|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | -|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | -|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | -|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | -|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | -|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | -|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | -|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | -|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | -|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | -|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | -|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | -|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | -|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | -|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | -|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | -|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | -|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | -|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | -|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | -|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | -|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | -|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | -|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | -|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | -|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | -|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | -|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | -|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | -|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | -|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | -|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | -|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | -|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | -|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | -|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | -|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | -|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | -|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | -|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | -|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | -|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | -|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | -|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | -|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | -|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | -|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | -|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | -|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | -|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | -|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | -|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | -|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | -|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | -|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | -|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | -|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | -|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | -|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | -|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | -|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | -|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | -|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | -|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | -|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | -|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | -|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | -|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | -|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | -|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | -|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | -|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | -|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | -|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | -|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | -|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | -|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | -|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | +| 编号 | 题目 | 描述 | 代码 | 难度 | +| ---- | ---- | ---- | ---- | ---- | +|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | Easy | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | Medium | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | Medium | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Hard | +|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | Medium | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | Easy | +|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | Medium | +|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number/) | Easy | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | Medium | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) | Medium | +|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer/) | Easy | +|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix/) | Easy | +|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum/) | Medium | +|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest/) | Medium | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | Medium | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | Medium | +|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Medium | +|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | Easy | +|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | Easy | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Hard | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | Medium | +|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Hard | +|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | Easy | +|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | Easy | +|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | Easy | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Medium | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Medium | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Medium | +|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | Easy | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Medium | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Medium | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Hard | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Medium | +|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Medium | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Medium | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | Medium | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | Medium | +|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | Medium | +|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Hard | +|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Hard | +|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) | Easy | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | Medium | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | Medium | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | Medium | +|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word/) | Easy | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths/) | Medium | +|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) | Medium | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) | Medium | +|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | Easy | +|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary/) | Easy | +|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | Easy | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | Easy | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | Medium | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | Medium | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | Medium | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | Medium | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | Medium | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | Medium | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | Medium | +|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) | Medium | +|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | Medium | +|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | Medium | +|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | Easy | +|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | Easy | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Medium | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Medium | +|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | Medium | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) | Easy | +|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | Medium | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | Medium | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | Medium | +|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree/) | Easy | +|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) | Easy | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | Medium | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | Medium | +|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | Easy | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | Medium | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | Medium | +|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | Medium | +|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) | Easy | +|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree/) | Easy | +|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) | Easy | +|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum/) | Easy | +|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) | Medium | +|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle/) | Easy | +|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii/) | Easy | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | Medium | +|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/) | Easy | +|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | Easy | +|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | Easy | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Medium | +|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | Easy | +|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Medium | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | Easy | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | Easy | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Medium | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | Medium | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Medium | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | Medium | +|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | Easy | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | Medium | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | Medium | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | Medium | +|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | Easy | +|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | Easy | +|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element/) | Easy | +|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) | Easy | +|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | Easy | +|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | Medium | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | Medium | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | Easy | +|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | Easy | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | Medium | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | Medium | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | Medium | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | Medium | +|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number/) | Easy | +|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) | Easy | +|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | Easy | +|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | Easy | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | Easy | +|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | Medium | +|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | Medium | +|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | Medium | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) | Medium | +|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) | Medium | +|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate/) | Easy | +|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii/) | Easy | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) | Medium | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area/) | Medium | +|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues/) | Easy | +|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree/) | Easy | +|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges/) | Easy | +|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) | Medium | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) | Medium | +|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two/) | Easy | +|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks/) | Easy | +|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) | Easy | +|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | Easy | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Medium | +|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | Easy | +|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | Easy | +|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits/) | Easy | +|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | Easy | +|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | Easy | +|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Medium | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | +|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | +|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | +|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | +|350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | +|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | +|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | +|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | +|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | +|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | +|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | +|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | +|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | +|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | +|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | +|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | +|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | +|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | +|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | +|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | +|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | +|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | +|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Easy | +|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | +|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | +|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | +|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | +|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | +|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Medium | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | Medium | +|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | Easy | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | +|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | +|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | +|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | +|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | +|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | +|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | +|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | +|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | +|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | +|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | +|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | +|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | +|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | +|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Medium | +|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | Easy | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | +|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | +|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | +|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Medium | +|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | +|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | +|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | Easy | +|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | Easy | +|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | +|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | +|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | +|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | +|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | +|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | +|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | +|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | +|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | +|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | +|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | +|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | +|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | +|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | +|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | diff --git a/src/file.rs b/src/file.rs index 2e9ef324..10070d6f 100644 --- a/src/file.rs +++ b/src/file.rs @@ -3,7 +3,7 @@ use std::io::Write; use lazy_static::lazy_static; use regex::Regex; -use crate::http::{Resp, Data, Ques}; +use crate::http::{Resp, Data, Ques, Difficulty}; lazy_static!( static ref RE: Regex = Regex::new(r"\|\s*([0-9]*)\s*\|\s*(.*?)\s*\|.*?bin/(.*?)\.rs.*?\|.*?\|").unwrap(); @@ -77,7 +77,7 @@ fn parse(contents: &str) -> Vec { translated_title: i.get(2).unwrap().as_str().to_string(), title_slug: i.get(3).unwrap().as_str().to_string(), code_snippets: vec![], - difficulty: String::new(), + difficulty: Difficulty::Easy, } }, }) diff --git a/src/http.rs b/src/http.rs index b8a45026..c1ac650a 100644 --- a/src/http.rs +++ b/src/http.rs @@ -1,7 +1,10 @@ use lazy_static::lazy_static; use regex::Regex; use reqwest::blocking::Client; -use serde::{Serialize, Deserialize}; +use serde::{Serialize, Deserialize, Serializer, Deserializer}; +use serde::de::{Error, Visitor}; + +use std::fmt; lazy_static! { @@ -10,6 +13,57 @@ lazy_static! { const URL: &str = "https://leetcode-cn.com/graphql/"; +#[derive(Debug, Eq, PartialEq)] +pub enum Difficulty { + Easy, + Medium, + Hard, +} + +impl Serialize for Difficulty { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer + { + match self { + Self::Easy => serializer.serialize_str("Easy"), + Self::Medium => serializer.serialize_str("Medium"), + Self::Hard => serializer.serialize_str("Hard"), + } + } +} + +struct DifficultyVisitor; + +impl<'de> Visitor<'de> for DifficultyVisitor { + type Value = Difficulty; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + write!(formatter, "") + } + + fn visit_str(self, v: &str) -> Result + where + E: Error, + { + match v { + "Easy" => Ok(Self::Value::Easy), + "Medium" => Ok(Self::Value::Medium), + "Hard" => Ok(Self::Value::Hard), + _ => Err(Error::unknown_variant(v, &["Easy", "Medium", "Hard"])), + } + } +} + +impl<'de> Deserialize<'de> for Difficulty { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de> + { + deserializer.deserialize_str(DifficultyVisitor) + } +} + #[derive(Deserialize, Serialize, Debug)] pub struct Ques { #[serde(rename = "questionId")] @@ -21,7 +75,7 @@ pub struct Ques { #[serde(rename = "codeSnippets")] pub code_snippets: Vec, #[serde(rename = "difficulty")] - pub difficulty: String, + pub difficulty: Difficulty, } #[derive(Deserialize, Serialize, Debug)] diff --git a/src/render.rs b/src/render.rs index 6345ff84..353717a9 100644 --- a/src/render.rs +++ b/src/render.rs @@ -4,13 +4,15 @@ use tera::{Tera, Context, Result as TeraResult}; /// 模板内容 const TEMPLATE_STR: &str = r"# leetcode -当前已刷:{{ datas | length }} +| Total | Easy | Medium | Hard | +| :----: | :----: | :----: | :----: | +| {{ datas | length }} | {{ easy_num }} | {{ medium_num }} | {{ hard_num }} | ### 题目 -| 编号 | 题目 | 描述 | 代码 | -| ---- | ----- | ------------------------------------------------------------ | ----------------------------------------------------- | -{% for t in datas %}|{{ t.data.question.questionId }} | {{ t.data.question.translatedTitle }} | [src](https://github.com/rustors/leetcode/blob/main/src/bin/{{ t.data.question.titleSlug }}.rs) | [leetcode](https://leetcode-cn.com/problems/{{ t.data.question.titleSlug }}/) | +| 编号 | 题目 | 描述 | 代码 | 难度 | +| ---- | ---- | ---- | ---- | ---- | +{% for t in datas %}|{{ t.data.question.questionId }} | {{ t.data.question.translatedTitle }} | [src](https://github.com/rustors/leetcode/blob/main/src/bin/{{ t.data.question.titleSlug }}.rs) | [leetcode](https://leetcode-cn.com/problems/{{ t.data.question.titleSlug }}/) | {{ t.data.question.difficulty }} | {% endfor %}"; /// 模板名字 @@ -29,14 +31,26 @@ lazy_static!( /// 把传入的内容渲染为模板内容 pub fn render(data: &[crate::http::Resp]) -> TeraResult { let mut ctx = Context::new(); + + let easy_num = counter(data, |x| x.data.question.difficulty == crate::http::Difficulty::Easy); + let medium_num = counter(data, |x| x.data.question.difficulty == crate::http::Difficulty::Medium); + let hard_num = counter(data, |x| x.data.question.difficulty == crate::http::Difficulty::Hard); + ctx.insert("datas", data); + ctx.insert("easy_num", &easy_num); + ctx.insert("medium_num", &medium_num); + ctx.insert("hard_num", &hard_num); TEMPLATE.render(TEMPLATE_NAME, &ctx) } +fn counter(data: &[crate::http::Resp], f: impl FnMut(&&crate::http::Resp) -> bool) -> usize { + data.into_iter().filter(f).count() +} + #[cfg(test)] mod tests { - use crate::http::{Resp, Ques, Data}; + use crate::http::{Resp, Ques, Data, Difficulty}; use crate::render::render; #[test] @@ -49,7 +63,7 @@ mod tests { title_slug: "aaa".to_string(), translated_title: "中国".to_string(), code_snippets: vec![], - difficulty: String::new(), + difficulty: Difficulty::Easy, } }, }, From 5f70a58c76da1c5db5647890ec91742d8e80a9b3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 26 Jul 2021 23:20:01 +0800 Subject: [PATCH 0040/1556] fmt file --- src/http.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/http.rs b/src/http.rs index c1ac650a..33f51a58 100644 --- a/src/http.rs +++ b/src/http.rs @@ -107,6 +107,7 @@ pub fn get_question_info(mut ques: &str) -> Resp { let data_fmt = r#"{"operationName":"questionData","variables":{"titleSlug":"{}"}, "query":"query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n boundTopicId\n title\n titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n contributors {\n username\n profileUrl\n avatarUrl\n __typename\n }\n langToValidPlayground\n topicTags {\n name\n slug\n translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n lang\n langSlug\n code\n __typename\n }\n stats\n hints\n solution {\n id\n canSeeDetail\n __typename\n }\n status\n sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n enableRunCode\n envInfo\n book {\n id\n bookName\n pressName\n source\n shortDescription\n fullDescription\n bookImgUrl\n pressImgUrl\n productUrl\n __typename\n }\n isSubscribed\n isDailyQuestion\n dailyRecordStatus\n editorType\n ugcQuestionId\n style\n __typename\n }\n}\n"}"#; + let data = data_fmt.replace("{}", ques); Client::new() From 8d528a1c43b76d2a69d7ddf12573b9b6dc7dc254 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 27 Jul 2021 21:13:30 +0800 Subject: [PATCH 0041/1556] src/bin/longest-increasing-subsequence.rs --- src/bin/longest-increasing-subsequence.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/longest-increasing-subsequence.rs diff --git a/src/bin/longest-increasing-subsequence.rs b/src/bin/longest-increasing-subsequence.rs new file mode 100644 index 00000000..d3564bc4 --- /dev/null +++ b/src/bin/longest-increasing-subsequence.rs @@ -0,0 +1,23 @@ +fn main() { + println!("{}", Solution::length_of_lis(vec![10, 9, 2, 5, 3, 7, 101, 18])); + println!("{}", Solution::length_of_lis(vec![0, 1, 0, 3, 2, 3])); + println!("{}", Solution::length_of_lis(vec![7, 7, 7, 7, 7, 7, 7])); +} + +struct Solution; + +impl Solution { + pub fn length_of_lis(nums: Vec) -> i32 { + let mut v = vec![1; nums.len()]; + + for i in 1..nums.len() { + for j in 0..i { + if nums[j] < nums[i] { + v[i] = v[i].max(v[j] + 1); + } + } + } + + v.into_iter().fold(0, |x, y| x.max(y)) + } +} From e7e551c5503235b22abf41fd54bca653dab2c851 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 27 Jul 2021 21:13:31 +0800 Subject: [PATCH 0042/1556] README.md --- README.md | 265 +++++++++++++++++++++++++++--------------------------- 1 file changed, 133 insertions(+), 132 deletions(-) diff --git a/README.md b/README.md index 5167fd36..0e1756c4 100644 --- a/README.md +++ b/README.md @@ -2,239 +2,240 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 248 | 117 | 125 | 6 | +| 249 | 248 | 1 | 0 | ### 题目 | 编号 | 题目 | 描述 | 代码 | 难度 | | ---- | ---- | ---- | ---- | ---- | |1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | Easy | -|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | Medium | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | Medium | -|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Hard | -|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | Medium | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | Easy | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | Easy | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Easy | +|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | Easy | |7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | Easy | -|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | Medium | +|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | Easy | |9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number/) | Easy | -|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | Medium | -|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) | Medium | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | Easy | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) | Easy | |13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer/) | Easy | |14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix/) | Easy | -|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum/) | Medium | -|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest/) | Medium | -|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | Medium | -|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | Medium | -|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Medium | +|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum/) | Easy | +|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest/) | Easy | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | Easy | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | Easy | +|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Easy | |20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | Easy | |21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | Easy | -|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Hard | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | Medium | -|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Hard | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Easy | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | Easy | +|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Easy | |26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | Easy | |27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | Easy | |28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | Easy | -|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Medium | -|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Medium | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Medium | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Easy | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Easy | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Easy | |35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | Easy | -|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Medium | -|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Medium | -|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Hard | -|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Medium | -|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Medium | -|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Medium | -|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | Medium | -|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | Medium | -|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | Medium | -|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Hard | -|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Hard | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Easy | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Easy | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Easy | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Easy | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Easy | +|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Easy | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Easy | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | Easy | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | Easy | +|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | Easy | +|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Easy | +|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Easy | |53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) | Easy | -|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | Medium | -|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | Medium | -|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | Medium | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | Easy | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | Easy | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | Easy | |58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word/) | Easy | -|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths/) | Medium | -|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) | Medium | -|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) | Medium | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths/) | Easy | +|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) | Easy | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) | Easy | |66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | Easy | |67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary/) | Easy | |69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | Easy | |70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | Easy | -|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | Medium | -|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | Medium | -|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | Medium | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | Medium | -|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | Medium | -|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | Medium | -|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | Medium | -|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) | Medium | -|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | Medium | -|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | Medium | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | Easy | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | Easy | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | Easy | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | Easy | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | Easy | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | Easy | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | Easy | +|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) | Easy | +|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | Easy | +|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | Easy | |83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | Easy | |88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | Easy | -|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Medium | -|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Medium | -|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | Medium | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Easy | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Easy | +|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | Easy | |94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) | Easy | -|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | Medium | -|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | Medium | -|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | Medium | +|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | Easy | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | Easy | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | Easy | |100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree/) | Easy | |101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) | Easy | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | Medium | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | Medium | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | Easy | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | Easy | |104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | Easy | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | Medium | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | Medium | -|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | Medium | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | Easy | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | Easy | +|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | Easy | |108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) | Easy | |110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree/) | Easy | |111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) | Easy | |112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum/) | Easy | -|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) | Medium | +|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) | Easy | |118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle/) | Easy | |119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii/) | Easy | -|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | Medium | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | Easy | |121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/) | Easy | |122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | Easy | |125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | Easy | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Medium | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Easy | |136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | Easy | -|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Medium | +|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Easy | |144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | Easy | |145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | Easy | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Medium | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | Medium | -|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Medium | -|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | Medium | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Easy | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | Easy | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Easy | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | Easy | |155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | Easy | -|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | Medium | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | Medium | -|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | Medium | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | Easy | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | Easy | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | Easy | |167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | Easy | |168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | Easy | |169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element/) | Easy | |171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) | Easy | |172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | Easy | -|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | Medium | -|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | Medium | +|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | Easy | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | Easy | |190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | Easy | |191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | Easy | -|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | Medium | -|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | Medium | -|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | Medium | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | Medium | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | Easy | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | Easy | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | Easy | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | Easy | |202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number/) | Easy | |203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) | Easy | |204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | Easy | |205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | Easy | |206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | Easy | -|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | Medium | -|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | Medium | -|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | Medium | -|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) | Medium | -|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) | Medium | +|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | Easy | +|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | Easy | +|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | Easy | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) | Easy | +|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) | Easy | |217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate/) | Easy | |219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii/) | Easy | -|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) | Medium | -|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area/) | Medium | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) | Easy | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area/) | Easy | |225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues/) | Easy | |226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree/) | Easy | |228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges/) | Easy | -|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) | Medium | -|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) | Medium | +|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) | Easy | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) | Easy | |231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two/) | Easy | |232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks/) | Easy | |234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) | Easy | |235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | Easy | -|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Medium | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Easy | |242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | Easy | |257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | Easy | |258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits/) | Easy | |263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | Easy | |268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | Easy | -|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Medium | +|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Easy | |278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | -|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Easy | |290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | +|300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | |303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | -|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | -|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Easy | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Easy | |326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | |349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | |350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Easy | |367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Easy | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | -|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | -|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | +|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Easy | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Easy | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | |476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | -|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Easy | |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | -|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Easy | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | -|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | -|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | +|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Easy | +|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Easy | |594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | -|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | -|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | +|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Easy | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Easy | |653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | -|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | +|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Easy | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | -|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | -|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Easy | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Easy | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Easy | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | -|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | -|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | -|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Easy | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Easy | +|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Easy | |924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Easy | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | |981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | -|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Medium | -|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | Medium | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Easy | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | Easy | |1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | Easy | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | -|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Easy | +|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Easy | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Easy | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | -|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | -|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Easy | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Easy | |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | -|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Easy | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | -|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | +|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Easy | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | -|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | +|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Easy | |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | -|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | -|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | -|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | -|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | -|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | +|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Easy | +|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Easy | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Easy | +|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Easy | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Easy | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | |1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | -|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Medium | +|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Easy | |1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | Easy | -|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Easy | |1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | -|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Easy | |1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | |1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | -|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Medium | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Easy | |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | -|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Easy | +|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Easy | |1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | Easy | |1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | Easy | |1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | @@ -242,17 +243,17 @@ |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | -|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | +|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Easy | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | -|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Easy | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | -|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | -|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Easy | +|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Easy | |100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | |100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | -|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | From ccef238490c4d3030d5460b5e450919f45d3f598 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 27 Jul 2021 21:26:36 +0800 Subject: [PATCH 0043/1556] src/bin/2-keys-keyboard.rs --- src/bin/2-keys-keyboard.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/bin/2-keys-keyboard.rs b/src/bin/2-keys-keyboard.rs index 1c8a7c8f..ca43d14e 100644 --- a/src/bin/2-keys-keyboard.rs +++ b/src/bin/2-keys-keyboard.rs @@ -10,9 +10,7 @@ struct Solution; impl Solution { pub fn min_steps(mut n: i32) -> i32 { - if n == 1 { - return 0; - } + if n == 1 { return 0; } // 检查是否是质数 let mut count = 0; From 2e134a63ab3f8cc72beb05da301c57aa8afa016b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 27 Jul 2021 21:26:36 +0800 Subject: [PATCH 0044/1556] README.md --- README.md | 265 +++++++++++++++++++++++++++--------------------------- 1 file changed, 133 insertions(+), 132 deletions(-) diff --git a/README.md b/README.md index 0e1756c4..e63af034 100644 --- a/README.md +++ b/README.md @@ -2,240 +2,241 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 249 | 248 | 1 | 0 | +| 250 | 117 | 133 | 0 | ### 题目 | 编号 | 题目 | 描述 | 代码 | 难度 | | ---- | ---- | ---- | ---- | ---- | |1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | Easy | -|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | Easy | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | Easy | -|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Easy | -|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | Easy | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | Medium | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | Medium | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Medium | +|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | Medium | |7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | Easy | -|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | Easy | +|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | Medium | |9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number/) | Easy | -|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | Easy | -|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) | Easy | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | Medium | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) | Medium | |13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer/) | Easy | |14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix/) | Easy | -|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum/) | Easy | -|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest/) | Easy | -|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | Easy | -|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | Easy | -|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Easy | +|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum/) | Medium | +|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest/) | Medium | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | Medium | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | Medium | +|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Medium | |20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | Easy | |21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | Easy | -|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Easy | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | Easy | -|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Easy | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Medium | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | Medium | +|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Medium | |26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | Easy | |27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | Easy | |28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | Easy | -|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Easy | -|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Easy | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Easy | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Medium | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Medium | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Medium | |35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | Easy | -|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Easy | -|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Easy | -|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Easy | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Easy | -|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Easy | -|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Easy | -|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Easy | -|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | Easy | -|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | Easy | -|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | Easy | -|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Easy | -|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Easy | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Medium | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Medium | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Medium | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Medium | +|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Medium | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Medium | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | Medium | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | Medium | +|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | Medium | +|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Medium | +|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Medium | |53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) | Easy | -|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | Easy | -|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | Easy | -|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | Easy | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | Medium | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | Medium | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | Medium | |58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word/) | Easy | -|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths/) | Easy | -|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) | Easy | -|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) | Easy | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths/) | Medium | +|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) | Medium | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) | Medium | |66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | Easy | |67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary/) | Easy | |69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | Easy | |70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | Easy | -|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | Easy | -|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | Easy | -|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | Easy | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | Easy | -|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | Easy | -|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | Easy | -|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | Easy | -|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) | Easy | -|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | Easy | -|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | Easy | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | Medium | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | Medium | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | Medium | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | Medium | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | Medium | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | Medium | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | Medium | +|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) | Medium | +|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | Medium | +|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | Medium | |83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | Easy | |88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | Easy | -|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Easy | -|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Easy | -|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | Easy | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Medium | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Medium | +|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | Medium | |94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) | Easy | -|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | Easy | -|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | Easy | -|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | Easy | +|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | Medium | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | Medium | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | Medium | |100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree/) | Easy | |101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) | Easy | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | Easy | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | Easy | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | Medium | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | Medium | |104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | Easy | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | Easy | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | Easy | -|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | Easy | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | Medium | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | Medium | +|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | Medium | |108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) | Easy | |110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree/) | Easy | |111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) | Easy | |112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum/) | Easy | -|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) | Easy | +|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) | Medium | |118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle/) | Easy | |119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii/) | Easy | -|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | Easy | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | Medium | |121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/) | Easy | |122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | Easy | |125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | Easy | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Easy | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Medium | |136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | Easy | -|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Easy | +|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Medium | |144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | Easy | |145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | Easy | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Easy | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | Easy | -|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Easy | -|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | Easy | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Medium | +|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | Medium | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Medium | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | Medium | |155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | Easy | -|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | Easy | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | Easy | -|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | Easy | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | Medium | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | Medium | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | Medium | |167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | Easy | |168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | Easy | |169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element/) | Easy | |171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) | Easy | |172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | Easy | -|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | Easy | -|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | Easy | +|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | Medium | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | Medium | |190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | Easy | |191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | Easy | -|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | Easy | -|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | Easy | -|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | Easy | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | Easy | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | Medium | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | Medium | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | Medium | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | Medium | |202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number/) | Easy | |203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) | Easy | |204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | Easy | |205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | Easy | |206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | Easy | -|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | Easy | -|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | Easy | -|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | Easy | -|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) | Easy | -|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) | Easy | +|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | Medium | +|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | Medium | +|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | Medium | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) | Medium | +|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) | Medium | |217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate/) | Easy | |219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii/) | Easy | -|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) | Easy | -|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area/) | Easy | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) | Medium | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area/) | Medium | |225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues/) | Easy | |226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree/) | Easy | |228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges/) | Easy | -|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) | Easy | -|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) | Easy | +|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) | Medium | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) | Medium | |231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two/) | Easy | |232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks/) | Easy | |234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) | Easy | |235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | Easy | -|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Easy | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Medium | |242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | Easy | |257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | Easy | |258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits/) | Easy | |263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | Easy | |268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | Easy | -|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Easy | +|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Medium | |278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | -|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Easy | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | |290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | |300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | |303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | -|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Easy | -|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Easy | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | |326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | |349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | |350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Easy | +|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | |367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Easy | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | -|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Easy | -|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Easy | +|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | |476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | -|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Easy | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | -|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Easy | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | -|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Easy | -|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Easy | +|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | +|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | |594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | -|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Easy | -|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Easy | +|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | |653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | -|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Easy | +|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | -|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Easy | -|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Easy | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Easy | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | -|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Easy | -|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Easy | -|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Easy | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | +|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | |924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Easy | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | |981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | -|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Easy | -|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | Easy | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Medium | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | Medium | |1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | Easy | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Easy | -|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Easy | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Easy | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | +|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | -|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Easy | -|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Easy | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | -|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Easy | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | -|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Easy | +|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | -|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Easy | +|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | -|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Easy | -|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Easy | -|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Easy | -|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Easy | -|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Easy | +|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | +|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | +|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | |1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | -|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Easy | +|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Medium | |1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | Easy | -|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Easy | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | |1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | -|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Easy | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | |1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | |1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | -|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Easy | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Medium | |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Easy | -|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Easy | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | +|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | |1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | Easy | |1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | Easy | |1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | @@ -243,17 +244,17 @@ |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | -|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Easy | +|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | -|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Easy | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | -|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Easy | -|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Easy | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | +|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | |100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | |100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | -|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Easy | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | From 7a4565e6a2b3c25f4b9116e4baaa5cc653fed08f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 27 Jul 2021 21:29:45 +0800 Subject: [PATCH 0045/1556] src/bin/4sum.rs --- src/bin/4sum.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/4sum.rs b/src/bin/4sum.rs index e10ccbca..751401f5 100644 --- a/src/bin/4sum.rs +++ b/src/bin/4sum.rs @@ -1,7 +1,7 @@ fn main() { - // println!("{:?}", Solution::four_sum(vec![1, 0, -1, 0, -2, 2], 0)); - // println!("{:?}", Solution::four_sum(vec![0, 0, 0, 0], 0)); - // println!("{:?}", Solution::four_sum(vec![-2, -1, -1, 1, 1, 2, 2], 0)); + println!("{:?}", Solution::four_sum(vec![1, 0, -1, 0, -2, 2], 0)); + println!("{:?}", Solution::four_sum(vec![0, 0, 0, 0], 0)); + println!("{:?}", Solution::four_sum(vec![-2, -1, -1, 1, 1, 2, 2], 0)); println!( "{:?}", Solution::four_sum(vec![1, -2, -5, -4, -3, 3, 3, 5], -11) From 5996485bc2a02d1768cdf56c2ab82e40b156902a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 27 Jul 2021 21:29:46 +0800 Subject: [PATCH 0046/1556] README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e63af034..91e20dcb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 250 | 117 | 133 | 0 | +| 250 | 117 | 127 | 6 | ### 题目 @@ -11,7 +11,7 @@ |1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | Easy | |2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | Medium | |3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | Medium | -|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Medium | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Hard | |6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | Medium | |7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | Easy | |8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | Medium | @@ -24,12 +24,13 @@ |16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest/) | Medium | |17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | Medium | |18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | Medium | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | Medium | |19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Medium | |20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | Easy | |21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | Easy | -|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Medium | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Hard | |24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | Medium | -|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Medium | +|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Hard | |26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | Easy | |27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | Easy | |28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | Easy | @@ -40,15 +41,15 @@ |36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Medium | |38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Medium | |39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Medium | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Hard | |43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Medium | |45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Medium | |46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Medium | |48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | Medium | |49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | Medium | |50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | Medium | -|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Medium | -|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Medium | +|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Hard | +|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Hard | |53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) | Easy | |55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | Medium | |56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | Medium | @@ -186,7 +187,6 @@ |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | |649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | |650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | -|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | |653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | From 521b918522fc43038dc5cc8c8c6890cd44553a61 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 27 Jul 2021 21:31:29 +0800 Subject: [PATCH 0047/1556] regular matching of READMD.md failed, unable to parse the field --- src/file.rs | 11 ++++++++--- src/http.rs | 13 ++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/file.rs b/src/file.rs index 10070d6f..25ba4f31 100644 --- a/src/file.rs +++ b/src/file.rs @@ -6,7 +6,7 @@ use regex::Regex; use crate::http::{Resp, Data, Ques, Difficulty}; lazy_static!( - static ref RE: Regex = Regex::new(r"\|\s*([0-9]*)\s*\|\s*(.*?)\s*\|.*?bin/(.*?)\.rs.*?\|.*?\|").unwrap(); + static ref RE: Regex = Regex::new(r"\|\s*([0-9]*)\s*\|\s*(.*?)\s*\|.*?bin/(.*?)\.rs.*?\|.*?\|\s*?(\w*)\s*?\|").unwrap(); ); /// 将结果写入README.md中 @@ -77,7 +77,7 @@ fn parse(contents: &str) -> Vec { translated_title: i.get(2).unwrap().as_str().to_string(), title_slug: i.get(3).unwrap().as_str().to_string(), code_snippets: vec![], - difficulty: Difficulty::Easy, + difficulty: Difficulty::new(i.get(4).unwrap().as_str()), } }, }) @@ -99,7 +99,12 @@ mod tests { println!("{}", x.len()); for i in x { - println!("{}, {}, {}", i.data.question.translated_title, i.data.question.question_id, i.data.question.title_slug); + println!("{}, {}, {}, {:?}", + i.data.question.translated_title, + i.data.question.question_id, + i.data.question.title_slug, + i.data.question.difficulty + ); } } diff --git a/src/http.rs b/src/http.rs index 33f51a58..cdcfcb2a 100644 --- a/src/http.rs +++ b/src/http.rs @@ -20,6 +20,17 @@ pub enum Difficulty { Hard, } +impl Difficulty { + pub fn new(s: &str) -> Self { + match s { + "Easy" => Self::Easy, + "Medium" => Self::Medium, + "Hard" => Self::Hard, + _ => Self::Easy + } + } +} + impl Serialize for Difficulty { fn serialize(&self, serializer: S) -> Result where @@ -117,7 +128,7 @@ pub fn get_question_info(mut ques: &str) -> Resp { .send() .unwrap() .json::() - .unwrap() + .expect(format!("{} download failed", ques).as_str()) } #[cfg(test)] From a50fddf6b99eee23d48f0a7ffb5232d81288676a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 28 Jul 2021 23:31:26 +0800 Subject: [PATCH 0048/1556] src/bin/nim-game.rs --- src/bin/nim-game.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/bin/nim-game.rs diff --git a/src/bin/nim-game.rs b/src/bin/nim-game.rs new file mode 100644 index 00000000..a8cdcb9c --- /dev/null +++ b/src/bin/nim-game.rs @@ -0,0 +1,9 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn can_win_nim(n: i32) -> bool { + n % 4 != 0 + } +} From 493a4e15db57d806d9b6923c4a2283bd25c339b5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 28 Jul 2021 23:31:26 +0800 Subject: [PATCH 0049/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 91e20dcb..fabd93a1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 250 | 117 | 127 | 6 | +| 251 | 118 | 127 | 6 | ### 题目 @@ -159,6 +159,7 @@ |278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | |279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | |290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | +|292 | Nim 游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nim-game.rs) | [leetcode](https://leetcode-cn.com/problems/nim-game/) | Easy | |300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | |303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | |318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | From 2c37140c9697604498fec1a49573a26cbe4d0155 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 29 Jul 2021 22:29:44 +0800 Subject: [PATCH 0050/1556] src/bin/move-zeroes.rs --- src/bin/move-zeroes.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/move-zeroes.rs diff --git a/src/bin/move-zeroes.rs b/src/bin/move-zeroes.rs new file mode 100644 index 00000000..44a59073 --- /dev/null +++ b/src/bin/move-zeroes.rs @@ -0,0 +1,32 @@ +fn main() { + let mut v = vec![0, 1, 0, 3, 12]; + Solution::move_zeroes(&mut v); + println!("{:?}", v); +} + +struct Solution; + +impl Solution { + pub fn move_zeroes(nums: &mut Vec) { + let (mut i, mut j) = (0, 0); + + while j < nums.len() { + match (nums[i], nums[j]) { + (0, 0) => { + j += 1; + } + (_, 0) => { + j += 1; + } + (0, _) => { + nums.swap(i, j); + i += 1; + } + _ => { + i += 1; + j += 1; + } + } + } + } +} From 7e6dfb270bfc4de670c7d7bb39590a00dd87be89 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 29 Jul 2021 22:29:45 +0800 Subject: [PATCH 0051/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fabd93a1..5ebbb6c2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 251 | 118 | 127 | 6 | +| 252 | 119 | 127 | 6 | ### 题目 @@ -158,6 +158,7 @@ |274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Medium | |278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | |279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | +|283 | 移动零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/move-zeroes/) | Easy | |290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | |292 | Nim 游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nim-game.rs) | [leetcode](https://leetcode-cn.com/problems/nim-game/) | Easy | |300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | From b0340b305b406fd1a491797b8c9b01996bdb0276 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 30 Jul 2021 21:22:22 +0800 Subject: [PATCH 0052/1556] src/bin/ransom-note.rs --- src/bin/ransom-note.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/bin/ransom-note.rs diff --git a/src/bin/ransom-note.rs b/src/bin/ransom-note.rs new file mode 100644 index 00000000..f93c9765 --- /dev/null +++ b/src/bin/ransom-note.rs @@ -0,0 +1,26 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn can_construct(ransom_note: String, magazine: String) -> bool { + let mut h = std::collections::HashMap::new(); + for i in magazine.bytes() { + h.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + + for i in ransom_note.bytes() { + if let Some(x) = h.get_mut(&i) { + if *x >= 1 { + *x -= 1; + continue; + } + } + + return false; + } + + + true + } +} From bc3e9e81161036e8aea37ee402c7adeb9b628402 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 30 Jul 2021 21:22:23 +0800 Subject: [PATCH 0053/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ebbb6c2..394b71a4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 252 | 119 | 127 | 6 | +| 253 | 120 | 127 | 6 | ### 题目 @@ -172,6 +172,7 @@ |367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | |371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | +|383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | From 1daf38a76b9b032dda1c591d51ac3e573900ec1b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 31 Jul 2021 22:50:20 +0800 Subject: [PATCH 0054/1556] src/bin/ransom-note.rs --- src/bin/ransom-note.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin/ransom-note.rs b/src/bin/ransom-note.rs index f93c9765..7c9bb5ad 100644 --- a/src/bin/ransom-note.rs +++ b/src/bin/ransom-note.rs @@ -20,7 +20,6 @@ impl Solution { return false; } - true } } From c14137122c10a3139d2bf1abcb7adb7ba3d39bf2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 31 Jul 2021 22:50:20 +0800 Subject: [PATCH 0055/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 394b71a4..6d829d5d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 253 | 120 | 127 | 6 | +| 254 | 121 | 127 | 6 | ### 题目 @@ -173,6 +173,7 @@ |371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | +|383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | From b15bfb6fa83a6cc46dcc993cbfcba3747002bd7c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 1 Aug 2021 23:59:19 +0800 Subject: [PATCH 0056/1556] src/bin/find-the-difference.rs --- src/bin/find-the-difference.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/find-the-difference.rs diff --git a/src/bin/find-the-difference.rs b/src/bin/find-the-difference.rs new file mode 100644 index 00000000..50628a63 --- /dev/null +++ b/src/bin/find-the-difference.rs @@ -0,0 +1,23 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_the_difference(s: String, t: String) -> char { + let mut h = vec![0u8; 26]; + + for i in s.bytes() { + h[(i - b'a') as usize] += 1; + } + + for i in t.bytes() { + if h[(i - b'a') as usize] == 0 { + return i as char; + } + + h[(i - b'a') as usize] -= 1; + } + + 'a' + } +} From 12de9c9dd0a5aacc791d6cb8059385308d556047 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 1 Aug 2021 23:59:20 +0800 Subject: [PATCH 0057/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d829d5d..991c2794 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 254 | 121 | 127 | 6 | +| 255 | 122 | 127 | 6 | ### 题目 @@ -175,6 +175,7 @@ |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | +|389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | From 7cbdd736ef646397c957cf330ace6cd7e4aba5c8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 4 Aug 2021 00:00:06 +0800 Subject: [PATCH 0058/1556] src/bin/add-strings.rs --- src/bin/add-strings.rs | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/bin/add-strings.rs diff --git a/src/bin/add-strings.rs b/src/bin/add-strings.rs new file mode 100644 index 00000000..eb46559b --- /dev/null +++ b/src/bin/add-strings.rs @@ -0,0 +1,45 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn add_strings(num1: String, num2: String) -> String { + let mut i = 0u8; // 进制 + let (num1, num2) = (num1.as_bytes(), num2.as_bytes()); + let (mut i1, mut i2) = (num1.len(), num2.len()); + + let mut v = vec![0u8; i1.max(i2) + 1]; + let mut vindex = v.len() - 1; + + loop { + let a = if i1 == 0 && i2 == 0 { + break; + } else if i1 == 0 && i2 > 0 { + i2 -= 1; + num2[i2] - b'0' + i + } else if i1 > 0 && i2 == 0 { + i1 -= 1; + num1[i1] - b'0' + i + } else { + i2 -= 1; + i1 -= 1; + num1[i1] + num2[i2] -b'0' + i + }; + + if a >= 10 { + v[vindex] = a - 10; + i = 1; + } else { + v[vindex] = a; + i = 0; + } + + vindex -= 1; + } + + v[vindex..].iter().fold(String::with_capacity((&v[vindex..]).len()), |mut x, y| { + x.push_str(&*y.to_string()); + x + }) + } +} From ba4f4e78cceff798baffbe8849390501a335836f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 4 Aug 2021 00:00:07 +0800 Subject: [PATCH 0059/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 991c2794..b34e7540 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 255 | 122 | 127 | 6 | +| 256 | 123 | 127 | 6 | ### 题目 @@ -177,6 +177,7 @@ |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | +|415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | From 462504ee1dca86793f0613403e96b94a493e80d8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 4 Aug 2021 00:09:02 +0800 Subject: [PATCH 0060/1556] src/bin/add-strings.rs --- src/bin/add-strings.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/bin/add-strings.rs b/src/bin/add-strings.rs index eb46559b..09f4a19e 100644 --- a/src/bin/add-strings.rs +++ b/src/bin/add-strings.rs @@ -12,9 +12,7 @@ impl Solution { let mut vindex = v.len() - 1; loop { - let a = if i1 == 0 && i2 == 0 { - break; - } else if i1 == 0 && i2 > 0 { + let a = if i1 == 0 && i2 > 0 { i2 -= 1; num2[i2] - b'0' + i } else if i1 > 0 && i2 == 0 { @@ -23,7 +21,7 @@ impl Solution { } else { i2 -= 1; i1 -= 1; - num1[i1] + num2[i2] -b'0' + i + num1[i1] + num2[i2] - b'0' - b'0' + i }; if a >= 10 { @@ -34,7 +32,16 @@ impl Solution { i = 0; } + if i1 == 0 && i2 == 0 { + break; + } + + vindex -= 1; + } + + if i != 0 { vindex -= 1; + v[vindex] = 1; } v[vindex..].iter().fold(String::with_capacity((&v[vindex..]).len()), |mut x, y| { From e5b7b388e28310f633d8f3327f3db07e2db44e22 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 4 Aug 2021 00:09:03 +0800 Subject: [PATCH 0061/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b34e7540..791d392e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 256 | 123 | 127 | 6 | +| 257 | 124 | 127 | 6 | ### 题目 @@ -178,6 +178,7 @@ |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | +|415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | From 71fe6784a1e98fdb32561910bfb80bf996f24f36 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 5 Aug 2021 23:30:27 +0800 Subject: [PATCH 0062/1556] src/bin/is-subsequence.rs --- src/bin/is-subsequence.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/is-subsequence.rs diff --git a/src/bin/is-subsequence.rs b/src/bin/is-subsequence.rs new file mode 100644 index 00000000..9130871e --- /dev/null +++ b/src/bin/is-subsequence.rs @@ -0,0 +1,25 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn is_subsequence(s: String, t: String) -> bool { + let (mut i, mut j) = (0, 0); // i: s'index, j: t'index + let (s, t) = (s.as_bytes(), t.as_bytes()); + loop { + if i == s.len() { + return true; + } + if j == t.len() { + break; + } + + if s[i] == t[j] { + i += 1; + } + j += 1; + } + + return false; + } +} From 851bed41e6689f19e78e9aa12e7c627130c7f334 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 5 Aug 2021 23:30:28 +0800 Subject: [PATCH 0063/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 791d392e..4fec5843 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 257 | 124 | 127 | 6 | +| 258 | 125 | 127 | 6 | ### 题目 @@ -176,6 +176,7 @@ |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | +|392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | |415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | From 6cee9b8c06261c7572fb54c09c4091e22c5545c9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 6 Aug 2021 23:43:53 +0800 Subject: [PATCH 0064/1556] src/bin/coin-change.rs --- src/bin/coin-change.rs | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/bin/coin-change.rs diff --git a/src/bin/coin-change.rs b/src/bin/coin-change.rs new file mode 100644 index 00000000..1c2ff45b --- /dev/null +++ b/src/bin/coin-change.rs @@ -0,0 +1,49 @@ +fn main() { + println!("{}", Solution::coin_change(vec![1, 2, 5], 11)); + println!("{}", Solution::coin_change(vec![1], 1)); + println!("{}", Solution::coin_change(vec![1, 2, 5], 100)); +} + +struct Solution; + +impl Solution { + pub fn coin_change(coins: Vec, amount: i32) -> i32 { + if amount == 0 { return 0; } + + let mut h = std::collections::HashMap::new(); + + Self::f(&coins[..], &mut h, amount) + } + + fn f(coins: &[i32], h: &mut std::collections::HashMap, amount: i32) -> i32 { + let mut num = -1; + + for &i in coins { + if i > amount { + continue; + } else if i == amount { + return 1; + } + + let x = if let Some(x) = h.get(&(amount - i)) { + *x + } else { + Self::f(coins, h, amount - i) + }; + + if x == -1 { + continue; + } + + if num == -1 { + num = x + 1; + } else { + num = num.min(x + 1); + } + } + + h.insert(amount, num); + + num + } +} From 7b37ee23ffee1eca8b5fbc311623b064699e3cb5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 6 Aug 2021 23:43:53 +0800 Subject: [PATCH 0065/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4fec5843..ac924dbf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 258 | 125 | 127 | 6 | +| 259 | 125 | 128 | 6 | ### 题目 @@ -165,6 +165,7 @@ |303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | |318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | |319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | +|322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | |326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | |349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | |350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | From 4d15badeb0fc1b6039e1b03d20ac4aa8751f1f6e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 12 Aug 2021 23:47:22 +0800 Subject: [PATCH 0066/1556] src/bin/fizz-buzz.rs --- src/bin/fizz-buzz.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/fizz-buzz.rs diff --git a/src/bin/fizz-buzz.rs b/src/bin/fizz-buzz.rs new file mode 100644 index 00000000..3b4d758c --- /dev/null +++ b/src/bin/fizz-buzz.rs @@ -0,0 +1,23 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn fizz_buzz(n: i32) -> Vec { + let mut v = Vec::with_capacity(n as usize); + + for i in 1..=n { + if i % 3 == 0 && i % 5 == 0 { + v.push("FizzBuzz".to_string()); + } else if i % 3 == 0 { + v.push("Fizz".to_string()); + } else if i % 5 == 0 { + v.push("Buzz".to_string()); + } else { + v.push(i.to_string()); + } + } + + v + } +} From 419432350da8aa0cf594b9489f9776575d438975 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 12 Aug 2021 23:47:22 +0800 Subject: [PATCH 0067/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ac924dbf..be6a0468 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 259 | 125 | 128 | 6 | +| 260 | 126 | 128 | 6 | ### 题目 @@ -179,6 +179,7 @@ |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | |392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | +|412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | |415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | |415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | From 3161d719ca3dff095188d03ea4d5fa6649b8eb85 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 15 Aug 2021 22:19:21 +0800 Subject: [PATCH 0068/1556] src/bin/insert-delete-getrandom-o1.rs --- src/bin/insert-delete-getrandom-o1.rs | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/bin/insert-delete-getrandom-o1.rs diff --git a/src/bin/insert-delete-getrandom-o1.rs b/src/bin/insert-delete-getrandom-o1.rs new file mode 100644 index 00000000..15dd0a75 --- /dev/null +++ b/src/bin/insert-delete-getrandom-o1.rs @@ -0,0 +1,52 @@ +fn main() {} + +struct Solution; + +/** + * Your RandomizedSet object will be instantiated and called as such: + * let obj = RandomizedSet::new(); + * let ret_1: bool = obj.insert(val); + * let ret_2: bool = obj.remove(val); + * let ret_3: i32 = obj.get_random(); + */ +struct RandomizedSet { + set: std::cell::RefCell>, +} + + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl RandomizedSet { + /** Initialize your data structure here. */ + fn new() -> Self { + Self { + set: std::cell::RefCell::new(std::collections::HashSet::default()), + } + } + + /** Inserts a value to the set. Returns true if the set did not already contain the specified element. */ + fn insert(&self, val: i32) -> bool { + self.set.borrow_mut().insert(val) + } + + /** Removes a value from the set. Returns true if the set contained the specified element. */ + fn remove(&self, val: i32) -> bool { + self.set.borrow_mut().remove(&val) + } + + /** Get a random element from the set. */ + fn get_random(&self) -> i32 { + use rand::Rng; + let mut rng = rand::thread_rng(); + let s = rng.gen_range(0..self.set.borrow().len()); + for (i, v) in self.set.borrow().iter().enumerate() { + if i == s { + return *v; + } + } + + 0 + } +} From 9673038a8dd33103d8feae08d8a55d617216a0d2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 15 Aug 2021 22:19:22 +0800 Subject: [PATCH 0069/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index be6a0468..a04b2f96 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 260 | 126 | 128 | 6 | +| 261 | 126 | 129 | 6 | ### 题目 @@ -173,6 +173,7 @@ |367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | |371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | +|380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | From 62df1a6d07e35d75577cc9590bd36507dc5aa7e7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 15 Aug 2021 22:19:35 +0800 Subject: [PATCH 0070/1556] add rand --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index dd4342f5..3acd6cb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ clap = "3.0.0-beta.2" tera = "1.12.1" lazy_static = "1.4.0" regex = "1" +rand = "0.8.4" [[bin]] From d19f899db719812e255ff420ae535c57d74e4391 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 16 Aug 2021 22:40:06 +0800 Subject: [PATCH 0071/1556] src/bin/reverse-string.rs --- src/bin/reverse-string.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/bin/reverse-string.rs diff --git a/src/bin/reverse-string.rs b/src/bin/reverse-string.rs new file mode 100644 index 00000000..2789f7a0 --- /dev/null +++ b/src/bin/reverse-string.rs @@ -0,0 +1,18 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn reverse_string(s: &mut Vec) { + if s.is_empty() { + return; + } + let (mut s1, mut s2) = (0, s.len() - 1); + + while s1 < s2 { + s.swap(s1, s2); + s1 += 1; + s2 -= 1; + } + } +} From 6714072e4ac4bd43cff66beed68e00b847d813f5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 16 Aug 2021 22:40:07 +0800 Subject: [PATCH 0072/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a04b2f96..97ff94aa 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 261 | 126 | 129 | 6 | +| 262 | 127 | 129 | 6 | ### 题目 @@ -167,6 +167,7 @@ |319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | |322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | |326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | +|344 | 反转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string/) | Easy | |349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | |350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | |357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | From 112d07c41388b8bb1211634c81632590ecfac768 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 18 Aug 2021 22:23:46 +0800 Subject: [PATCH 0073/1556] src/bin/kth-smallest-element-in-a-sorted-matrix.rs --- ...kth-smallest-element-in-a-sorted-matrix.rs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/bin/kth-smallest-element-in-a-sorted-matrix.rs diff --git a/src/bin/kth-smallest-element-in-a-sorted-matrix.rs b/src/bin/kth-smallest-element-in-a-sorted-matrix.rs new file mode 100644 index 00000000..30a62f30 --- /dev/null +++ b/src/bin/kth-smallest-element-in-a-sorted-matrix.rs @@ -0,0 +1,38 @@ +fn main() {} + +struct Solution; + +impl Solution { + /// 二分查找法? + pub fn kth_smallest(matrix: Vec>, k: i32) -> i32 { + let (mut left, mut right) = (matrix[0][0], matrix[matrix.len() - 1][matrix.len() - 1]); + + while left < right { + let mid = left + (right - left) / 2; + let num = Self::get_number(&matrix[..], mid); + if num >= k { + right = mid; + } else { + left = mid + 1; + } + } + left + } + + /// 求个数 + fn get_number(matrix: &[Vec], mid: i32) -> i32 { + let (mut i, mut j) = (matrix.len() as i32 - 1, 0i32); + let mut num = 0; + + while i >= 0 && j < matrix.len() as i32 { + if matrix[i as usize][j as usize] <= mid { + num += i as i32 + 1; + j += 1; + } else { + i -= 1; + } + } + + num + } +} \ No newline at end of file From 8077872ec19b401e1699db7e091cc39b9305b9c6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 18 Aug 2021 22:23:47 +0800 Subject: [PATCH 0074/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 97ff94aa..53a324ab 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 262 | 127 | 129 | 6 | +| 263 | 127 | 130 | 6 | ### 题目 @@ -174,6 +174,7 @@ |367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | |371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | +|378 | 有序矩阵中第 K 小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-sorted-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/) | Medium | |380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | From b3f2408de7d9b96986d895a35ae21241ab018863 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 21 Aug 2021 20:41:28 +0800 Subject: [PATCH 0075/1556] src/bin/shuffle-an-array.rs --- src/bin/shuffle-an-array.rs | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/bin/shuffle-an-array.rs diff --git a/src/bin/shuffle-an-array.rs b/src/bin/shuffle-an-array.rs new file mode 100644 index 00000000..138a166c --- /dev/null +++ b/src/bin/shuffle-an-array.rs @@ -0,0 +1,39 @@ +fn main() {} + +/** + * Your Solution object will be instantiated and called as such: + * let obj = Solution::new(nums); + * let ret_1: Vec = obj.reset(); + * let ret_2: Vec = obj.shuffle(); + */ +struct Solution { + nums: Vec, +} + + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl Solution { + fn new(nums: Vec) -> Self { + Self { nums } + } + + /** Resets the array to its original configuration and return it. */ + fn reset(&self) -> Vec { + self.nums.clone() + } + + /** Returns a random shuffling of the array. */ + fn shuffle(&self) -> Vec { + use rand::Rng; + + let mut rng = rand::thread_rng(); + let mut v = self.nums.clone(); + for i in 0..self.nums.len() { + v.swap(rng.gen_range(0..self.nums.len()), i); + } + v + } +} From cdf27310903f8febcf08f427d2cc62d2a357136b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 21 Aug 2021 20:41:28 +0800 Subject: [PATCH 0076/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 53a324ab..8123c661 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 263 | 127 | 130 | 6 | +| 264 | 127 | 131 | 6 | ### 题目 @@ -178,6 +178,7 @@ |380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | +|384 | 打乱数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shuffle-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/shuffle-an-array/) | Medium | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | |392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | From e55680b28db69bbda33021f037ca1712dd9563cb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 23 Aug 2021 21:48:57 +0800 Subject: [PATCH 0077/1556] src/bin/max-consecutive-ones.rs --- src/bin/max-consecutive-ones.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/max-consecutive-ones.rs diff --git a/src/bin/max-consecutive-ones.rs b/src/bin/max-consecutive-ones.rs new file mode 100644 index 00000000..c020cd2b --- /dev/null +++ b/src/bin/max-consecutive-ones.rs @@ -0,0 +1,20 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_max_consecutive_ones(nums: Vec) -> i32 { + let mut r = 0; + let mut count = 0; + + for i in nums { + if i == 1 { + count += 1; + } else { + r = r.max(count); + count = 0 + } + } + r + } +} From b2f59831521c9bdaeed19da0c1974e62045cf63f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 23 Aug 2021 21:48:58 +0800 Subject: [PATCH 0078/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8123c661..86cc322e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 264 | 127 | 131 | 6 | +| 265 | 128 | 131 | 6 | ### 题目 @@ -191,6 +191,7 @@ |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | |476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | +|485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | From f4f084072eb2bf799c44687dd40c415e4a38dc01 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 24 Aug 2021 22:21:10 +0800 Subject: [PATCH 0079/1556] src/bin/arithmetic-slices.rs --- src/bin/arithmetic-slices.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/arithmetic-slices.rs diff --git a/src/bin/arithmetic-slices.rs b/src/bin/arithmetic-slices.rs new file mode 100644 index 00000000..6638d930 --- /dev/null +++ b/src/bin/arithmetic-slices.rs @@ -0,0 +1,31 @@ +fn main() { + println!("{}", Solution::number_of_arithmetic_slices(vec![1, 2, 3, 4])); + println!("{}", Solution::number_of_arithmetic_slices(vec![1, 2, 3, 4, 5, 6])); + println!("{}", Solution::number_of_arithmetic_slices(vec![1, 2, 3, 4, 10, 11, 12, 13])); +} + +struct Solution; + +impl Solution { + pub fn number_of_arithmetic_slices(nums: Vec) -> i32 { + if nums.len() < 3 { return 0; } + + let mut count = 0; + let mut num = 2; + let mut s = nums[1] - nums[0]; + + for i in 2..nums.len() { + if nums[i] - nums[i - 1] == s { + num += 1; + } else { + if num >= 3 { count += (1..=num - 3 + 1).into_iter().sum::(); } + s = nums[i] - nums[i - 1]; + num = 2; + } + } + + if num >= 3 { count += (1..=num - 3 + 1).into_iter().sum::(); } + + count + } +} From 893a8c9b6b98b469c383043d53584435ce41756d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 24 Aug 2021 22:21:10 +0800 Subject: [PATCH 0080/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 86cc322e..14fa5894 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 265 | 128 | 131 | 6 | +| 266 | 128 | 132 | 6 | ### 题目 @@ -184,6 +184,7 @@ |392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | +|413 | 等差数列划分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/arithmetic-slices.rs) | [leetcode](https://leetcode-cn.com/problems/arithmetic-slices/) | Medium | |415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | |415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | From e25cf8b17ef8e024cdd03a07488a91c433f8d5a4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 25 Aug 2021 13:45:44 +0800 Subject: [PATCH 0081/1556] fix readme table error --- src/render.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render.rs b/src/render.rs index 353717a9..55abb3f5 100644 --- a/src/render.rs +++ b/src/render.rs @@ -10,7 +10,7 @@ const TEMPLATE_STR: &str = r"# leetcode ### 题目 -| 编号 | 题目 | 描述 | 代码 | 难度 | +| 编号 | 题目 | 代码 | 题目描述 | 难度 | | ---- | ---- | ---- | ---- | ---- | {% for t in datas %}|{{ t.data.question.questionId }} | {{ t.data.question.translatedTitle }} | [src](https://github.com/rustors/leetcode/blob/main/src/bin/{{ t.data.question.titleSlug }}.rs) | [leetcode](https://leetcode-cn.com/problems/{{ t.data.question.titleSlug }}/) | {{ t.data.question.difficulty }} | {% endfor %}"; From 57490b1cd53c237b93a55c48e10c322e7f903d9b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 25 Aug 2021 13:46:12 +0800 Subject: [PATCH 0082/1556] fix --- README.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 14fa5894..07f688ca 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 266 | 128 | 132 | 6 | +| 263 | 125 | 132 | 6 | ### 题目 @@ -24,7 +24,6 @@ |16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest/) | Medium | |17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | Medium | |18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | Medium | -|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | Medium | |19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Medium | |20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | Easy | |21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | Easy | @@ -116,7 +115,7 @@ |167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | Easy | |168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | Easy | |169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element/) | Easy | -|171 | Excel表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) | Easy | +|171 | Excel 表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) | Easy | |172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | Easy | |173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | Medium | |187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | Medium | @@ -177,7 +176,6 @@ |378 | 有序矩阵中第 K 小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-sorted-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/) | Medium | |380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | -|383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |384 | 打乱数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shuffle-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/shuffle-an-array/) | Medium | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | @@ -186,7 +184,6 @@ |412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | |413 | 等差数列划分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/arithmetic-slices.rs) | [leetcode](https://leetcode-cn.com/problems/arithmetic-slices/) | Medium | |415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | -|415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | @@ -208,7 +205,7 @@ |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | -|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Easy | +|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | |917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | From 0de6f5f05648ab6dd4124f5e029b13ecb32ed5e3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 25 Aug 2021 13:49:38 +0800 Subject: [PATCH 0083/1556] fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 07f688ca..f826b1ad 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ### 题目 -| 编号 | 题目 | 描述 | 代码 | 难度 | +| 编号 | 题目 | 代码 | 题目描述 | 难度 | | ---- | ---- | ---- | ---- | ---- | |1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | Easy | |2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | Medium | From 650260a81b91dfffa279a998097764e26fa32591 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 26 Aug 2021 23:53:53 +0800 Subject: [PATCH 0084/1556] src/bin/lexicographical-numbers.rs --- src/bin/lexicographical-numbers.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/bin/lexicographical-numbers.rs diff --git a/src/bin/lexicographical-numbers.rs b/src/bin/lexicographical-numbers.rs new file mode 100644 index 00000000..116e7558 --- /dev/null +++ b/src/bin/lexicographical-numbers.rs @@ -0,0 +1,16 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn lexical_order(n: i32) -> Vec { + let mut s = (1..=n) + .into_iter() + .map(|x| x.to_string()) + .collect::>(); + + s.sort(); + + s.into_iter().map(|x| x.parse::().unwrap()).collect::>() + } +} From dc0f120807825e6713ba57ed29531bcdbcd16858 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 26 Aug 2021 23:53:54 +0800 Subject: [PATCH 0085/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f826b1ad..3723fb04 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 263 | 125 | 132 | 6 | +| 264 | 125 | 133 | 6 | ### 题目 @@ -177,6 +177,7 @@ |380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |384 | 打乱数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shuffle-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/shuffle-an-array/) | Medium | +|386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | |392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | From 2b38318e882ba02aa78f99304c749c1fd2afacff Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 27 Aug 2021 00:06:40 +0800 Subject: [PATCH 0086/1556] src/bin/lexicographical-numbers.rs --- src/bin/lexicographical-numbers.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/bin/lexicographical-numbers.rs b/src/bin/lexicographical-numbers.rs index 116e7558..8a55dee7 100644 --- a/src/bin/lexicographical-numbers.rs +++ b/src/bin/lexicographical-numbers.rs @@ -3,7 +3,7 @@ fn main() {} struct Solution; impl Solution { - pub fn lexical_order(n: i32) -> Vec { + pub fn lexical_order1(n: i32) -> Vec { let mut s = (1..=n) .into_iter() .map(|x| x.to_string()) @@ -13,4 +13,27 @@ impl Solution { s.into_iter().map(|x| x.parse::().unwrap()).collect::>() } + + pub fn lexical_order(n: i32) -> Vec { + let mut v = Vec::with_capacity(n as usize); + + for i in 1..10.min(n + 1) { + v.push(i); + Self::dfs(&mut v, i, n); + } + v + } + + fn dfs(v: &mut Vec, number: i32, n: i32) { + if number > n { return; } + + let number = number * 10; + + for i in 0..10 { + if number + i <= n { + v.push(number + i); + Self::dfs(v, number + i, n); + } + } + } } From fea7f27c682fcde64d91bbe8e65b80c364521056 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 27 Aug 2021 00:06:40 +0800 Subject: [PATCH 0087/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3723fb04..72a56a06 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 264 | 125 | 133 | 6 | +| 265 | 125 | 134 | 6 | ### 题目 @@ -178,6 +178,7 @@ |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |384 | 打乱数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shuffle-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/shuffle-an-array/) | Medium | |386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | +|386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | |392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | From 472f74097d496d7fd3d51f1fcf23e7d62628e5cb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 29 Aug 2021 23:22:20 +0800 Subject: [PATCH 0088/1556] src/bin/random-pick-index.rs --- src/bin/random-pick-index.rs | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/bin/random-pick-index.rs diff --git a/src/bin/random-pick-index.rs b/src/bin/random-pick-index.rs new file mode 100644 index 00000000..18ee9c4c --- /dev/null +++ b/src/bin/random-pick-index.rs @@ -0,0 +1,42 @@ +fn main() {} + +/** + * Your Solution object will be instantiated and called as such: + * let obj = Solution::new(nums); + * let ret_1: i32 = obj.pick(target); + */ +struct Solution { + index_map: std::collections::HashMap> +} + + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl Solution { + fn new(nums: Vec) -> Self { + let mut index_map = std::collections::HashMap::new(); + + nums + .into_iter() + .enumerate() + .for_each(|(index, value)| { + index_map.entry(value) + .and_modify(|y: &mut Vec| y.push(index)).or_insert(vec![index]); + }); + + Self { index_map } + } + + fn pick(&self, target: i32) -> i32 { + use rand::Rng; + + match self.index_map.get(&target) { + Some(x) => { + x[rand::thread_rng().gen_range(0..x.len())] as i32 + } + None => 0 + } + } +} From e6990c0932985a7d0221d756a2e09e42dcf95a36 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 29 Aug 2021 23:22:21 +0800 Subject: [PATCH 0089/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 72a56a06..50e09211 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 265 | 125 | 134 | 6 | +| 266 | 125 | 135 | 6 | ### 题目 @@ -182,6 +182,7 @@ |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | |392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | +|398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | |413 | 等差数列划分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/arithmetic-slices.rs) | [leetcode](https://leetcode-cn.com/problems/arithmetic-slices/) | Medium | From ac3c93cca2af05ae083fb43ce7079f62f0252287 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 30 Aug 2021 08:41:26 +0800 Subject: [PATCH 0090/1556] src/bin/random-pick-index.rs --- src/bin/random-pick-index.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/bin/random-pick-index.rs b/src/bin/random-pick-index.rs index 18ee9c4c..eee616a2 100644 --- a/src/bin/random-pick-index.rs +++ b/src/bin/random-pick-index.rs @@ -5,7 +5,7 @@ fn main() {} * let obj = Solution::new(nums); * let ret_1: i32 = obj.pick(target); */ -struct Solution { +struct Solution1 { index_map: std::collections::HashMap> } @@ -14,7 +14,7 @@ struct Solution { * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. */ -impl Solution { +impl Solution1 { fn new(nums: Vec) -> Self { let mut index_map = std::collections::HashMap::new(); @@ -40,3 +40,30 @@ impl Solution { } } } + +struct Solution { + nums: Vec +} + +impl Solution { + fn new(nums: Vec) -> Self { + Self { nums } + } + + fn pick(&self, target: i32) -> i32 { + use rand::Rng; + let mut n = 0; + let mut r = 0; + + for i in 0..self.nums.len() { + if self.nums[i] == target { + n += 1; + if rand::thread_rng().gen_range(0..n) == 0 { + r = i as i32; + } + } + } + + r + } +} \ No newline at end of file From 2e1d17846b62c401e02c41a818987566de9e67b9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 30 Aug 2021 08:41:27 +0800 Subject: [PATCH 0091/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 50e09211..deba56ff 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 266 | 125 | 135 | 6 | +| 267 | 125 | 136 | 6 | ### 题目 @@ -183,6 +183,7 @@ |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | |392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | +|398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | |413 | 等差数列划分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/arithmetic-slices.rs) | [leetcode](https://leetcode-cn.com/problems/arithmetic-slices/) | Medium | From a2d6213e035f03246158fa75a55d350a95910463 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 30 Aug 2021 20:22:25 +0800 Subject: [PATCH 0092/1556] src/bin/longest-palindrome.rs --- src/bin/longest-palindrome.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/longest-palindrome.rs diff --git a/src/bin/longest-palindrome.rs b/src/bin/longest-palindrome.rs new file mode 100644 index 00000000..e6d74c4e --- /dev/null +++ b/src/bin/longest-palindrome.rs @@ -0,0 +1,24 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn longest_palindrome(s: String) -> i32 { + let mut hash = std::collections::HashMap::new(); + s.as_bytes().into_iter().for_each(|x| { + hash.entry(x).and_modify(|v| *v += 1).or_insert(1); + }); + + let mut odd = false; // 是否有单数,如果有单数的话,则最后的结果+1 + + let mut r = 0; + + hash.into_iter().for_each(|(_, v)| if v % 2 == 0 { r += v; } else { + odd = true; + r += v - 1; + }); + + + if odd { r + 1 } else { r } + } +} From a379fbf6db324aec6c1f5790d249b65cfb51592b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 30 Aug 2021 20:22:26 +0800 Subject: [PATCH 0093/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index deba56ff..bd9d803a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 267 | 125 | 136 | 6 | +| 268 | 126 | 136 | 6 | ### 题目 @@ -185,6 +185,7 @@ |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | +|409 | 最长回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindrome/) | Easy | |412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | |413 | 等差数列划分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/arithmetic-slices.rs) | [leetcode](https://leetcode-cn.com/problems/arithmetic-slices/) | Medium | |415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | From f7db1f5172ca343b43d53056902f111315180277 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 4 Sep 2021 23:26:07 +0800 Subject: [PATCH 0094/1556] src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs --- ...-delete-getrandom-o1-duplicates-allowed.rs | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs diff --git a/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs b/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs new file mode 100644 index 00000000..e69654e7 --- /dev/null +++ b/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs @@ -0,0 +1,96 @@ +use rand::Rng; + +fn main() { + let mut r = RandomizedCollection::new(); + assert!(r.insert(1)); + assert!(!r.insert(1)); + assert!(r.insert(2)); + assert!(r.remove(1)); + println!("{}", r.get_random()); + println!("{}", r.get_random()); + println!("{}", r.get_random()); + println!("{}", rand::thread_rng().gen_range(0..10)); + println!("{}", rand::thread_rng().gen_range(0..10)); + println!("{}", rand::thread_rng().gen_range(0..10)); + println!("{}", rand::thread_rng().gen_range(0..10)); +} + +/** + * Your RandomizedCollection object will be instantiated and called as such: + * let obj = RandomizedCollection::new(); + * let ret_1: bool = obj.insert(val); + * let ret_2: bool = obj.remove(val); + * let ret_3: i32 = obj.get_random(); + */ +struct RandomizedCollection { + data: Vec, + indexes: std::collections::HashMap>, +} + + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl RandomizedCollection { + /** Initialize your data structure here. */ + fn new() -> Self { + Self { + data: Vec::new(), + indexes: std::collections::HashMap::new(), + } + } + + /** Inserts a value to the collection. Returns true if the collection did not already contain the specified element. */ + fn insert(&mut self, val: i32) -> bool { + let has = self.indexes.get(&val).is_some(); + self.data.push(val); + let index = self.data.len() - 1; + self.indexes.entry(val) + .and_modify(|i| { i.insert(index, ()); }) + .or_insert_with(|| { + let mut h = std::collections::HashMap::new(); + h.insert(index, ()); + h + }); + + !has + } + + /** Removes a value from the collection. Returns true if the collection contained the specified element. */ + fn remove(&mut self, val: i32) -> bool { + if self.indexes.get(&val).is_none() { return false; } + + let index = { + let i = *self.indexes.get(&val).unwrap().keys().next().unwrap(); + self.indexes.get_mut(&val).unwrap().remove(&i); + i + }; + let l = self.data.len() - 1; + let last = self.data[l]; + self.data.swap(index, l); + + if l != index { + self.indexes.entry(last).and_modify(|x| { + x.remove(&l); + x.insert(index, ()); + }); + } + + self.data.pop(); + + if self.indexes.get(&val).unwrap().is_empty() { + self.indexes.remove(&val); + } + + true + } + + /** Get a random element from the collection. */ + fn get_random(&self) -> i32 { + use rand::Rng; + let mut rng = rand::thread_rng(); + let index = rng.gen_range(0..self.data.len()); + self.data[index] + } +} From 5eadbad323febe59708749522edf8003a4c74a07 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 4 Sep 2021 23:26:07 +0800 Subject: [PATCH 0095/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bd9d803a..633b97e4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 268 | 126 | 136 | 6 | +| 269 | 126 | 136 | 7 | ### 题目 @@ -175,6 +175,7 @@ |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | |378 | 有序矩阵中第 K 小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-sorted-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/) | Medium | |380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | +|381 | O(1) 时间插入、删除和获取随机元素 - 允许重复 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed/) | Hard | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |384 | 打乱数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shuffle-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/shuffle-an-array/) | Medium | |386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | From f34d01d49631f27723af12ec7a7b87d970b64117 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 5 Sep 2021 23:10:50 +0800 Subject: [PATCH 0096/1556] src/bin/integer-replacement.rs --- src/bin/integer-replacement.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/integer-replacement.rs diff --git a/src/bin/integer-replacement.rs b/src/bin/integer-replacement.rs new file mode 100644 index 00000000..132279c7 --- /dev/null +++ b/src/bin/integer-replacement.rs @@ -0,0 +1,31 @@ +fn main() { + println!("{}", Solution::integer_replacement(2147483647)); +} + +struct Solution; + +impl Solution { + pub fn integer_replacement(n: i32) -> i32 { + let mut h = std::collections::HashMap::new(); + Self::f(n as i64, &mut h) as i32 + } + + fn f(n: i64, h: &mut std::collections::HashMap) -> i64 { + if n == 1 { + return 0; + } + + if let Some(x) = h.get(&n) { + return *x; + } + + let m = if n % 2 == 0 { + Self::f(n / 2, h) + 1 + } else { + Self::f(n - 1, h).min(Self::f(n + 1, h)) + 1 + }; + + h.insert(n, m); + m + } +} From 2b0bb54dcb79b3185ac551bf15b6023ac35bda15 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 5 Sep 2021 23:10:50 +0800 Subject: [PATCH 0097/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 633b97e4..d2166223 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 269 | 126 | 136 | 7 | +| 270 | 126 | 137 | 7 | ### 题目 @@ -183,6 +183,7 @@ |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | |392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | +|397 | 整数替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-replacement.rs) | [leetcode](https://leetcode-cn.com/problems/integer-replacement/) | Medium | |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | From 00a767ee7142bc9451cfa0a702d7d5bef2544dca Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 Sep 2021 22:50:53 +0800 Subject: [PATCH 0098/1556] src/bin/linked-list-random-node.rs --- src/bin/linked-list-random-node.rs | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/bin/linked-list-random-node.rs diff --git a/src/bin/linked-list-random-node.rs b/src/bin/linked-list-random-node.rs new file mode 100644 index 00000000..0a0d747b --- /dev/null +++ b/src/bin/linked-list-random-node.rs @@ -0,0 +1,59 @@ +use rand::Rng; + +fn main() {} + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { + next: None, + val, + } + } +} + +/** + * Your Solution object will be instantiated and called as such: + * let obj = Solution::new(head); + * let ret_1: i32 = obj.get_random(); + */ +struct Solution { + head: Option> +} + + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl Solution { + /** @param head The linked list's head. + Note that the head is guaranteed to be not null, so it contains at least one node. */ + fn new(head: Option>) -> Self { + Self { head } + } + + /** Returns a random node's value. */ + fn get_random(&self) -> i32 { + use rand::Rng; + let mut s = &self.head; + let mut n = 1; + let mut r = 0; + while let Some(x) = s { + if rand::thread_rng().gen_range(0..n) == 0 { + r = x.val; + } + + s = &x.next; + n += 1; + } + r + } +} From 16ef36f98b9694845043cf6f5f59b56a8321bd6b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 Sep 2021 22:50:53 +0800 Subject: [PATCH 0099/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d2166223..d3e4ea88 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 270 | 126 | 137 | 7 | +| 271 | 126 | 138 | 7 | ### 题目 @@ -176,6 +176,7 @@ |378 | 有序矩阵中第 K 小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-sorted-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/) | Medium | |380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | |381 | O(1) 时间插入、删除和获取随机元素 - 允许重复 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed/) | Hard | +|382 | 链表随机节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/linked-list-random-node.rs) | [leetcode](https://leetcode-cn.com/problems/linked-list-random-node/) | Medium | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |384 | 打乱数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shuffle-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/shuffle-an-array/) | Medium | |386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | From f0f0624ac10713a8b831d1c1ac6caf2bb5aec9b9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 7 Sep 2021 10:13:31 +0800 Subject: [PATCH 0100/1556] use stderr when error --- src/file.rs | 4 ++-- src/lib.rs | 7 ++++++- src/main.rs | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/file.rs b/src/file.rs index 25ba4f31..6591e983 100644 --- a/src/file.rs +++ b/src/file.rs @@ -21,7 +21,7 @@ pub fn write_readme(r: &mut Vec) { match std::fs::write("README.md", s) { Ok(_) => (), - Err(e) => println!("写入 README.md 失败,err{}", e.to_string()) + Err(e) => eprintln!("写入 README.md 失败,err{}", e.to_string()) } } @@ -41,7 +41,7 @@ pub fn get_all_bin_file() -> Vec { pub fn write_question(resp: Resp) { let file = format!("src/bin/{}.rs", resp.data.question.title_slug); if std::path::Path::new(file.as_str()).exists() { - println!("{} exists", file); + eprintln!("{} exists", file); return; } diff --git a/src/lib.rs b/src/lib.rs index 993a91c2..d4ee68e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,8 @@ mod all; use clap::{App, Arg}; +use std::process; + pub fn run() { let matches = App::new("leetcode") .version("0.0.1") @@ -24,7 +26,10 @@ pub fn run() { if let Some(matches) = matches.subcommand_matches("new") { match matches.value_of_t::("question_name") { Ok(x) => new::new(x), - Err(_) => println!("please input the name of question") + Err(_) => { + eprintln!("please input the name of question"); + process::exit(1); + } } } else if matches.subcommand_matches("all").is_some() { all::all(); diff --git a/src/main.rs b/src/main.rs index 449447a2..68ec8695 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,3 @@ fn main() { - leetcode::run() + leetcode::run(); } From 7ed425ef3084c5a6fe0079a2dbce29aa0818186c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 8 Sep 2021 10:54:22 +0800 Subject: [PATCH 0101/1556] src/bin/utf-8-validation.rs --- src/bin/utf-8-validation.rs | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/bin/utf-8-validation.rs diff --git a/src/bin/utf-8-validation.rs b/src/bin/utf-8-validation.rs new file mode 100644 index 00000000..2bb5f5b5 --- /dev/null +++ b/src/bin/utf-8-validation.rs @@ -0,0 +1,46 @@ +fn main() { + assert!(Solution::valid_utf8(vec![197, 130, 1])); + assert!(!Solution::valid_utf8(vec![235, 140, 4])); + assert!(Solution::valid_utf8(vec![197, 130, 1])); + assert!(!Solution::valid_utf8(vec![248, 130, 130, 130])); +} + +struct Solution; + +impl Solution { + pub fn valid_utf8(data: Vec) -> bool { + let mut index = 0; + while index < data.len() { + let n = if data[index] & 248 == 240 { + 4 + } else if data[index] & 240 == 224 { + 3 + } else if data[index] & 224 == 192 { + 2 + } else if data[index] & 128 == 0 { + 1 + } else { + return false; + }; + + if index + n > data.len() || !Self::check(&data[index..index + n]) { + return false; + } + + index += n; + } + + index == data.len() + } + + /// 检查除第一位的后几位是否都是10开头的 + fn check(data: &[i32]) -> bool { + for &i in data.iter().skip(1) { + if i & 0b11000000 != 0b10000000 { + return false; + } + } + + true + } +} From 2dea26ca12caf4bb4848ecc5d7dd91ff51850491 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 8 Sep 2021 10:54:23 +0800 Subject: [PATCH 0102/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d3e4ea88..1f05d4e5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 271 | 126 | 138 | 7 | +| 272 | 126 | 139 | 7 | ### 题目 @@ -184,6 +184,7 @@ |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | |392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | +|393 | UTF-8 编码验证 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/utf-8-validation.rs) | [leetcode](https://leetcode-cn.com/problems/utf-8-validation/) | Medium | |397 | 整数替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-replacement.rs) | [leetcode](https://leetcode-cn.com/problems/integer-replacement/) | Medium | |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | From 9a2abc2e4e0e89580d9ba7732c1518e8fb889d4d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 9 Sep 2021 23:59:46 +0800 Subject: [PATCH 0103/1556] src/bin/find-all-numbers-disappeared-in-an-array.rs --- .../find-all-numbers-disappeared-in-an-array.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/bin/find-all-numbers-disappeared-in-an-array.rs diff --git a/src/bin/find-all-numbers-disappeared-in-an-array.rs b/src/bin/find-all-numbers-disappeared-in-an-array.rs new file mode 100644 index 00000000..653d5b7d --- /dev/null +++ b/src/bin/find-all-numbers-disappeared-in-an-array.rs @@ -0,0 +1,16 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_disappeared_numbers(nums: Vec) -> Vec { + let mut s = std::collections::HashMap::new(); + + for &i in nums.iter() { + s.insert(i, ()); + } + + let mut v= vec![]; + for i in 1..=nums.len() {} + } +} From ef9c78da1c4801afd2a4aa4d27c711275ec7becd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 9 Sep 2021 23:59:47 +0800 Subject: [PATCH 0104/1556] README.md --- README.md | 3 ++- src/bin/find-all-numbers-disappeared-in-an-array.rs | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1f05d4e5..da962fb1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 272 | 126 | 139 | 7 | +| 273 | 127 | 139 | 7 | ### 题目 @@ -196,6 +196,7 @@ |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | +|448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | |476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | diff --git a/src/bin/find-all-numbers-disappeared-in-an-array.rs b/src/bin/find-all-numbers-disappeared-in-an-array.rs index 653d5b7d..c5c8b9aa 100644 --- a/src/bin/find-all-numbers-disappeared-in-an-array.rs +++ b/src/bin/find-all-numbers-disappeared-in-an-array.rs @@ -10,7 +10,13 @@ impl Solution { s.insert(i, ()); } - let mut v= vec![]; - for i in 1..=nums.len() {} + let mut v = vec![]; + for i in 1..=nums.len() as i32 { + if s.get(&i).is_none() { + v.push(i); + } + } + + v } } From 2b957c0df762026152e93f95da527750c931bdc4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 10 Sep 2021 10:42:47 +0800 Subject: [PATCH 0105/1556] update src/bin/find-all-numbers-disappeared-in-an-array.rs --- ...find-all-numbers-disappeared-in-an-array.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/bin/find-all-numbers-disappeared-in-an-array.rs b/src/bin/find-all-numbers-disappeared-in-an-array.rs index c5c8b9aa..601c6318 100644 --- a/src/bin/find-all-numbers-disappeared-in-an-array.rs +++ b/src/bin/find-all-numbers-disappeared-in-an-array.rs @@ -3,7 +3,7 @@ fn main() {} struct Solution; impl Solution { - pub fn find_disappeared_numbers(nums: Vec) -> Vec { + pub fn find_disappeared_numbers1(nums: Vec) -> Vec { let mut s = std::collections::HashMap::new(); for &i in nums.iter() { @@ -19,4 +19,20 @@ impl Solution { v } + + pub fn find_disappeared_numbers(nums: Vec) -> Vec { + let mut nums = nums; + let l = nums.len(); + for i in 0..l { + let v = nums[i] - 1; + nums[v as usize % l] += l as i32; + } + + nums + .into_iter() + .enumerate() + .filter(|&(_, x)| x <= (l as i32)) + .map(|x| x.0 as i32 + 1) + .collect() + } } From 64c6097822336bb7a767241b254b3a18c2241c8d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 13 Sep 2021 11:05:23 +0800 Subject: [PATCH 0106/1556] src/bin/nth-digit.rs --- src/bin/nth-digit.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/bin/nth-digit.rs diff --git a/src/bin/nth-digit.rs b/src/bin/nth-digit.rs new file mode 100644 index 00000000..f8e4e8cd --- /dev/null +++ b/src/bin/nth-digit.rs @@ -0,0 +1,48 @@ +fn main() { + println!("{}", Solution::find_nth_digit(1)); + println!("{}", Solution::find_nth_digit(2)); + println!("{}", Solution::find_nth_digit(10)); + println!("{}", Solution::find_nth_digit(11)); + println!("{}", Solution::find_nth_digit(12)); + println!("{}", Solution::find_nth_digit(13)); + println!("{}", Solution::find_nth_digit(14)); + println!("{}", Solution::find_nth_digit(190)); + println!("{}", Solution::find_nth_digit(191)); + println!("{}", Solution::find_nth_digit(192)); + println!("{}", Solution::find_nth_digit(193)); + println!("{}", Solution::find_nth_digit(312313)); + println!("{}", Solution::find_nth_digit(1000000000)); +} + +struct Solution; + +impl Solution { + /// 1.先找到n代表的数字有几位,规律:数字每增加一位,个数为:1*9 + 20*9 + 300*9... + pub fn find_nth_digit(n: i32) -> i32 { + if n <= 9 { + return n; + } + + let mut n = n; + + let mut s: i32 = 1; // n所在的数字有几位 + + loop { + let m = 9i64 * s as i64 * 10i64.pow(s as u32 - 1) as i64; + if (n as i64) < m { + break; + } else { + n -= m as i32; + s += 1; + } + } + + // 基于相同位数的最小值的偏移,比如1123相对于1000偏移123 + let n1 = n - 1; + + + let x = 10i32.pow(s as u32 - 1) + n1 / s; // 定位到具体的数字 + + x / 10i32.pow((s - n1 % s - 1) as u32) % 10 + } +} From 953e47c75c0c45986d30f6eb989c98d6c2b8c63d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 13 Sep 2021 11:05:24 +0800 Subject: [PATCH 0107/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da962fb1..d226f242 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 273 | 127 | 139 | 7 | +| 274 | 127 | 140 | 7 | ### 题目 @@ -188,6 +188,7 @@ |397 | 整数替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-replacement.rs) | [leetcode](https://leetcode-cn.com/problems/integer-replacement/) | Medium | |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | +|400 | 第 N 位数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nth-digit.rs) | [leetcode](https://leetcode-cn.com/problems/nth-digit/) | Medium | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |409 | 最长回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindrome/) | Easy | |412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | From aed249fada209933192360aa37016676a1ea4956 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 14 Sep 2021 22:44:45 +0800 Subject: [PATCH 0108/1556] src/bin/wiggle-subsequence.rs --- src/bin/wiggle-subsequence.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/wiggle-subsequence.rs diff --git a/src/bin/wiggle-subsequence.rs b/src/bin/wiggle-subsequence.rs new file mode 100644 index 00000000..b0e0133b --- /dev/null +++ b/src/bin/wiggle-subsequence.rs @@ -0,0 +1,24 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn wiggle_max_length(nums: Vec) -> i32 { + // 当长度小于等于2时,就可能为1或者2,结果取决与长度 + if nums.len() <= 1 { + return nums.len() as i32; + } + + let (mut down, mut up) = (1, 1); + + for i in 1..nums.len() { + if nums[i] > nums[i - 1] { + up = down + 1; + } else if nums[i] < nums[i - 1] { + down = up + 1; + } + } + + down.max(up) + } +} From bdabac76cb0a54bf6cd8f5658ef77aa754123ae0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 14 Sep 2021 22:44:46 +0800 Subject: [PATCH 0109/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d226f242..0742674e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 274 | 127 | 140 | 7 | +| 275 | 127 | 141 | 7 | ### 题目 @@ -173,6 +173,7 @@ |367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | |371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | +|376 | 摆动序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wiggle-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/wiggle-subsequence/) | Medium | |378 | 有序矩阵中第 K 小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-sorted-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/) | Medium | |380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | |381 | O(1) 时间插入、删除和获取随机元素 - 允许重复 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed/) | Hard | From 7c18a5e9a38d54b80abf6e9017dcd88140a1ec9c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 16 Sep 2021 23:57:06 +0800 Subject: [PATCH 0110/1556] src/bin/serialize-and-deserialize-bst.rs --- src/bin/serialize-and-deserialize-bst.rs | 89 ++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/bin/serialize-and-deserialize-bst.rs diff --git a/src/bin/serialize-and-deserialize-bst.rs b/src/bin/serialize-and-deserialize-bst.rs new file mode 100644 index 00000000..3e645ba5 --- /dev/null +++ b/src/bin/serialize-and-deserialize-bst.rs @@ -0,0 +1,89 @@ +fn main() {} + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::rc::Rc; +use std::cell::RefCell; + +/** + * Your Codec object will be instantiated and called as such: + * let obj = Codec::new(); + * let data: String = obj.serialize(strs); + * let ans: Option>> = obj.deserialize(data); + */ +struct Codec {} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl Codec { + fn new() -> Self { + Self {} + } + + /// 当为None是序列化为-1 + fn serialize(&self, root: Option>>) -> String { + let mut v = vec![root]; + let mut high = 0u32; + let mut index = 0usize; + let mut has_more = true; + let mut s = vec![]; + while has_more { + let mut i = 1i32; + has_more = false; + while i <= 2i32.pow(high) { + let mut x = v[index].take(); + if let Some(x) = x { + has_more = true; + s.push(x.borrow().val.to_string()); + v.push(x.borrow_mut().left.take()); + v.push(x.borrow_mut().right.take()); + } else { + s.push((-1).to_string()); + v.push(None); + v.push(None); + } + i += 1; + index += 1; + } + high += 1; + } + + s.join(",") + } + + fn deserialize(&self, data: String) -> Option>> { + let s = data.split(',').into_iter().map(|x| x.parse().unwrap()).collect::>(); + self.d(&s[..], 0) + } + + fn d(&self, v: &[i32], index: usize) -> Option>> { + if index >= v.len() || v[index] == -1 { + return None; + } + + let mut node = TreeNode::new(v[index]); + node.left = self.d(v, 2 * index + 1); + node.right = self.d(v, 2 * index + 2); + + Some(Rc::new(RefCell::new(node))) + } +} From 4e2b1a0048d788c9c41d5a2879db8deea8e4b027 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 16 Sep 2021 23:57:07 +0800 Subject: [PATCH 0111/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0742674e..948d1d62 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 275 | 127 | 141 | 7 | +| 276 | 127 | 142 | 7 | ### 题目 @@ -199,6 +199,7 @@ |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | |448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | +|449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | |476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | From 794a503c9bbbbaa59da5fe8b8f33f12a1c3b3b26 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 17 Sep 2021 23:48:59 +0800 Subject: [PATCH 0112/1556] src/bin/serialize-and-deserialize-bst.rs --- src/bin/serialize-and-deserialize-bst.rs | 68 +++++++++++++----------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/src/bin/serialize-and-deserialize-bst.rs b/src/bin/serialize-and-deserialize-bst.rs index 3e645ba5..6720c41a 100644 --- a/src/bin/serialize-and-deserialize-bst.rs +++ b/src/bin/serialize-and-deserialize-bst.rs @@ -41,48 +41,52 @@ impl Codec { /// 当为None是序列化为-1 fn serialize(&self, root: Option>>) -> String { - let mut v = vec![root]; - let mut high = 0u32; - let mut index = 0usize; - let mut has_more = true; - let mut s = vec![]; - while has_more { - let mut i = 1i32; - has_more = false; - while i <= 2i32.pow(high) { - let mut x = v[index].take(); - if let Some(x) = x { - has_more = true; - s.push(x.borrow().val.to_string()); - v.push(x.borrow_mut().left.take()); - v.push(x.borrow_mut().right.take()); - } else { - s.push((-1).to_string()); - v.push(None); - v.push(None); - } - i += 1; - index += 1; + match root { + Some(root) => { + let value = root.borrow().val; + let left = root.borrow_mut().left.take(); + let right = root.borrow_mut().right.take(); + format!( + "{},{},{}", + self.serialize(left), + value, + self.serialize(right), + ) } - high += 1; + None => "-1".to_string() } - - s.join(",") } fn deserialize(&self, data: String) -> Option>> { - let s = data.split(',').into_iter().map(|x| x.parse().unwrap()).collect::>(); - self.d(&s[..], 0) + println!("{:?}", data); + let s = data + .split(',') + .into_iter() + .map(|x| x.parse().unwrap()) + .collect::>(); + + self.f(&s[..], &mut 0) } - fn d(&self, v: &[i32], index: usize) -> Option>> { - if index >= v.len() || v[index] == -1 { + fn f(&self, data: &[i32], index: &mut usize) -> Option>> { + if data.len() <= *index || data[*index] == -1 { return None; } - let mut node = TreeNode::new(v[index]); - node.left = self.d(v, 2 * index + 1); - node.right = self.d(v, 2 * index + 2); + let mut node = TreeNode::new(data[*index]); + *index += 1; + if data[*index] != -1 { + node.left = self.f(data, index); + } else { + node.left = None; + } + + *index += 1; + if data[*index] != -1 { + node.right = self.f(data, index); + } else { + node.right = None; + } Some(Rc::new(RefCell::new(node))) } From 33c20d3a4dd3ee5e6efe624a495483fcb99656f1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 17 Sep 2021 23:48:59 +0800 Subject: [PATCH 0113/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 948d1d62..07f00709 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 276 | 127 | 142 | 7 | +| 277 | 127 | 143 | 7 | ### 题目 @@ -200,6 +200,7 @@ |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | |448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | |449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | +|449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | |476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | From 746ce28cd6f983e04faf336124114dbeacb44fc8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 19 Sep 2021 10:17:24 +0800 Subject: [PATCH 0114/1556] src/bin/add-two-numbers-ii.rs --- src/bin/add-two-numbers-ii.rs | 77 +++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/bin/add-two-numbers-ii.rs diff --git a/src/bin/add-two-numbers-ii.rs b/src/bin/add-two-numbers-ii.rs new file mode 100644 index 00000000..1ca56811 --- /dev/null +++ b/src/bin/add-two-numbers-ii.rs @@ -0,0 +1,77 @@ +use std::borrow::Borrow; + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { + next: None, + val, + } + } +} + +impl Solution { + pub fn add_two_numbers(l1: Option>, l2: Option>) -> Option> { + let (mut l1, mut l2) = (l1, l2); + let (mut v1, mut v2) = (vec![], vec![]); + + while l1.is_some() || l2.is_some() { + if let Some(mut x) = l1 { + v1.push(x.val); + l1 = x.next.take(); + } + + if let Some(mut x) = l2 { + v2.push(x.val); + l2 = x.next.take(); + } + } + + let mut i = 0; // 进制 + let mut new_node = None; + loop { + match (v1.pop(), v2.pop()) { + (Some(a), Some(b)) => { + let mut n = ListNode::new((a + b + i) % 10); + n.next = new_node.take(); + new_node = Some(Box::new(n)); + i = (a + b + i) / 10; + } + (Some(a), None) => { + let mut n = ListNode::new((a + i) % 10); + n.next = new_node.take(); + new_node = Some(Box::new(n)); + i = (a + i) / 10; + } + (None, Some(b)) => { + let mut n = ListNode::new((b + i) % 10); + n.next = new_node.take(); + new_node = Some(Box::new(n)); + i = (b + i) / 10; + } + + (None, None) => { + if i > 0 { + let mut n = ListNode::new(i); + n.next = new_node.take(); + new_node = Some(Box::new(n)); + } + break; + } + } + } + + new_node + } +} From 81ea6a0520b685113fcad6febdb9717ee40abfdb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 19 Sep 2021 10:17:24 +0800 Subject: [PATCH 0115/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 07f00709..f2fcd2ec 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 277 | 127 | 143 | 7 | +| 278 | 127 | 144 | 7 | ### 题目 @@ -198,6 +198,7 @@ |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | +|445 | 两数相加 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers-ii.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers-ii/) | Medium | |448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | |449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | |449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | From da32c9d8aa0fcd473710b9ef4bf317cb271d1fb4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 19 Sep 2021 23:52:53 +0800 Subject: [PATCH 0116/1556] style: cargo fmt the project --- src/all.rs | 3 +- src/bin/2-keys-keyboard.rs | 4 +- src/bin/add-digits.rs | 10 +++- src/bin/add-strings.rs | 10 ++-- src/bin/add-two-numbers-ii.rs | 10 ++-- src/bin/arithmetic-slices.rs | 27 +++++++--- src/bin/binary-tree-paths.rs | 44 ++++++++++------ src/bin/climbing-stairs.rs | 2 - src/bin/coin-change.rs | 4 +- src/bin/count-complete-tree-nodes.rs | 1 - src/bin/count-numbers-with-unique-digits.rs | 2 +- ...ind-all-numbers-disappeared-in-an-array.rs | 3 +- src/bin/first-bad-version.rs | 6 ++- ...-delete-getrandom-o1-duplicates-allowed.rs | 12 +++-- src/bin/insert-delete-getrandom-o1.rs | 1 - ...kth-smallest-element-in-a-sorted-matrix.rs | 2 +- src/bin/lexicographical-numbers.rs | 8 ++- src/bin/linked-list-random-node.rs | 10 ++-- src/bin/longest-increasing-subsequence.rs | 5 +- src/bin/longest-palindrome.rs | 17 +++++-- ...-substring-without-repeating-characters.rs | 2 - src/bin/maximum-population-year.rs | 6 +-- src/bin/missing-number.rs | 11 ++-- src/bin/nth-digit.rs | 5 +- src/bin/palindrome-linked-list.rs | 5 +- src/bin/random-pick-index.rs | 26 ++++------ src/bin/range-sum-query-immutable.rs | 4 +- src/bin/search-in-rotated-sorted-array.rs | 2 - src/bin/serialize-and-deserialize-bst.rs | 6 +-- src/bin/shuffle-an-array.rs | 1 - src/bin/summary-ranges.rs | 2 - src/file.rs | 50 +++++++++++-------- src/git.rs | 4 +- src/http.rs | 30 +++++++---- src/lib.rs | 21 ++++---- src/render.rs | 37 +++++++------- 36 files changed, 222 insertions(+), 171 deletions(-) diff --git a/src/all.rs b/src/all.rs index 31a783c2..5680c96d 100644 --- a/src/all.rs +++ b/src/all.rs @@ -1,9 +1,8 @@ use crate::file; +use crate::http::Resp; use std::sync::{Arc, Mutex}; use std::thread; -use crate::http::Resp; - /// 重新格式化 pub fn all() { diff --git a/src/bin/2-keys-keyboard.rs b/src/bin/2-keys-keyboard.rs index ca43d14e..1c8a7c8f 100644 --- a/src/bin/2-keys-keyboard.rs +++ b/src/bin/2-keys-keyboard.rs @@ -10,7 +10,9 @@ struct Solution; impl Solution { pub fn min_steps(mut n: i32) -> i32 { - if n == 1 { return 0; } + if n == 1 { + return 0; + } // 检查是否是质数 let mut count = 0; diff --git a/src/bin/add-digits.rs b/src/bin/add-digits.rs index 95cfe0c8..383505fa 100644 --- a/src/bin/add-digits.rs +++ b/src/bin/add-digits.rs @@ -25,6 +25,14 @@ impl Solution { /// 能够被9整除的整数,各位上的数字加起来也必然能被9整除,所以,连续累加起来,最终必然就是9。 /// 不能被9整除的整数,各位上的数字加起来,结果对9取模,和初始数对9取摸,是一样的,所以,连续累加起来,最终必然就是初始数对9取摸。 pub fn add_digits(num: i32) -> i32 { - if num % 9 == 0 { if num == 0 { 0 } else { 9 } } else { num % 9 } + if num % 9 == 0 { + if num == 0 { + 0 + } else { + 9 + } + } else { + num % 9 + } } } diff --git a/src/bin/add-strings.rs b/src/bin/add-strings.rs index 09f4a19e..5a61bd7e 100644 --- a/src/bin/add-strings.rs +++ b/src/bin/add-strings.rs @@ -44,9 +44,11 @@ impl Solution { v[vindex] = 1; } - v[vindex..].iter().fold(String::with_capacity((&v[vindex..]).len()), |mut x, y| { - x.push_str(&*y.to_string()); - x - }) + v[vindex..] + .iter() + .fold(String::with_capacity((&v[vindex..]).len()), |mut x, y| { + x.push_str(&*y.to_string()); + x + }) } } diff --git a/src/bin/add-two-numbers-ii.rs b/src/bin/add-two-numbers-ii.rs index 1ca56811..63aba2af 100644 --- a/src/bin/add-two-numbers-ii.rs +++ b/src/bin/add-two-numbers-ii.rs @@ -14,15 +14,15 @@ pub struct ListNode { impl ListNode { #[inline] fn new(val: i32) -> Self { - ListNode { - next: None, - val, - } + ListNode { next: None, val } } } impl Solution { - pub fn add_two_numbers(l1: Option>, l2: Option>) -> Option> { + pub fn add_two_numbers( + l1: Option>, + l2: Option>, + ) -> Option> { let (mut l1, mut l2) = (l1, l2); let (mut v1, mut v2) = (vec![], vec![]); diff --git a/src/bin/arithmetic-slices.rs b/src/bin/arithmetic-slices.rs index 6638d930..f4a1c5d2 100644 --- a/src/bin/arithmetic-slices.rs +++ b/src/bin/arithmetic-slices.rs @@ -1,14 +1,25 @@ fn main() { - println!("{}", Solution::number_of_arithmetic_slices(vec![1, 2, 3, 4])); - println!("{}", Solution::number_of_arithmetic_slices(vec![1, 2, 3, 4, 5, 6])); - println!("{}", Solution::number_of_arithmetic_slices(vec![1, 2, 3, 4, 10, 11, 12, 13])); + println!( + "{}", + Solution::number_of_arithmetic_slices(vec![1, 2, 3, 4]) + ); + println!( + "{}", + Solution::number_of_arithmetic_slices(vec![1, 2, 3, 4, 5, 6]) + ); + println!( + "{}", + Solution::number_of_arithmetic_slices(vec![1, 2, 3, 4, 10, 11, 12, 13]) + ); } struct Solution; impl Solution { pub fn number_of_arithmetic_slices(nums: Vec) -> i32 { - if nums.len() < 3 { return 0; } + if nums.len() < 3 { + return 0; + } let mut count = 0; let mut num = 2; @@ -18,13 +29,17 @@ impl Solution { if nums[i] - nums[i - 1] == s { num += 1; } else { - if num >= 3 { count += (1..=num - 3 + 1).into_iter().sum::(); } + if num >= 3 { + count += (1..=num - 3 + 1).into_iter().sum::(); + } s = nums[i] - nums[i - 1]; num = 2; } } - if num >= 3 { count += (1..=num - 3 + 1).into_iter().sum::(); } + if num >= 3 { + count += (1..=num - 3 + 1).into_iter().sum::(); + } count } diff --git a/src/bin/binary-tree-paths.rs b/src/bin/binary-tree-paths.rs index 652e97af..b3f2a562 100644 --- a/src/bin/binary-tree-paths.rs +++ b/src/bin/binary-tree-paths.rs @@ -21,13 +21,20 @@ impl TreeNode { } } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn binary_tree_paths(root: Option>>) -> Vec { let s = Self::f(root); - s.into_iter().map(|x| x.into_iter().map(|y| y.to_string()).collect::>().join("->")).collect() + s.into_iter() + .map(|x| { + x.into_iter() + .map(|y| y.to_string()) + .collect::>() + .join("->") + }) + .collect() } fn f(root: Option>>) -> Vec> { @@ -42,26 +49,33 @@ impl Solution { (Some(x), Some(y)) => { let f = Self::f(Some(x)); let r = Self::f(Some(y)); - f.into_iter().chain(r.into_iter()).map(|mut x| { - x.insert(0, v); - x - }).collect::>>() + f.into_iter() + .chain(r.into_iter()) + .map(|mut x| { + x.insert(0, v); + x + }) + .collect::>>() } (Some(x), None) => { let f = Self::f(Some(x)); - f.into_iter().map(|mut x| { - x.insert(0, v); - x - }).collect::>>() + f.into_iter() + .map(|mut x| { + x.insert(0, v); + x + }) + .collect::>>() } (None, Some(y)) => { let f = Self::f(Some(y)); - f.into_iter().map(|mut x| { - x.insert(0, v); - x - }).collect::>>() + f.into_iter() + .map(|mut x| { + x.insert(0, v); + x + }) + .collect::>>() } - (None, None) => vec![vec![v]] + (None, None) => vec![vec![v]], } } } diff --git a/src/bin/climbing-stairs.rs b/src/bin/climbing-stairs.rs index e9c3e658..e887afd8 100644 --- a/src/bin/climbing-stairs.rs +++ b/src/bin/climbing-stairs.rs @@ -1,5 +1,3 @@ - - fn main() {} struct Solution; diff --git a/src/bin/coin-change.rs b/src/bin/coin-change.rs index 1c2ff45b..4bb09c54 100644 --- a/src/bin/coin-change.rs +++ b/src/bin/coin-change.rs @@ -8,7 +8,9 @@ struct Solution; impl Solution { pub fn coin_change(coins: Vec, amount: i32) -> i32 { - if amount == 0 { return 0; } + if amount == 0 { + return 0; + } let mut h = std::collections::HashMap::new(); diff --git a/src/bin/count-complete-tree-nodes.rs b/src/bin/count-complete-tree-nodes.rs index c6a5e45f..d321065e 100644 --- a/src/bin/count-complete-tree-nodes.rs +++ b/src/bin/count-complete-tree-nodes.rs @@ -21,7 +21,6 @@ impl TreeNode { } } - use std::cell::RefCell; use std::rc::Rc; diff --git a/src/bin/count-numbers-with-unique-digits.rs b/src/bin/count-numbers-with-unique-digits.rs index cd5c4b62..f0d7ce3f 100644 --- a/src/bin/count-numbers-with-unique-digits.rs +++ b/src/bin/count-numbers-with-unique-digits.rs @@ -16,7 +16,7 @@ impl Solution { return 10; } - let mut sum =9; + let mut sum = 9; for i in 0..n - 1 { sum *= 9 - i; diff --git a/src/bin/find-all-numbers-disappeared-in-an-array.rs b/src/bin/find-all-numbers-disappeared-in-an-array.rs index 601c6318..445285c1 100644 --- a/src/bin/find-all-numbers-disappeared-in-an-array.rs +++ b/src/bin/find-all-numbers-disappeared-in-an-array.rs @@ -28,8 +28,7 @@ impl Solution { nums[v as usize % l] += l as i32; } - nums - .into_iter() + nums.into_iter() .enumerate() .filter(|&(_, x)| x <= (l as i32)) .map(|x| x.0 as i32 + 1) diff --git a/src/bin/first-bad-version.rs b/src/bin/first-bad-version.rs index d778940a..23990015 100644 --- a/src/bin/first-bad-version.rs +++ b/src/bin/first-bad-version.rs @@ -5,7 +5,7 @@ fn main() { } struct Solution { - n: i32 + n: i32, } // The API isBadVersion is defined for you. @@ -13,7 +13,9 @@ struct Solution { // to call it use self.isBadVersion(versions) impl Solution { - fn new(n: i32) -> Self { Self { n } } + fn new(n: i32) -> Self { + Self { n } + } pub fn first_bad_version(&self, n: i32) -> i32 { let mut good: i64 = 0; diff --git a/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs b/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs index e69654e7..c848dc29 100644 --- a/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs +++ b/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs @@ -27,7 +27,6 @@ struct RandomizedCollection { indexes: std::collections::HashMap>, } - /** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. @@ -46,8 +45,11 @@ impl RandomizedCollection { let has = self.indexes.get(&val).is_some(); self.data.push(val); let index = self.data.len() - 1; - self.indexes.entry(val) - .and_modify(|i| { i.insert(index, ()); }) + self.indexes + .entry(val) + .and_modify(|i| { + i.insert(index, ()); + }) .or_insert_with(|| { let mut h = std::collections::HashMap::new(); h.insert(index, ()); @@ -59,7 +61,9 @@ impl RandomizedCollection { /** Removes a value from the collection. Returns true if the collection contained the specified element. */ fn remove(&mut self, val: i32) -> bool { - if self.indexes.get(&val).is_none() { return false; } + if self.indexes.get(&val).is_none() { + return false; + } let index = { let i = *self.indexes.get(&val).unwrap().keys().next().unwrap(); diff --git a/src/bin/insert-delete-getrandom-o1.rs b/src/bin/insert-delete-getrandom-o1.rs index 15dd0a75..752c40dc 100644 --- a/src/bin/insert-delete-getrandom-o1.rs +++ b/src/bin/insert-delete-getrandom-o1.rs @@ -13,7 +13,6 @@ struct RandomizedSet { set: std::cell::RefCell>, } - /** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. diff --git a/src/bin/kth-smallest-element-in-a-sorted-matrix.rs b/src/bin/kth-smallest-element-in-a-sorted-matrix.rs index 30a62f30..654263e1 100644 --- a/src/bin/kth-smallest-element-in-a-sorted-matrix.rs +++ b/src/bin/kth-smallest-element-in-a-sorted-matrix.rs @@ -35,4 +35,4 @@ impl Solution { num } -} \ No newline at end of file +} diff --git a/src/bin/lexicographical-numbers.rs b/src/bin/lexicographical-numbers.rs index 8a55dee7..ffd7abc0 100644 --- a/src/bin/lexicographical-numbers.rs +++ b/src/bin/lexicographical-numbers.rs @@ -11,7 +11,9 @@ impl Solution { s.sort(); - s.into_iter().map(|x| x.parse::().unwrap()).collect::>() + s.into_iter() + .map(|x| x.parse::().unwrap()) + .collect::>() } pub fn lexical_order(n: i32) -> Vec { @@ -25,7 +27,9 @@ impl Solution { } fn dfs(v: &mut Vec, number: i32, n: i32) { - if number > n { return; } + if number > n { + return; + } let number = number * 10; diff --git a/src/bin/linked-list-random-node.rs b/src/bin/linked-list-random-node.rs index 0a0d747b..9dc9f8a7 100644 --- a/src/bin/linked-list-random-node.rs +++ b/src/bin/linked-list-random-node.rs @@ -12,10 +12,7 @@ pub struct ListNode { impl ListNode { #[inline] fn new(val: i32) -> Self { - ListNode { - next: None, - val, - } + ListNode { next: None, val } } } @@ -25,17 +22,16 @@ impl ListNode { * let ret_1: i32 = obj.get_random(); */ struct Solution { - head: Option> + head: Option>, } - /** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. */ impl Solution { /** @param head The linked list's head. - Note that the head is guaranteed to be not null, so it contains at least one node. */ + Note that the head is guaranteed to be not null, so it contains at least one node. */ fn new(head: Option>) -> Self { Self { head } } diff --git a/src/bin/longest-increasing-subsequence.rs b/src/bin/longest-increasing-subsequence.rs index d3564bc4..dea8a05e 100644 --- a/src/bin/longest-increasing-subsequence.rs +++ b/src/bin/longest-increasing-subsequence.rs @@ -1,5 +1,8 @@ fn main() { - println!("{}", Solution::length_of_lis(vec![10, 9, 2, 5, 3, 7, 101, 18])); + println!( + "{}", + Solution::length_of_lis(vec![10, 9, 2, 5, 3, 7, 101, 18]) + ); println!("{}", Solution::length_of_lis(vec![0, 1, 0, 3, 2, 3])); println!("{}", Solution::length_of_lis(vec![7, 7, 7, 7, 7, 7, 7])); } diff --git a/src/bin/longest-palindrome.rs b/src/bin/longest-palindrome.rs index e6d74c4e..99615d84 100644 --- a/src/bin/longest-palindrome.rs +++ b/src/bin/longest-palindrome.rs @@ -13,12 +13,19 @@ impl Solution { let mut r = 0; - hash.into_iter().for_each(|(_, v)| if v % 2 == 0 { r += v; } else { - odd = true; - r += v - 1; + hash.into_iter().for_each(|(_, v)| { + if v % 2 == 0 { + r += v; + } else { + odd = true; + r += v - 1; + } }); - - if odd { r + 1 } else { r } + if odd { + r + 1 + } else { + r + } } } diff --git a/src/bin/longest-substring-without-repeating-characters.rs b/src/bin/longest-substring-without-repeating-characters.rs index 17074cb5..34be7735 100644 --- a/src/bin/longest-substring-without-repeating-characters.rs +++ b/src/bin/longest-substring-without-repeating-characters.rs @@ -1,5 +1,3 @@ - - fn main() { assert_eq!(2, Solution::length_of_longest_substring("aab".to_string())); assert_eq!( diff --git a/src/bin/maximum-population-year.rs b/src/bin/maximum-population-year.rs index c6ac123d..6e6a7e71 100644 --- a/src/bin/maximum-population-year.rs +++ b/src/bin/maximum-population-year.rs @@ -15,11 +15,7 @@ impl Solution { let mut max = 0; for i in 1..v.len() { - max = if v[i] > v[max] { - i - } else { - max - } + max = if v[i] > v[max] { i } else { max } } max as i32 + 1950 diff --git a/src/bin/missing-number.rs b/src/bin/missing-number.rs index 2fd9b662..d770ba9d 100644 --- a/src/bin/missing-number.rs +++ b/src/bin/missing-number.rs @@ -1,6 +1,9 @@ fn main() { println!("{}", Solution::missing_number1(vec![3, 0, 1])); - println!("{}", Solution::missing_number1(vec![9, 6, 4, 2, 3, 5, 7, 0, 1])); + println!( + "{}", + Solution::missing_number1(vec![9, 6, 4, 2, 3, 5, 7, 0, 1]) + ); } struct Solution; @@ -12,8 +15,8 @@ impl Solution { pub fn missing_number1(nums: Vec) -> i32 { let l = nums.len() as i32; - nums.into_iter().enumerate().fold(l, |l, (x, y)| { - x as i32 ^ y ^ l - }) + nums.into_iter() + .enumerate() + .fold(l, |l, (x, y)| x as i32 ^ y ^ l) } } diff --git a/src/bin/nth-digit.rs b/src/bin/nth-digit.rs index f8e4e8cd..2a98c200 100644 --- a/src/bin/nth-digit.rs +++ b/src/bin/nth-digit.rs @@ -25,7 +25,7 @@ impl Solution { let mut n = n; - let mut s: i32 = 1; // n所在的数字有几位 + let mut s: i32 = 1; // n所在的数字有几位 loop { let m = 9i64 * s as i64 * 10i64.pow(s as u32 - 1) as i64; @@ -40,8 +40,7 @@ impl Solution { // 基于相同位数的最小值的偏移,比如1123相对于1000偏移123 let n1 = n - 1; - - let x = 10i32.pow(s as u32 - 1) + n1 / s; // 定位到具体的数字 + let x = 10i32.pow(s as u32 - 1) + n1 / s; // 定位到具体的数字 x / 10i32.pow((s - n1 % s - 1) as u32) % 10 } diff --git a/src/bin/palindrome-linked-list.rs b/src/bin/palindrome-linked-list.rs index 5fe6b1a3..e46b7a2b 100644 --- a/src/bin/palindrome-linked-list.rs +++ b/src/bin/palindrome-linked-list.rs @@ -12,10 +12,7 @@ pub struct ListNode { impl ListNode { #[inline] fn new(val: i32) -> Self { - ListNode { - next: None, - val, - } + ListNode { next: None, val } } } diff --git a/src/bin/random-pick-index.rs b/src/bin/random-pick-index.rs index eee616a2..e0fb5882 100644 --- a/src/bin/random-pick-index.rs +++ b/src/bin/random-pick-index.rs @@ -6,10 +6,9 @@ fn main() {} * let ret_1: i32 = obj.pick(target); */ struct Solution1 { - index_map: std::collections::HashMap> + index_map: std::collections::HashMap>, } - /** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. @@ -18,13 +17,12 @@ impl Solution1 { fn new(nums: Vec) -> Self { let mut index_map = std::collections::HashMap::new(); - nums - .into_iter() - .enumerate() - .for_each(|(index, value)| { - index_map.entry(value) - .and_modify(|y: &mut Vec| y.push(index)).or_insert(vec![index]); - }); + nums.into_iter().enumerate().for_each(|(index, value)| { + index_map + .entry(value) + .and_modify(|y: &mut Vec| y.push(index)) + .or_insert(vec![index]); + }); Self { index_map } } @@ -33,16 +31,14 @@ impl Solution1 { use rand::Rng; match self.index_map.get(&target) { - Some(x) => { - x[rand::thread_rng().gen_range(0..x.len())] as i32 - } - None => 0 + Some(x) => x[rand::thread_rng().gen_range(0..x.len())] as i32, + None => 0, } } } struct Solution { - nums: Vec + nums: Vec, } impl Solution { @@ -66,4 +62,4 @@ impl Solution { r } -} \ No newline at end of file +} diff --git a/src/bin/range-sum-query-immutable.rs b/src/bin/range-sum-query-immutable.rs index 80e321d0..995dda35 100644 --- a/src/bin/range-sum-query-immutable.rs +++ b/src/bin/range-sum-query-immutable.rs @@ -2,17 +2,15 @@ fn main() {} struct Solution; - /** * Your NumArray object will be instantiated and called as such: * let obj = NumArray::new(nums); * let ret_1: i32 = obj.sum_range(left, right); */ struct NumArray { - sums: Vec + sums: Vec, } - /** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. diff --git a/src/bin/search-in-rotated-sorted-array.rs b/src/bin/search-in-rotated-sorted-array.rs index 469d17ee..c339cce4 100644 --- a/src/bin/search-in-rotated-sorted-array.rs +++ b/src/bin/search-in-rotated-sorted-array.rs @@ -1,5 +1,3 @@ - - fn main() { assert_eq!(4, Solution::search(vec![4, 5, 6, 7, 8, 1, 2, 3], 8)); assert_eq!(-1, Solution::search(vec![1, 3], 0)); diff --git a/src/bin/serialize-and-deserialize-bst.rs b/src/bin/serialize-and-deserialize-bst.rs index 6720c41a..d9c6ad9e 100644 --- a/src/bin/serialize-and-deserialize-bst.rs +++ b/src/bin/serialize-and-deserialize-bst.rs @@ -19,8 +19,8 @@ impl TreeNode { } } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; /** * Your Codec object will be instantiated and called as such: @@ -30,7 +30,7 @@ use std::cell::RefCell; */ struct Codec {} -/** +/** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. */ @@ -53,7 +53,7 @@ impl Codec { self.serialize(right), ) } - None => "-1".to_string() + None => "-1".to_string(), } } diff --git a/src/bin/shuffle-an-array.rs b/src/bin/shuffle-an-array.rs index 138a166c..e32bff34 100644 --- a/src/bin/shuffle-an-array.rs +++ b/src/bin/shuffle-an-array.rs @@ -10,7 +10,6 @@ struct Solution { nums: Vec, } - /** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. diff --git a/src/bin/summary-ranges.rs b/src/bin/summary-ranges.rs index 263dfb5e..f25fc2f0 100644 --- a/src/bin/summary-ranges.rs +++ b/src/bin/summary-ranges.rs @@ -1,5 +1,3 @@ - - fn main() { println!("{:?}", Solution::summary_ranges(vec![0, 1, 2, 4, 5, 7])); } diff --git a/src/file.rs b/src/file.rs index 6591e983..b9e1984a 100644 --- a/src/file.rs +++ b/src/file.rs @@ -1,13 +1,15 @@ -use std::fs::{self, File}; -use std::io::Write; use lazy_static::lazy_static; use regex::Regex; +use std::fs::{self, File}; +use std::io::Write; -use crate::http::{Resp, Data, Ques, Difficulty}; +use crate::http::{Data, Difficulty, Ques, Resp}; -lazy_static!( - static ref RE: Regex = Regex::new(r"\|\s*([0-9]*)\s*\|\s*(.*?)\s*\|.*?bin/(.*?)\.rs.*?\|.*?\|\s*?(\w*)\s*?\|").unwrap(); -); +lazy_static! { + static ref RE: Regex = + Regex::new(r"\|\s*([0-9]*)\s*\|\s*(.*?)\s*\|.*?bin/(.*?)\.rs.*?\|.*?\|\s*?(\w*)\s*?\|") + .unwrap(); +}; /// 将结果写入README.md中 pub fn write_readme(r: &mut Vec) { @@ -21,22 +23,25 @@ pub fn write_readme(r: &mut Vec) { match std::fs::write("README.md", s) { Ok(_) => (), - Err(e) => eprintln!("写入 README.md 失败,err{}", e.to_string()) + Err(e) => eprintln!("写入 README.md 失败,err{}", e.to_string()), } } /// 获取 src/bin 目录下所有文件的名称 pub fn get_all_bin_file() -> Vec { let dir = fs::read_dir("src/bin/").unwrap(); - dir. - into_iter(). - map(|x| { - x.unwrap().file_name().to_str().unwrap().trim_end_matches(".rs").to_string() - }). - collect() + dir.into_iter() + .map(|x| { + x.unwrap() + .file_name() + .to_str() + .unwrap() + .trim_end_matches(".rs") + .to_string() + }) + .collect() } - /// 创建 bin/{quest_name}.rs 文件 pub fn write_question(resp: Resp) { let file = format!("src/bin/{}.rs", resp.data.question.title_slug); @@ -78,7 +83,7 @@ fn parse(contents: &str) -> Vec { title_slug: i.get(3).unwrap().as_str().to_string(), code_snippets: vec![], difficulty: Difficulty::new(i.get(4).unwrap().as_str()), - } + }, }, }) } @@ -89,7 +94,7 @@ fn parse(contents: &str) -> Vec { #[cfg(test)] mod tests { - use crate::file::{parse, get_all_bin_file}; + use crate::file::{get_all_bin_file, parse}; #[test] fn test_parse_readme() { @@ -99,11 +104,12 @@ mod tests { println!("{}", x.len()); for i in x { - println!("{}, {}, {}, {:?}", - i.data.question.translated_title, - i.data.question.question_id, - i.data.question.title_slug, - i.data.question.difficulty + println!( + "{}, {}, {}, {:?}", + i.data.question.translated_title, + i.data.question.question_id, + i.data.question.title_slug, + i.data.question.difficulty ); } } @@ -112,4 +118,4 @@ mod tests { fn test_get_all_bin_file() { println!("{:?}", get_all_bin_file()); } -} \ No newline at end of file +} diff --git a/src/git.rs b/src/git.rs index fb9591b8..ef446c82 100644 --- a/src/git.rs +++ b/src/git.rs @@ -19,7 +19,6 @@ pub fn push() { push_to_origin(); } - fn get_uncommit_files() -> Vec { let mut options = StatusOptions::new(); options.pathspec("src/bin"); @@ -50,7 +49,6 @@ pub fn push_to_origin() { println!("{}", String::from_utf8(output.stdout).unwrap()); } - #[cfg(test)] mod tests { use crate::git::get_uncommit_files; @@ -59,4 +57,4 @@ mod tests { fn test_get_uncommit_files() { println!("{:?}", get_uncommit_files()); } -} \ No newline at end of file +} diff --git a/src/http.rs b/src/http.rs index cdcfcb2a..06184190 100644 --- a/src/http.rs +++ b/src/http.rs @@ -1,12 +1,11 @@ use lazy_static::lazy_static; use regex::Regex; use reqwest::blocking::Client; -use serde::{Serialize, Deserialize, Serializer, Deserializer}; use serde::de::{Error, Visitor}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::fmt; - lazy_static! { static ref RE: Regex = Regex::new(r".*?/problems/(.*?)/").unwrap(); } @@ -26,15 +25,15 @@ impl Difficulty { "Easy" => Self::Easy, "Medium" => Self::Medium, "Hard" => Self::Hard, - _ => Self::Easy + _ => Self::Easy, } } } impl Serialize for Difficulty { fn serialize(&self, serializer: S) -> Result - where - S: Serializer + where + S: Serializer, { match self { Self::Easy => serializer.serialize_str("Easy"), @@ -54,8 +53,8 @@ impl<'de> Visitor<'de> for DifficultyVisitor { } fn visit_str(self, v: &str) -> Result - where - E: Error, + where + E: Error, { match v { "Easy" => Ok(Self::Value::Easy), @@ -68,8 +67,8 @@ impl<'de> Visitor<'de> for DifficultyVisitor { impl<'de> Deserialize<'de> for Difficulty { fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de> + where + D: Deserializer<'de>, { deserializer.deserialize_str(DifficultyVisitor) } @@ -113,7 +112,13 @@ pub struct Resp { pub fn get_question_info(mut ques: &str) -> Resp { if ques.starts_with("http") { - ques = RE.captures_iter(ques).next().unwrap().get(1).unwrap().as_str(); + ques = RE + .captures_iter(ques) + .next() + .unwrap() + .get(1) + .unwrap() + .as_str(); } let data_fmt = r#"{"operationName":"questionData","variables":{"titleSlug":"{}"}, @@ -138,6 +143,9 @@ mod tests { #[test] fn test_get_question_info() { println!("{:?}", get_question_info("container-with-most-water")); - println!("{:?}", get_question_info("https://leetcode-cn.com/problems/container-with-most-water/")); + println!( + "{:?}", + get_question_info("https://leetcode-cn.com/problems/container-with-most-water/") + ); } } diff --git a/src/lib.rs b/src/lib.rs index d4ee68e1..51c70da9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,9 @@ -mod new; -mod http; +mod all; mod file; mod git; +mod http; +mod new; mod render; -mod all; use clap::{App, Arg}; @@ -14,13 +14,14 @@ pub fn run() { .version("0.0.1") .author("bestgopher <84328409@qq.com>") .about("a helper for leetcode") - .subcommand(App::new("new") - .about("get a new leetcode question") - .arg(Arg::new("question_name") - .about("The configuration file to use") - .index(1))) - .subcommand(App::new("all") - .about("get all questions' info and rewrite README.md")) + .subcommand( + App::new("new").about("get a new leetcode question").arg( + Arg::new("question_name") + .about("The configuration file to use") + .index(1), + ), + ) + .subcommand(App::new("all").about("get all questions' info and rewrite README.md")) .get_matches(); if let Some(matches) = matches.subcommand_matches("new") { diff --git a/src/render.rs b/src/render.rs index 55abb3f5..6dfb1fe7 100644 --- a/src/render.rs +++ b/src/render.rs @@ -1,5 +1,5 @@ use lazy_static::lazy_static; -use tera::{Tera, Context, Result as TeraResult}; +use tera::{Context, Result as TeraResult, Tera}; /// 模板内容 const TEMPLATE_STR: &str = r"# leetcode @@ -27,14 +27,19 @@ lazy_static!( }; ); - /// 把传入的内容渲染为模板内容 pub fn render(data: &[crate::http::Resp]) -> TeraResult { let mut ctx = Context::new(); - let easy_num = counter(data, |x| x.data.question.difficulty == crate::http::Difficulty::Easy); - let medium_num = counter(data, |x| x.data.question.difficulty == crate::http::Difficulty::Medium); - let hard_num = counter(data, |x| x.data.question.difficulty == crate::http::Difficulty::Hard); + let easy_num = counter(data, |x| { + x.data.question.difficulty == crate::http::Difficulty::Easy + }); + let medium_num = counter(data, |x| { + x.data.question.difficulty == crate::http::Difficulty::Medium + }); + let hard_num = counter(data, |x| { + x.data.question.difficulty == crate::http::Difficulty::Hard + }); ctx.insert("datas", data); ctx.insert("easy_num", &easy_num); @@ -50,24 +55,22 @@ fn counter(data: &[crate::http::Resp], f: impl FnMut(&&crate::http::Resp) -> boo #[cfg(test)] mod tests { - use crate::http::{Resp, Ques, Data, Difficulty}; + use crate::http::{Data, Difficulty, Ques, Resp}; use crate::render::render; #[test] fn test_render() { - let data = vec![ - Resp { - data: Data { - question: Ques { - question_id: "111".to_string(), - title_slug: "aaa".to_string(), - translated_title: "中国".to_string(), - code_snippets: vec![], - difficulty: Difficulty::Easy, - } + let data = vec![Resp { + data: Data { + question: Ques { + question_id: "111".to_string(), + title_slug: "aaa".to_string(), + translated_title: "中国".to_string(), + code_snippets: vec![], + difficulty: Difficulty::Easy, }, }, - ]; + }]; println!("{:?}", render(&data).unwrap().to_string()); } From 13bf321052c7a21fa4d13910edca95ab67d66653 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 21 Sep 2021 10:28:40 +0800 Subject: [PATCH 0117/1556] src/bin/find-all-duplicates-in-an-array.rs --- src/bin/find-all-duplicates-in-an-array.rs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/find-all-duplicates-in-an-array.rs diff --git a/src/bin/find-all-duplicates-in-an-array.rs b/src/bin/find-all-duplicates-in-an-array.rs new file mode 100644 index 00000000..ef2f21a0 --- /dev/null +++ b/src/bin/find-all-duplicates-in-an-array.rs @@ -0,0 +1,24 @@ +fn main() { + println!("{:?}", Solution::find_duplicates(vec![4, 3, 2, 7, 8, 2, 3, 1])) +} + +struct Solution; + +impl Solution { + pub fn find_duplicates(nums: Vec) -> Vec { + let mut nums = nums; + let a = nums.len() + 1; + + for i in 0..nums.len() { + let index = (nums[i] as usize % a) - 1usize; + nums[index] += a as i32; + } + + nums + .into_iter() + .enumerate() + .filter(|&(i, x)| x / (a as i32) == 2) + .map(|(i, x)| i as i32 + 1) + .collect() + } +} From 827156edb8256f622e0ac18dd631e7f2601fa54f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 21 Sep 2021 10:28:41 +0800 Subject: [PATCH 0118/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f2fcd2ec..88d233cf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 278 | 127 | 144 | 7 | +| 279 | 127 | 145 | 7 | ### 题目 @@ -198,6 +198,7 @@ |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | +|442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | |445 | 两数相加 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers-ii.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers-ii/) | Medium | |448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | |449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | From 47a56b4057a188a258bacd26c2d70ddc4cec1d66 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 21 Sep 2021 10:29:16 +0800 Subject: [PATCH 0119/1556] style: format file --- src/file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file.rs b/src/file.rs index b9e1984a..5d8ca82e 100644 --- a/src/file.rs +++ b/src/file.rs @@ -9,7 +9,7 @@ lazy_static! { static ref RE: Regex = Regex::new(r"\|\s*([0-9]*)\s*\|\s*(.*?)\s*\|.*?bin/(.*?)\.rs.*?\|.*?\|\s*?(\w*)\s*?\|") .unwrap(); -}; +} /// 将结果写入README.md中 pub fn write_readme(r: &mut Vec) { From b22896c30ce4eb393653edb6158fbb0296205944 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 23 Sep 2021 21:08:27 +0800 Subject: [PATCH 0120/1556] src/bin/most-frequent-subtree-sum.rs --- src/bin/most-frequent-subtree-sum.rs | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/bin/most-frequent-subtree-sum.rs diff --git a/src/bin/most-frequent-subtree-sum.rs b/src/bin/most-frequent-subtree-sum.rs new file mode 100644 index 00000000..761a4fa9 --- /dev/null +++ b/src/bin/most-frequent-subtree-sum.rs @@ -0,0 +1,51 @@ +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::rc::Rc; +use std::cell::RefCell; + +impl Solution { + pub fn find_frequent_tree_sum(root: Option>>) -> Vec { + let mut root = root; + let mut h = std::collections::HashMap::new(); + let mut max = 0; + Self::get_sum(&mut root, &mut h, &mut max); + + h.iter().filter(|&(_, y)| *y == max).map(|(&x, _)| x).collect() + } + + fn get_sum(root: &mut Option>>, h: &mut std::collections::HashMap, max: &mut i32) { + if root.is_none() { return; } + + Self::get_sum(&mut root.as_mut().unwrap().borrow_mut().left, h, max); + Self::get_sum(&mut root.as_mut().unwrap().borrow_mut().right, h, max); + + let sum = root.as_ref().unwrap().borrow().left.as_ref().map_or(0, |x| x.borrow().val) + + root.as_ref().unwrap().borrow().right.as_ref().map_or(0, |x| x.borrow().val) + + root.as_ref().unwrap().borrow().val; + + root.as_mut().unwrap().borrow_mut().val = sum; + let count = h.entry(sum).and_modify(|x| *x += 1).or_insert(1); + *max = (*max).max(*count) + } +} From c1a899a8da999745b74634218276b1d01e9714c3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 23 Sep 2021 21:08:29 +0800 Subject: [PATCH 0121/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 88d233cf..28713dbd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 279 | 127 | 145 | 7 | +| 280 | 127 | 146 | 7 | ### 题目 @@ -207,6 +207,7 @@ |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | +|508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | From 45466b5fe185c0249c33bfed223ba326593a450f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 24 Sep 2021 23:49:35 +0800 Subject: [PATCH 0122/1556] src/bin/jewels-and-stones.rs --- src/bin/jewels-and-stones.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/bin/jewels-and-stones.rs diff --git a/src/bin/jewels-and-stones.rs b/src/bin/jewels-and-stones.rs new file mode 100644 index 00000000..454223a9 --- /dev/null +++ b/src/bin/jewels-and-stones.rs @@ -0,0 +1,10 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn num_jewels_in_stones(jewels: String, stones: String) -> i32 { + let j = jewels.bytes().into_iter().collect::>(); + stones.bytes().into_iter().filter(|x| j.contains(x)).count() as i32 + } +} From b351309050b2ffa8e5cbfa2e4a8e45840c3d2488 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 24 Sep 2021 23:49:35 +0800 Subject: [PATCH 0123/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 28713dbd..9a545f3b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 280 | 127 | 146 | 7 | +| 281 | 128 | 146 | 7 | ### 题目 @@ -220,6 +220,7 @@ |653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | +|782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | From 4064969196b7253cbb28fecc45db215acf525c5e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 Sep 2021 21:51:03 +0800 Subject: [PATCH 0124/1556] src/bin/find-bottom-left-tree-value.rs --- src/bin/find-bottom-left-tree-value.rs | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/bin/find-bottom-left-tree-value.rs diff --git a/src/bin/find-bottom-left-tree-value.rs b/src/bin/find-bottom-left-tree-value.rs new file mode 100644 index 00000000..3123a60d --- /dev/null +++ b/src/bin/find-bottom-left-tree-value.rs @@ -0,0 +1,51 @@ +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::rc::Rc; +use std::cell::RefCell; + +impl Solution { + pub fn find_bottom_left_value(root: Option>>) -> i32 { + let mut stack = vec![root]; + let mut result = 0; + while !stack.is_empty() { + let mut new_stack = vec![]; + let mut flag = false; + for node in stack.into_iter() { + if let Some(x) = node { + if !flag { + result = x.borrow().val; + flag = true; + } + new_stack.push(x.borrow_mut().left.take()); + new_stack.push(x.borrow_mut().right.take()); + } + } + + stack = new_stack; + flag = false; + } + + result + } +} From fcf68847d582015c82e5f3164f6fe3f7555a5329 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 Sep 2021 21:51:03 +0800 Subject: [PATCH 0125/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a545f3b..38ccf790 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 281 | 128 | 146 | 7 | +| 282 | 128 | 147 | 7 | ### 题目 @@ -208,6 +208,7 @@ |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | |508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | +|513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | From dc0ef021c28b6aaa97aaad2a9fb61061af9a874c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 26 Sep 2021 21:03:37 +0800 Subject: [PATCH 0126/1556] src/bin/insert-into-a-binary-search-tree.rs --- src/bin/insert-into-a-binary-search-tree.rs | 44 +++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/bin/insert-into-a-binary-search-tree.rs diff --git a/src/bin/insert-into-a-binary-search-tree.rs b/src/bin/insert-into-a-binary-search-tree.rs new file mode 100644 index 00000000..c2346366 --- /dev/null +++ b/src/bin/insert-into-a-binary-search-tree.rs @@ -0,0 +1,44 @@ +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::rc::Rc; +use std::cell::RefCell; + +impl Solution { + pub fn insert_into_bst(root: Option>>, val: i32) -> Option>> { + if root.is_none() { + return Some(Rc::new(RefCell::new(TreeNode::new(val)))); + } + let v = root.as_ref().unwrap().borrow().val; + + if v > val { + let left = root.as_ref().unwrap().borrow_mut().left.take(); + root.as_ref().unwrap().borrow_mut().left = Self::insert_into_bst(left, val); + } else { + let right = root.as_ref().unwrap().borrow_mut().right.take(); + root.as_ref().unwrap().borrow_mut().right = Self::insert_into_bst(right, val); + } + + root + } +} \ No newline at end of file From e6799c7b007b0e4bfb3f22bfeef12e8d8cabfb37 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 26 Sep 2021 21:03:37 +0800 Subject: [PATCH 0127/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 38ccf790..df2b5c17 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 282 | 128 | 147 | 7 | +| 283 | 128 | 148 | 7 | ### 题目 @@ -222,6 +222,7 @@ |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | |782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | +|784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | From b3dcd3a41c603be32d282ccb4d6aab816e0a5f14 Mon Sep 17 00:00:00 2001 From: "DESKTOP-SQL335Q\\DELL" <123456@qq.com> Date: Mon, 27 Sep 2021 18:34:54 +0800 Subject: [PATCH 0128/1556] add .gitignore --- .gitignore | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index c9418364..723ef36f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1 @@ -# Generated by Cargo -# will have compiled files and executables -/target/ - -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -Cargo.lock - -# These are backup files generated by rustfmt -**/*.rs.bk - -leetcode.iml -.idea - - -#Added by cargo - -/target - - -#Added by cargo -# -#already existing elements were commented out - -#/target -#Cargo.lock +.idea \ No newline at end of file From c0c99ee312b605d47726e3c9f8713bebed9a1923 Mon Sep 17 00:00:00 2001 From: "DESKTOP-SQL335Q\\DELL" <123456@qq.com> Date: Tue, 28 Sep 2021 10:47:20 +0800 Subject: [PATCH 0129/1556] modify .gitignore --- .gitignore | 3 +- Cargo.lock | 1715 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1717 insertions(+), 1 deletion(-) create mode 100644 Cargo.lock diff --git a/.gitignore b/.gitignore index 723ef36f..6db043d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea \ No newline at end of file +.idea +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 00000000..bd397e9f --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1715 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding", + "byte-tools", + "byteorder", + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] + +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "memchr", +] + +[[package]] +name = "bumpalo" +version = "3.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538" + +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "cc" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" +dependencies = [ + "jobserver", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "winapi 0.3.9", +] + +[[package]] +name = "chrono-tz" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2554a3155fec064362507487171dcc4edc3df60cb10f3a1fb10ed8094822b120" +dependencies = [ + "chrono", + "parse-zoneinfo", +] + +[[package]] +name = "clap" +version = "3.0.0-beta.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcd70aa5597dbc42f7217a543f9ef2768b2ef823ba29036072d30e1d88e98406" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "indexmap", + "lazy_static", + "os_str_bytes", + "strsim", + "termcolor", + "textwrap", + "vec_map", +] + +[[package]] +name = "clap_derive" +version = "3.0.0-beta.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5bb0d655624a0b8770d1c178fb8ffcb1f91cc722cb08f451e3dc72465421ac" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "core-foundation" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" + +[[package]] +name = "crossbeam-utils" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +dependencies = [ + "cfg-if 1.0.0", + "lazy_static", +] + +[[package]] +name = "deunicode" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690" + +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "encoding_rs" +version = "0.8.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +dependencies = [ + "bitflags", + "fuchsia-zircon-sys", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" + +[[package]] +name = "futures-channel" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" + +[[package]] +name = "futures-io" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" + +[[package]] +name = "futures-sink" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" + +[[package]] +name = "futures-task" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" + +[[package]] +name = "futures-util" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" +dependencies = [ + "autocfg", + "futures-core", + "futures-io", + "futures-task", + "memchr", + "pin-project-lite 0.2.7", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +dependencies = [ + "typenum", +] + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi", +] + +[[package]] +name = "git2" +version = "0.13.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c1cbbfc9a1996c6af82c2b4caf828d2c653af4fcdbb0e5674cc966eee5a4197" +dependencies = [ + "bitflags", + "libc", + "libgit2-sys", + "log", + "openssl-probe", + "openssl-sys", + "url", +] + +[[package]] +name = "globset" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd" +dependencies = [ + "aho-corasick", + "bstr", + "fnv", + "log", + "regex", +] + +[[package]] +name = "globwalk" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" +dependencies = [ + "bitflags", + "ignore", + "walkdir", +] + +[[package]] +name = "h2" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" +dependencies = [ + "bytes 0.5.6", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", + "tracing-futures", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" +dependencies = [ + "bytes 1.1.0", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" +dependencies = [ + "bytes 0.5.6", + "http", +] + +[[package]] +name = "httparse" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" + +[[package]] +name = "httpdate" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" + +[[package]] +name = "humansize" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026" + +[[package]] +name = "hyper" +version = "0.13.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a6f157065790a3ed2f88679250419b5cdd96e714a0d65f7797fd337186e96bb" +dependencies = [ + "bytes 0.5.6", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed" +dependencies = [ + "bytes 0.5.6", + "hyper", + "native-tls", + "tokio", + "tokio-tls", +] + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ignore" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713f1b139373f96a2e0ce3ac931cd01ee973c3c5dd7c40c0c2efe96ad2b6751d" +dependencies = [ + "crossbeam-utils", + "globset", + "lazy_static", + "log", + "memchr", + "regex", + "same-file", + "thread_local", + "walkdir", + "winapi-util", +] + +[[package]] +name = "indexmap" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "iovec" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +dependencies = [ + "libc", +] + +[[package]] +name = "ipnet" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" + +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + +[[package]] +name = "jobserver" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" +dependencies = [ + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "leetcode" +version = "0.1.0" +dependencies = [ + "clap", + "git2", + "lazy_static", + "rand", + "regex", + "reqwest", + "serde", + "serde_json", + "tera", +] + +[[package]] +name = "libc" +version = "0.2.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" + +[[package]] +name = "libgit2-sys" +version = "0.12.23+1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29730a445bae719db3107078b46808cc45a5b7a6bae3f31272923af969453356" +dependencies = [ + "cc", + "libc", + "libssh2-sys", + "libz-sys", + "openssl-sys", + "pkg-config", +] + +[[package]] +name = "libssh2-sys" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0186af0d8f171ae6b9c4c90ec51898bad5d08a2d5e470903a50d9ad8959cbee" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "libz-sys" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de5435b8549c16d423ed0c03dbaafe57cf6c3344744f1242520d59c9d8ecec66" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mime_guess" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "mio" +version = "0.6.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" +dependencies = [ + "cfg-if 0.1.10", + "fuchsia-zircon", + "fuchsia-zircon-sys", + "iovec", + "kernel32-sys", + "libc", + "log", + "miow", + "net2", + "slab", + "winapi 0.2.8", +] + +[[package]] +name = "miow" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" +dependencies = [ + "kernel32-sys", + "net2", + "winapi 0.2.8", + "ws2_32-sys", +] + +[[package]] +name = "native-tls" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "net2" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" + +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + +[[package]] +name = "openssl" +version = "0.10.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d9facdb76fec0b73c406f125d44d86fdad818d66fef0531eec9233ca425ff4a" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-sys", +] + +[[package]] +name = "openssl-probe" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" + +[[package]] +name = "openssl-sys" +version = "0.9.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69df2d8dfc6ce3aaf44b40dec6f487d5a886516cf6879c49e98e0710f310a058" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "os_str_bytes" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6acbef58a60fe69ab50510a55bc8cdd4d6cf2283d27ad338f54cb52747a9cf2d" + +[[package]] +name = "parse-zoneinfo" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41" +dependencies = [ + "regex", +] + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + +[[package]] +name = "pest_derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" +dependencies = [ + "maplit", + "pest", + "sha-1", +] + +[[package]] +name = "pin-project" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" + +[[package]] +name = "pin-project-lite" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c9b1041b4387893b91ee6746cddfc28516aff326a3519fb2adf820932c5e6cb" + +[[package]] +name = "ppv-lite86" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", + "rand_hc", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" +dependencies = [ + "rand_core", +] + +[[package]] +name = "redox_syscall" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "reqwest" +version = "0.10.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0718f81a8e14c4dbb3b34cf23dc6aaf9ab8a0dfec160c534b3dbca1aaa21f47c" +dependencies = [ + "base64", + "bytes 0.5.6", + "encoding_rs", + "futures-core", + "futures-util", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "lazy_static", + "log", + "mime", + "mime_guess", + "native-tls", + "percent-encoding", + "pin-project-lite 0.2.7", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-tls", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi 0.3.9", +] + +[[package]] +name = "security-framework" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha-1" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" +dependencies = [ + "block-buffer", + "digest", + "fake-simd", + "opaque-debug", +] + +[[package]] +name = "slab" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" + +[[package]] +name = "slug" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373" +dependencies = [ + "deunicode", +] + +[[package]] +name = "socket2" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5239bc68e0fef57495900cfea4e8dc75596d9a319d7e16b1e0a440d24e6fe0a0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "tempfile" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "rand", + "redox_syscall", + "remove_dir_all", + "winapi 0.3.9", +] + +[[package]] +name = "tera" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf95b0d8a46da5fe3ea119394a6c7f1e745f9de359081641c99946e2bf55d4f2" +dependencies = [ + "chrono", + "chrono-tz", + "globwalk", + "humansize", + "lazy_static", + "percent-encoding", + "pest", + "pest_derive", + "rand", + "regex", + "serde", + "serde_json", + "slug", + "unic-segment", +] + +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "thread_local" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tinyvec" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tokio" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" +dependencies = [ + "bytes 0.5.6", + "fnv", + "futures-core", + "iovec", + "lazy_static", + "memchr", + "mio", + "num_cpus", + "pin-project-lite 0.1.12", + "slab", +] + +[[package]] +name = "tokio-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +dependencies = [ + "bytes 0.5.6", + "futures-core", + "futures-sink", + "log", + "pin-project-lite 0.1.12", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + +[[package]] +name = "tracing" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84f96e095c0c82419687c20ddf5cb3eadb61f4e1405923c9dc8e53a1adacbda8" +dependencies = [ + "cfg-if 1.0.0", + "log", + "pin-project-lite 0.2.7", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46125608c26121c81b0c6d693eab5a420e416da7e43c426d2e8f7df8da8a3acf" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "typenum" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" + +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + +[[package]] +name = "unic-char-property" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221" +dependencies = [ + "unic-char-range", +] + +[[package]] +name = "unic-char-range" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc" + +[[package]] +name = "unic-common" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc" + +[[package]] +name = "unic-segment" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4ed5d26be57f84f176157270c112ef57b86debac9cd21daaabbe56db0f88f23" +dependencies = [ + "unic-ucd-segment", +] + +[[package]] +name = "unic-ucd-segment" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2079c122a62205b421f499da10f3ee0f7697f012f55b675e002483c73ea34700" +dependencies = [ + "unic-char-property", + "unic-char-range", + "unic-ucd-version", +] + +[[package]] +name = "unic-ucd-version" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4" +dependencies = [ + "unic-common", +] + +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "246f4c42e67e7a4e3c6106ff716a5d067d4132a642840b242e357e468a2a0085" + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" + +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi 0.3.9", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "wasm-bindgen" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" +dependencies = [ + "cfg-if 1.0.0", + "serde", + "serde_json", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" + +[[package]] +name = "web-sys" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winreg" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" +dependencies = [ + "winapi 0.3.9", +] + +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] From c75ecd975e544c9dcc5d43d110a713a5826cefef Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 28 Sep 2021 10:51:19 +0800 Subject: [PATCH 0130/1556] modify .gitignore --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index c9418364..d2bc282d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,3 @@ leetcode.iml #Added by cargo # #already existing elements were commented out - -#/target -#Cargo.lock From 7eb5c77453273425f8cf2966492acd21929e1213 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 28 Sep 2021 18:53:00 +0800 Subject: [PATCH 0131/1556] src/bin/maximum-length-of-repeated-subarray.rs --- .../maximum-length-of-repeated-subarray.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/maximum-length-of-repeated-subarray.rs diff --git a/src/bin/maximum-length-of-repeated-subarray.rs b/src/bin/maximum-length-of-repeated-subarray.rs new file mode 100644 index 00000000..0395c45b --- /dev/null +++ b/src/bin/maximum-length-of-repeated-subarray.rs @@ -0,0 +1,24 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_length(nums1: Vec, nums2: Vec) -> i32 { + let mut v = vec![vec![0;nums1.len()]; nums2.len()]; + let mut res = 0; + for (i, &v1) in nums1.iter().enumerate() { + for (j, &v2) in nums2.iter().enumerate() { + if v1 == v2 { + v[j][i] = if j != 0 && i != 0 { + v[j - 1][i - 1] + 1 + } else { + 1 + }; + } + res = res.max(v[j][i]) + } + } + + res + } +} From d4149911249b9a6f174b108952b01ca7760e18ab Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 28 Sep 2021 18:53:01 +0800 Subject: [PATCH 0132/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index df2b5c17..ea8d9cb3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 283 | 128 | 148 | 7 | +| 284 | 128 | 149 | 7 | ### 题目 @@ -221,6 +221,7 @@ |653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | +|718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | |782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | |784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | From c4b67fcf19295920b4acb4b5001d4cb3c70ec682 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 1 Oct 2021 11:21:12 +0800 Subject: [PATCH 0133/1556] chore(.gitignore): add leetcode.iml --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 095261ce..c60432c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .idea /target - +leetcode.iml #Added by cargo # From 21eb4e9b7e9741cfdcb4067e17e20280924e450d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 2 Oct 2021 22:47:44 +0800 Subject: [PATCH 0134/1556] src/bin/find-largest-value-in-each-tree-row.rs --- .../find-largest-value-in-each-tree-row.rs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/bin/find-largest-value-in-each-tree-row.rs diff --git a/src/bin/find-largest-value-in-each-tree-row.rs b/src/bin/find-largest-value-in-each-tree-row.rs new file mode 100644 index 00000000..d8a6006f --- /dev/null +++ b/src/bin/find-largest-value-in-each-tree-row.rs @@ -0,0 +1,57 @@ +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::rc::Rc; +use std::cell::RefCell; + +impl Solution { + pub fn largest_values(root: Option>>) -> Vec { + if root.is_none() { return vec![]; } + let mut stack = vec![root]; + let mut result = vec![]; + while !stack.is_empty() { + let mut new = vec![]; + let mut r: Option = None; + while let Some(node) = stack.pop() { + if node.is_none() { + continue; + } + let v = node.as_ref().unwrap().borrow().val; + r = r.map_or(Option::from(v), |x| Option::from(x.max(v))); + if let Some(x) = node.as_ref().unwrap().borrow_mut().left.take() { + new.push(Some(x)); + } + + if let Some(x) = node.as_ref().unwrap().borrow_mut().right.take() { + new.push(Some(x)); + } + } + if r.is_some() { + result.push(r.unwrap()); + } + stack = new; + } + + result + } +} From 3cb98ee5162013dbadd4a4f1d5655c6f944b945a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 2 Oct 2021 22:47:45 +0800 Subject: [PATCH 0135/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ea8d9cb3..f358c1c9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 284 | 128 | 149 | 7 | +| 285 | 128 | 150 | 7 | ### 题目 @@ -209,6 +209,7 @@ |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | |508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | |513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | +|515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | From d4e5c5b9570978fe3da25c34b88fb9a8be74fd01 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 3 Oct 2021 08:00:39 +0800 Subject: [PATCH 0136/1556] src/bin/encode-and-decode-tinyurl.rs --- src/bin/encode-and-decode-tinyurl.rs | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/bin/encode-and-decode-tinyurl.rs diff --git a/src/bin/encode-and-decode-tinyurl.rs b/src/bin/encode-and-decode-tinyurl.rs new file mode 100644 index 00000000..b2f87327 --- /dev/null +++ b/src/bin/encode-and-decode-tinyurl.rs @@ -0,0 +1,38 @@ +fn main() {} + +struct Solution; + +/** + * Your Codec object will be instantiated and called as such: + * let obj = Codec::new(); + * let s: String = obj.encode(strs); + * let ans: VecVec = obj.decode(s); + */ +struct Codec { + hash: std::collections::HashMap::, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl Codec { + fn new() -> Self { + Self { hash: std::collections::HashMap::new() } + } + + // Encodes a URL to a shortened URL. + fn encode(&mut self, longURL: String) -> String { + let mut s = std::collections::hash_map::DefaultHasher::new(); + ::hash(&longURL, &mut s); + let hash_code = ::finish(&s); + self.hash.insert(hash_code, longURL); + format!("http://tinyurl.com/{}", hash_code) + } + + // Decodes a shortened URL to its original URL. + fn decode(&self, shortURL: String) -> String { + let hash_code = shortURL.trim_start_matches("http://tinyurl.com/").parse::().unwrap(); + self.hash.get(&hash_code).unwrap().to_string() + } +} From b55cde3aaf3e405268a44453a1f19450852b6563 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 3 Oct 2021 08:00:40 +0800 Subject: [PATCH 0137/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f358c1c9..d4b020cc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 285 | 128 | 150 | 7 | +| 286 | 128 | 151 | 7 | ### 题目 @@ -212,6 +212,7 @@ |515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | +|535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | |565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | From 312c618caa8aa03e74810dcd3f1f52d8691a70c2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 6 Oct 2021 20:35:18 +0800 Subject: [PATCH 0138/1556] src/bin/base-7.rs --- src/bin/base-7.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/base-7.rs diff --git a/src/bin/base-7.rs b/src/bin/base-7.rs new file mode 100644 index 00000000..5154b788 --- /dev/null +++ b/src/bin/base-7.rs @@ -0,0 +1,28 @@ +fn main() { + assert_eq!("202".to_string(), Solution::convert_to_base7(100)); + assert_eq!("-10".to_string(), Solution::convert_to_base7(-7)); +} + +struct Solution; + +impl Solution { + pub fn convert_to_base7(num: i32) -> String { + let (mut s, mut num) = (String::new(), num); + if num < 0 { + s.push('-'); + num *= -1; + } + let mut index = 1; + let mut s1 = 0; + while num > 0 { + s1 += (num % 7) * index; + + num /= 7; + index *= 10; + } + + s.push_str(s1.to_string().as_str()); + + s + } +} From e4b3fe8c0a51a3fe16f4d5e6605fb567918eb031 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 6 Oct 2021 20:35:19 +0800 Subject: [PATCH 0139/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d4b020cc..1513e914 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 286 | 128 | 151 | 7 | +| 287 | 129 | 151 | 7 | ### 题目 @@ -207,6 +207,7 @@ |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | +|504 | 七进制数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/base-7.rs) | [leetcode](https://leetcode-cn.com/problems/base-7/) | Easy | |508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | |513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | |515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | From 9e423980e0068ca4a315d92394a4f9eed5bc638b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 7 Oct 2021 22:40:55 +0800 Subject: [PATCH 0140/1556] src/bin/average-of-levels-in-binary-tree.rs --- src/bin/average-of-levels-in-binary-tree.rs | 65 +++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/bin/average-of-levels-in-binary-tree.rs diff --git a/src/bin/average-of-levels-in-binary-tree.rs b/src/bin/average-of-levels-in-binary-tree.rs new file mode 100644 index 00000000..21f88044 --- /dev/null +++ b/src/bin/average-of-levels-in-binary-tree.rs @@ -0,0 +1,65 @@ +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::rc::Rc; +use std::cell::RefCell; + +impl Solution { + pub fn average_of_levels(root: Option>>) -> Vec { + if root.is_none() { + return vec![]; + } + + let mut result = vec![]; + let mut stack = vec![root]; + + while !stack.is_empty() { + let mut s = vec![]; + let mut l = stack.len(); + let mut sum = 0; + + while let Some(v) = stack.pop() { + if v.is_none() { + continue; + } + + let v = v.unwrap(); + sum += v.borrow().val as i64; + let left = v.borrow_mut().left.take(); + if left.is_some() { + s.push(left); + } + + let right = v.borrow_mut().right.take(); + if right.is_some() { + s.push(right); + } + } + + result.push(sum as f64 / l as f64); + stack = s; + } + + result + } +} From 9fcc68b2a840b0371429fdbba50b00b3bea19b9f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 7 Oct 2021 22:40:56 +0800 Subject: [PATCH 0141/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1513e914..26ef5f89 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 287 | 129 | 151 | 7 | +| 288 | 130 | 151 | 7 | ### 题目 @@ -219,6 +219,7 @@ |565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | |594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | +|637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | |649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | |650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | |653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | From 0d817357a7f83dc5c90774c2ec8f1782091b7c44 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 8 Oct 2021 22:00:50 +0800 Subject: [PATCH 0142/1556] src/bin/design-circular-queue.rs --- src/bin/design-circular-queue.rs | 94 ++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/bin/design-circular-queue.rs diff --git a/src/bin/design-circular-queue.rs b/src/bin/design-circular-queue.rs new file mode 100644 index 00000000..a01797fb --- /dev/null +++ b/src/bin/design-circular-queue.rs @@ -0,0 +1,94 @@ +fn main() {} + +/** + * Your MyCircularQueue object will be instantiated and called as such: + * let obj = MyCircularQueue::new(k); + * let ret_1: bool = obj.en_queue(value); + * let ret_2: bool = obj.de_queue(); + * let ret_3: i32 = obj.front(); + * let ret_4: i32 = obj.rear(); + * let ret_5: bool = obj.is_empty(); + * let ret_6: bool = obj.is_full(); + */ +struct MyCircularQueue { + cap: usize, + start: usize, + end: usize, + len: usize, + data: Vec, +} + + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl MyCircularQueue { + fn new(k: i32) -> Self { + Self { + cap: k as usize, + len: 0, + start: 0, + end: 0, + data: vec![0; k as usize], + } + } + + fn en_queue(&mut self, value: i32) -> bool { + if self.is_full() { + return false; + } + self.len += 1; + self.data[self.start] = value; + + if self.start == self.cap - 1 { + self.start = 0; + } else { + self.start += 1; + } + + true + } + + fn de_queue(&mut self) -> bool { + if self.is_empty() { + return false; + } + + self.len -= 1; + + self.data[self.end] = 0; + + if self.end == self.cap - 1 { + self.end = 0; + } else { + self.end += 1; + } + + true + } + + fn front(&self) -> i32 { + if self.is_empty() { + return -1; + } + + self.data[self.end] + } + + fn rear(&self) -> i32 { + if self.is_empty() { + return -1; + } + + self.data[if self.start == 0 { self.cap - 1 } else { self.start - 1 }] + } + + fn is_empty(&self) -> bool { + self.len == 0 + } + + fn is_full(&self) -> bool { + self.len == self.cap + } +} From 5fb6938b3041f66caf93f5b48524153c4708e5af Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 8 Oct 2021 22:00:51 +0800 Subject: [PATCH 0143/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 26ef5f89..a50c2893 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 288 | 130 | 151 | 7 | +| 289 | 130 | 152 | 7 | ### 题目 @@ -232,6 +232,7 @@ |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | +|860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | |917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | |921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | From 92b3a1c367b7157db7c5b148a170e3f4615c694d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 10 Oct 2021 22:43:51 +0800 Subject: [PATCH 0144/1556] src/bin/add-one-row-to-tree.rs --- src/bin/add-one-row-to-tree.rs | 59 ++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/bin/add-one-row-to-tree.rs diff --git a/src/bin/add-one-row-to-tree.rs b/src/bin/add-one-row-to-tree.rs new file mode 100644 index 00000000..53736192 --- /dev/null +++ b/src/bin/add-one-row-to-tree.rs @@ -0,0 +1,59 @@ +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::rc::Rc; +use std::cell::RefCell; + +impl Solution { + pub fn add_one_row(root: Option>>, val: i32, depth: i32) -> Option>> { + Self::add(root, val, depth, true) + } + + fn add(root: Option>>, val: i32, depth: i32, is_left: bool) -> Option>> { + if depth == 1 { + let mut node = TreeNode::new(val); + if is_left { + node.left = root; + } else { + node.right = root; + } + Some(Rc::new(RefCell::new(node))) + } else { + + if root.is_none() { + return None; + } + + let left = root.as_ref().unwrap().borrow_mut().left.take(); + let left = Self::add(left, val, depth - 1, true); + + let right = root.as_ref().unwrap().borrow_mut().right.take(); + let right = Self::add(right, val, depth - 1, false); + + root.as_ref().unwrap().borrow_mut().left = left; + root.as_ref().unwrap().borrow_mut().right = right; + + root + } + } +} From f89d5c9efb9c1d8a1125e93e98fd5be5e0e78a04 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 10 Oct 2021 22:43:52 +0800 Subject: [PATCH 0145/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a50c2893..4f17869a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 289 | 130 | 152 | 7 | +| 290 | 130 | 153 | 7 | ### 题目 @@ -219,6 +219,7 @@ |565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | |594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | +|623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | |637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | |649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | |650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | From e3d21f3a97a7f7f6204c2d97c82447074ef70c53 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Oct 2021 18:28:06 +0800 Subject: [PATCH 0146/1556] src/bin/can-place-flowers.rs --- src/bin/can-place-flowers.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/can-place-flowers.rs diff --git a/src/bin/can-place-flowers.rs b/src/bin/can-place-flowers.rs new file mode 100644 index 00000000..05822368 --- /dev/null +++ b/src/bin/can-place-flowers.rs @@ -0,0 +1,35 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn can_place_flowers(flowerbed: Vec, n: i32) -> bool { + let mut f = flowerbed; + let mut n = n; + + for i in 0..f.len() { + if i == 0 { + if f[i] == 0 && f.get(i + 1).unwrap_or(&0) == &0 { + f[i] = 1; + n -= 1; + } + } else if i == f.len() - 1 { + if f[i] == 0 && f.get(i - 1).unwrap_or(&0) == &0 { + f[i] = 1; + n -= 1; + } + } else { + if f[i] == 0 && f[i - 1] == 0 && f[i + 1] == 0 { + f[i] = 1; + n -= 1; + } + } + + if n <= 0 { + return true; + } + } + + false + } +} From c8d5623a6b25bce2a4e8d117e3f06b489c644ad3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Oct 2021 18:28:06 +0800 Subject: [PATCH 0147/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f17869a..f537d6d9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 290 | 130 | 153 | 7 | +| 291 | 131 | 153 | 7 | ### 题目 @@ -218,6 +218,7 @@ |560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | |565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | |594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | +|605 | 种花问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/can-place-flowers.rs) | [leetcode](https://leetcode-cn.com/problems/can-place-flowers/) | Easy | |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | |623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | |637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | From d2808950279b05785d45e35c22891c4f9540667a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 16 Oct 2021 23:08:54 +0800 Subject: [PATCH 0148/1556] src/bin/perfect-number.rs --- src/bin/perfect-number.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/bin/perfect-number.rs diff --git a/src/bin/perfect-number.rs b/src/bin/perfect-number.rs new file mode 100644 index 00000000..236b3492 --- /dev/null +++ b/src/bin/perfect-number.rs @@ -0,0 +1,9 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn check_perfect_number(num: i32) -> bool { + num == (1..=num / 2).into_iter().filter(|&x| num % x == 0).sum() + } +} From f07ab8de7c71fc0218bee281337ff98ef8a2419c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 16 Oct 2021 23:08:54 +0800 Subject: [PATCH 0149/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f537d6d9..1a9a80f6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 291 | 131 | 153 | 7 | +| 292 | 132 | 153 | 7 | ### 题目 @@ -208,6 +208,7 @@ |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | |504 | 七进制数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/base-7.rs) | [leetcode](https://leetcode-cn.com/problems/base-7/) | Easy | +|507 | 完美数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-number.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-number/) | Easy | |508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | |513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | |515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | From 34613c79ae57d9ecd4e6faac00fc437194fc2c65 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 17 Oct 2021 23:26:06 +0800 Subject: [PATCH 0150/1556] src/bin/maximum-average-subarray-i.rs --- src/bin/maximum-average-subarray-i.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/bin/maximum-average-subarray-i.rs diff --git a/src/bin/maximum-average-subarray-i.rs b/src/bin/maximum-average-subarray-i.rs new file mode 100644 index 00000000..c23e4a1b --- /dev/null +++ b/src/bin/maximum-average-subarray-i.rs @@ -0,0 +1,18 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_max_average(nums: Vec, k: i32) -> f64 { + let k = k as usize; + let mut sum = nums[0..k].iter().sum::(); + let mut argv = (sum as f64) / (k as f64); + + for i in k..nums.len() { + sum = sum + nums[i] - nums[i - k]; + argv = argv.max((sum as f64) / (k as f64)); + } + + argv + } +} From bd41821cea4be1a4f679172adc2705705d6e88bf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 17 Oct 2021 23:26:07 +0800 Subject: [PATCH 0151/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a9a80f6..c3c4158e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 292 | 132 | 153 | 7 | +| 293 | 133 | 153 | 7 | ### 题目 @@ -223,6 +223,7 @@ |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | |623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | |637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | +|643 | 子数组最大平均数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-average-subarray-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-average-subarray-i/) | Easy | |649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | |650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | |653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | From de2b1803eca65e4c4012c4f9610013a1badff5e4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 18 Oct 2021 23:01:57 +0800 Subject: [PATCH 0152/1556] src/bin/robot-return-to-origin.rs --- src/bin/robot-return-to-origin.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/bin/robot-return-to-origin.rs diff --git a/src/bin/robot-return-to-origin.rs b/src/bin/robot-return-to-origin.rs new file mode 100644 index 00000000..f79b69b0 --- /dev/null +++ b/src/bin/robot-return-to-origin.rs @@ -0,0 +1,22 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn judge_circle(moves: String) -> bool { + let mut v = (0, 0); + + for i in moves.bytes() { + match i { + b'L' => v.0 -= 1, + b'R' => v.0 += 1, + b'U' => v.1 += 1, + b'D' => v.1 -= 1, + _ => {} + } + } + + + v == (0, 0) + } +} From b24afbdba1a71af0801c8e87a513c77b2c51d2da Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 18 Oct 2021 23:01:58 +0800 Subject: [PATCH 0153/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c3c4158e..5c0957ad 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 293 | 133 | 153 | 7 | +| 294 | 134 | 153 | 7 | ### 题目 @@ -227,6 +227,7 @@ |649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | |650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | |653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | +|657 | 机器人能否返回原点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-return-to-origin.rs) | [leetcode](https://leetcode-cn.com/problems/robot-return-to-origin/) | Easy | |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | |718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | From 6f51545b6ca68ba9205c84d28b1cfb7ea3507e31 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 19 Oct 2021 23:18:23 +0800 Subject: [PATCH 0154/1556] src/bin/search-in-a-binary-search-tree.rs --- src/bin/search-in-a-binary-search-tree.rs | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/bin/search-in-a-binary-search-tree.rs diff --git a/src/bin/search-in-a-binary-search-tree.rs b/src/bin/search-in-a-binary-search-tree.rs new file mode 100644 index 00000000..dd12ad6f --- /dev/null +++ b/src/bin/search-in-a-binary-search-tree.rs @@ -0,0 +1,41 @@ +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::rc::Rc; +use std::cell::RefCell; + +impl Solution { + pub fn search_bst(root: Option>>, val: i32) -> Option>> { + let mut root = root; + while let Some(r) = root { + let v = r.borrow().val; + match v.cmp(&val) { + std::cmp::Ordering::Equal => return Some(r), + std::cmp::Ordering::Greater => root = r.borrow_mut().left.take(), + std::cmp::Ordering::Less => root = r.borrow_mut().right.take(), + } + } + + None + } +} From 39769fc6753943a68208afe2f740bc3ab0f3ced7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 19 Oct 2021 23:18:24 +0800 Subject: [PATCH 0155/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c0957ad..014ba55c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 294 | 134 | 153 | 7 | +| 295 | 135 | 153 | 7 | ### 题目 @@ -232,6 +232,7 @@ |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | |718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | |782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | +|783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | |784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | From 5ca148c5c59dc2995972834d3288e3102c269d03 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 21 Oct 2021 23:58:34 +0800 Subject: [PATCH 0156/1556] src/bin/minimum-absolute-difference-in-bst.rs --- src/bin/minimum-absolute-difference-in-bst.rs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/bin/minimum-absolute-difference-in-bst.rs diff --git a/src/bin/minimum-absolute-difference-in-bst.rs b/src/bin/minimum-absolute-difference-in-bst.rs new file mode 100644 index 00000000..27e96049 --- /dev/null +++ b/src/bin/minimum-absolute-difference-in-bst.rs @@ -0,0 +1,38 @@ +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::rc::Rc; +use std::cell::RefCell; + +impl Solution { + pub fn get_minimum_difference(root: Option>>) -> i32 { + if root.is_none() { return std::i32::MAX; } + let v = root.as_ref().unwrap().borrow().val; + let left = root.as_ref().unwrap().borrow_mut().left.take(); + let right = root.as_ref().unwrap().borrow_mut().right.take(); + + let x = (left.as_ref().map_or(std::i32::MAX, |x| x.borrow().val) - v).abs(); + let x = x.min((right.as_ref().map_or(std::i32::MAX, |x| x.borrow().val) - v).abs()); + x.min(Self::get_minimum_difference(left)).min(Self::get_minimum_difference(right)) + } +} From 7891a692cedfacc2c78ea5c168752df6b6be87a7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 21 Oct 2021 23:58:35 +0800 Subject: [PATCH 0157/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 014ba55c..56274e7d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 295 | 135 | 153 | 7 | +| 296 | 136 | 153 | 7 | ### 题目 @@ -214,6 +214,7 @@ |515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | +|530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | |535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | From 56aae0f155e3b7dd452be2ef110444a70dcaa013 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 22 Oct 2021 00:04:56 +0800 Subject: [PATCH 0158/1556] src/bin/minimum-absolute-difference-in-bst.rs --- src/bin/minimum-absolute-difference-in-bst.rs | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/bin/minimum-absolute-difference-in-bst.rs b/src/bin/minimum-absolute-difference-in-bst.rs index 27e96049..415b3443 100644 --- a/src/bin/minimum-absolute-difference-in-bst.rs +++ b/src/bin/minimum-absolute-difference-in-bst.rs @@ -26,13 +26,29 @@ use std::cell::RefCell; impl Solution { pub fn get_minimum_difference(root: Option>>) -> i32 { - if root.is_none() { return std::i32::MAX; } - let v = root.as_ref().unwrap().borrow().val; - let left = root.as_ref().unwrap().borrow_mut().left.take(); - let right = root.as_ref().unwrap().borrow_mut().right.take(); - - let x = (left.as_ref().map_or(std::i32::MAX, |x| x.borrow().val) - v).abs(); - let x = x.min((right.as_ref().map_or(std::i32::MAX, |x| x.borrow().val) - v).abs()); - x.min(Self::get_minimum_difference(left)).min(Self::get_minimum_difference(right)) + let mut v = vec![]; + let mut stack = vec![root]; + + while let Some(x) = stack.pop() { + if let Some(y) = x { + v.push(y.borrow().val); + if let Some(z) = y.borrow_mut().left.take() { + stack.push(Some(z)); + } + if let Some(o) = y.borrow_mut().right.take() { + stack.push(Some(o)); + } + } + } + + v.sort(); + + let mut x = std::i32::MAX; + + for i in 1..v.len() { + x = x.min(v[i] - v[i - 1]); + } + + x } } From 557fd62f1d7f621670cc31ade6dff30b1cb2965d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 22 Oct 2021 00:04:57 +0800 Subject: [PATCH 0159/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 56274e7d..6674bf5f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 296 | 136 | 153 | 7 | +| 297 | 137 | 153 | 7 | ### 题目 @@ -215,6 +215,7 @@ |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | |530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | +|530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | |535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | From 893934a70c637a3ce676baac262425370958a474 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 25 Oct 2021 23:49:48 +0800 Subject: [PATCH 0160/1556] src/bin/reverse-prefix-of-word.rs --- src/bin/reverse-prefix-of-word.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/reverse-prefix-of-word.rs diff --git a/src/bin/reverse-prefix-of-word.rs b/src/bin/reverse-prefix-of-word.rs new file mode 100644 index 00000000..60343a5e --- /dev/null +++ b/src/bin/reverse-prefix-of-word.rs @@ -0,0 +1,27 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn reverse_prefix(word: String, ch: char) -> String { + let mut word = word; + let mut i = 0; + for (index, value) in word.chars().enumerate() { + if value == ch { + i = index; + } + } + + unsafe { + let mut s = word.as_bytes_mut(); + let mut j = 0; + while j < i { + s.swap(i, j); + i -= 1; + j += 1; + } + } + + word + } +} From 9e59a542e22c8bcf47d0551100a5c1a1aa66748d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 25 Oct 2021 23:49:49 +0800 Subject: [PATCH 0161/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6674bf5f..6c557ad2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 297 | 137 | 153 | 7 | +| 298 | 138 | 153 | 7 | ### 题目 @@ -293,6 +293,7 @@ |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | |1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | +|2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | From af75924aac5897df6c416d7106f3e59326b59c6d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 11 Dec 2021 13:37:17 +0800 Subject: [PATCH 0162/1556] src/bin/online-election.rs --- src/bin/online-election.rs | 89 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/bin/online-election.rs diff --git a/src/bin/online-election.rs b/src/bin/online-election.rs new file mode 100644 index 00000000..7be65526 --- /dev/null +++ b/src/bin/online-election.rs @@ -0,0 +1,89 @@ +fn main() { + let s = TopVotedCandidate::new(vec![0, 1, 1, 0, 0, 1, 0], vec![0, 5, 10, 15, 20, 25, 30]); + assert_eq!(s.q(3), 0); + assert_eq!(s.q(12), 1); + assert_eq!(s.q(25), 1); + assert_eq!(s.q(15), 0); + assert_eq!(s.q(24), 0); + assert_eq!(s.q(8), 1); + + let s = TopVotedCandidate::new(vec![0, 0, 0, 0, 1], vec![0, 6, 39, 52, 75]); + assert_eq!(s.q(45), 0); + assert_eq!(s.q(49), 0); + assert_eq!(s.q(59), 0); + assert_eq!(s.q(68), 0); + assert_eq!(s.q(42), 0); + assert_eq!(s.q(37), 0); + assert_eq!(s.q(99), 0); + assert_eq!(s.q(26), 0); + assert_eq!(s.q(78), 0); + assert_eq!(s.q(43), 0); +} + +/** + * Your TopVotedCandidate object will be instantiated and called as such: + * let obj = TopVotedCandidate::new(persons, times); + * let ret_1: i32 = obj.q(t); + */ +struct TopVotedCandidate { + count: Vec, + times: Vec, +} + + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl TopVotedCandidate { + fn new(persons: Vec, times: Vec) -> Self { + Self { + count: Self::build(persons), + times, + } + } + + fn q(&self, t: i32) -> i32 { + let (mut start, mut end) = (0usize, self.times.len() - 1); + let mut middle = (start + end) / 2; + // binary search + while start < end { + if self.times[middle] == t || middle == 0 || middle == self.times.len() - 1 { + break; + } else if self.times[middle] > t && self.times[middle - 1] < t { + middle -= 1; + break; + } else if self.times[middle] < t && self.times[middle + 1] > t { + break; + } else if self.times[middle] > t { + end = middle; + middle = (start + end) / 2; + } else { + start = middle + 1; + middle = (start + end) / 2; + } + } + + self.count[middle] + } + + fn build(persons: Vec) -> Vec { + let mut v = Vec::with_capacity(persons.len()); + let mut counts = std::collections::HashMap::new(); + let mut max_count = 0; + let mut max_value = 0; + + for i in persons { + let c = counts.entry(i).and_modify(|x| *x += 1).or_insert(1); + if *c >= max_count { + v.push(i); + max_value = i; + max_count = *c; + } else { + v.push(max_value); + } + } + + v + } +} From 765e8de0eba0d90f063ce6c617a688472b081c60 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 11 Dec 2021 13:37:17 +0800 Subject: [PATCH 0163/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c557ad2..31ce2082 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 298 | 138 | 153 | 7 | +| 299 | 138 | 154 | 7 | ### 题目 @@ -247,6 +247,7 @@ |924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | |925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | +|947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | |981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | |982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Medium | From f4725ec4e414cb2dd1f129ce16501a3a9c76ec82 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 11 Dec 2021 13:38:34 +0800 Subject: [PATCH 0164/1556] update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c60432c0..cf782eb8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .idea /target leetcode.iml +.DS_Store #Added by cargo # From a842246f5d7a57847d60035f884384af09bed978 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 12 Dec 2021 10:23:25 +0800 Subject: [PATCH 0165/1556] src/bin/to-lower-case.rs --- src/bin/to-lower-case.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/bin/to-lower-case.rs diff --git a/src/bin/to-lower-case.rs b/src/bin/to-lower-case.rs new file mode 100644 index 00000000..d70d968b --- /dev/null +++ b/src/bin/to-lower-case.rs @@ -0,0 +1,19 @@ +use serde::de::Unexpected::Str; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn to_lower_case(s: String) -> String { + let mut new = Vec::with_capacity(s.len()); + s.bytes().into_iter().for_each(|mut x| { + if x >= b'A' && x <= b'Z' { + x += 32; + } + new.push(x); + }); + + String::from_utf8(new).unwrap() + } +} From 4965fe47504ab56e9c84d4328b3c5a96edd89e3d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 12 Dec 2021 10:23:25 +0800 Subject: [PATCH 0166/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 31ce2082..2541909e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 299 | 138 | 154 | 7 | +| 300 | 139 | 154 | 7 | ### 题目 @@ -233,6 +233,7 @@ |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | |718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | +|742 | 转换成小写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/to-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/to-lower-case/) | Easy | |782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | |783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | |784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | From 3b8d325ef9dea580cf52fb6f3b31b6cc32a7eb07 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 4 Jul 2022 22:32:03 +0800 Subject: [PATCH 0167/1556] src/bin/minimum-absolute-difference.rs --- src/bin/minimum-absolute-difference.rs | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/minimum-absolute-difference.rs diff --git a/src/bin/minimum-absolute-difference.rs b/src/bin/minimum-absolute-difference.rs new file mode 100644 index 00000000..225a2aec --- /dev/null +++ b/src/bin/minimum-absolute-difference.rs @@ -0,0 +1,27 @@ +use std::vec; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_abs_difference(mut arr: Vec) -> Vec> { + arr.sort(); + + let mut diff = arr[1] - arr[0]; + let mut v = vec![vec![arr[0], arr[1]]]; + for i in 2..arr.len() { + match (arr[i] - arr[i - 1]).cmp(&diff) { + std::cmp::Ordering::Less => { + diff = arr[i] - arr[i - 1]; + v = vec![]; + v.push(vec![arr[i - 1], arr[i]]); + } + + std::cmp::Ordering::Equal => v.push(vec![arr[i - 1], arr[i]]), + std::cmp::Ordering::Greater => {} + } + } + v + } +} From 566cd2875bb316728b193747f5af2405855383ae Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 4 Jul 2022 22:32:04 +0800 Subject: [PATCH 0168/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2541909e..006bbabc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 300 | 139 | 154 | 7 | +| 301 | 140 | 154 | 7 | ### 题目 @@ -265,6 +265,7 @@ |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | +|1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | |1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | |1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | From ad48a442b6977419dc0fd7ce153806020e70c1df Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 5 Jul 2022 22:33:37 +0800 Subject: [PATCH 0169/1556] src/bin/sort-the-matrix-diagonally.rs --- src/bin/sort-the-matrix-diagonally.rs | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/bin/sort-the-matrix-diagonally.rs diff --git a/src/bin/sort-the-matrix-diagonally.rs b/src/bin/sort-the-matrix-diagonally.rs new file mode 100644 index 00000000..7a2e3bdf --- /dev/null +++ b/src/bin/sort-the-matrix-diagonally.rs @@ -0,0 +1,55 @@ +fn main() { + let a = vec![vec![3, 3, 1, 1], vec![2, 2, 1, 2], vec![1, 1, 1, 2]]; + let b = Solution::diagonal_sort(a); + println!("{:?}", b); + + let a = vec![ + vec![11, 25, 66, 1, 69, 7], + vec![23, 55, 17, 45, 15, 52], + vec![75, 31, 36, 44, 58, 8], + vec![22, 27, 33, 25, 68, 4], + vec![84, 28, 14, 11, 5, 50], + ]; + let b = Solution::diagonal_sort(a); + println!("{:?}", b); +} + +struct Solution; + +impl Solution { + pub fn diagonal_sort(mut mat: Vec>) -> Vec> { + if mat.is_empty() { + return mat; + } + + for i in 0..mat[0].len() { + Self::bubble_sort(&mut mat, 0, i); + } + + for i in 1..mat.len() { + Self::bubble_sort(&mut mat, i, 0); + } + + mat + } + + pub fn bubble_sort(mat: &mut Vec>, x: usize, y: usize) { + let (mut l1, mut l2) = (mat.len() - 1, mat[0].len() - 1); + while l1 > x && l2 > y { + let (mut x1, mut y1) = (x + 1, y + 1); + + while x1 <= l1 && y1 <= l2 { + if mat[x1][y1] < mat[x1 - 1][y1 - 1] { + let a = mat[x1][y1]; + mat[x1][y1] = mat[x1 - 1][y1 - 1]; + mat[x1 - 1][y1 - 1] = a; + } + x1 += 1; + y1 += 1; + } + + l1 -= 1; + l2 -= 1; + } + } +} From 964e4e583453a4fe9563805ca6cbb09143107a13 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 5 Jul 2022 22:33:37 +0800 Subject: [PATCH 0170/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 006bbabc..533fce11 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 301 | 140 | 154 | 7 | +| 302 | 140 | 155 | 7 | ### 题目 @@ -264,6 +264,7 @@ |1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | +|1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | |1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | |1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | From d47d55ecdb2261df3c381a03ab3c7b900f6d2078 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 6 Jul 2022 22:42:59 +0800 Subject: [PATCH 0171/1556] src/bin/na-ying-bi.rs --- src/bin/na-ying-bi.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/bin/na-ying-bi.rs diff --git a/src/bin/na-ying-bi.rs b/src/bin/na-ying-bi.rs new file mode 100644 index 00000000..e9cb5188 --- /dev/null +++ b/src/bin/na-ying-bi.rs @@ -0,0 +1,11 @@ +fn main() { + assert_eq!(Solution::min_count(vec![4, 2, 1]), 4); +} + +struct Solution; + +impl Solution { + pub fn min_count(coins: Vec) -> i32 { + coins.into_iter().map(|x| x / 2 + x % 2).sum() + } +} From e35f22d2405cb33e20afa294a3588f2d49c5ece8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 6 Jul 2022 22:42:59 +0800 Subject: [PATCH 0172/1556] src/bin/remove-all-adjacent-duplicates-in-string.rs --- src/bin/remove-all-adjacent-duplicates-in-string.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/bin/remove-all-adjacent-duplicates-in-string.rs b/src/bin/remove-all-adjacent-duplicates-in-string.rs index 957c6c08..44e82450 100644 --- a/src/bin/remove-all-adjacent-duplicates-in-string.rs +++ b/src/bin/remove-all-adjacent-duplicates-in-string.rs @@ -1,5 +1,3 @@ -use serde::export::Option::Some; - fn main() {} struct Solution; From 0eb94934cf3044d668b777f4a32d11e3614068ef Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 6 Jul 2022 22:43:00 +0800 Subject: [PATCH 0173/1556] README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 533fce11..9f485485 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 302 | 140 | 155 | 7 | +| 304 | 142 | 155 | 7 | ### 题目 @@ -261,6 +261,7 @@ |1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | |1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | +|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | |1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | @@ -309,4 +310,5 @@ |100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | |100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | |100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | +|1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | From faae6871a5d3e6f6471c80c99a842814054c34fc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 10 Jul 2022 23:55:19 +0800 Subject: [PATCH 0174/1556] src/bin/find-all-k-distant-indices-in-an-array.rs --- .../find-all-k-distant-indices-in-an-array.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/find-all-k-distant-indices-in-an-array.rs diff --git a/src/bin/find-all-k-distant-indices-in-an-array.rs b/src/bin/find-all-k-distant-indices-in-an-array.rs new file mode 100644 index 00000000..4d6ee04a --- /dev/null +++ b/src/bin/find-all-k-distant-indices-in-an-array.rs @@ -0,0 +1,36 @@ +fn main() { + let s = Solution::find_k_distant_indices(vec![3, 4, 9, 1, 3, 9, 5], 9, 1); + println!("{s:?}"); + + let s = Solution::find_k_distant_indices(vec![2, 2, 2, 2, 2], 2, 2); + println!("{s:?}"); +} + +struct Solution; + +impl Solution { + pub fn find_k_distant_indices(nums: Vec, key: i32, k: i32) -> Vec { + let indeies: Vec = nums + .iter() + .enumerate() + .filter(|(_, &v)| v == key) + .map(|(i, _)| i) + .collect(); + + let mut data = vec![]; + + nums.into_iter().enumerate().for_each(|(index, _value)| { + for &i in indeies.iter() { + if (index > i && index - i <= k as usize) || (index <= i && i - index <= k as usize) + { + data.push(index as i32); + break; + } + } + }); + + data.sort(); + + data + } +} From 691b2a9476f53fd6daba9f0f4f344392fedadbc8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 10 Jul 2022 23:55:20 +0800 Subject: [PATCH 0175/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f485485..4c6d9a03 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 304 | 142 | 155 | 7 | +| 305 | 143 | 155 | 7 | ### 题目 @@ -299,6 +299,7 @@ |1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | +|2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | From 645aa977a1b253ca78915af23a393d4cd750494e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 22:43:17 +0800 Subject: [PATCH 0176/1556] src/bin/successful-pairs-of-spells-and-potions.rs --- .../successful-pairs-of-spells-and-potions.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/successful-pairs-of-spells-and-potions.rs diff --git a/src/bin/successful-pairs-of-spells-and-potions.rs b/src/bin/successful-pairs-of-spells-and-potions.rs new file mode 100644 index 00000000..45a2e5a6 --- /dev/null +++ b/src/bin/successful-pairs-of-spells-and-potions.rs @@ -0,0 +1,28 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn successful_pairs(spells: Vec, potions: Vec, success: i64) -> Vec { + let mut nums = vec![0; spells.len()]; + + let mut potions = potions; + potions.sort(); + + for (i, v) in spells.into_iter().enumerate() { + let (mut start, mut end) = (0, potions.len() - 1); + let min = success / v as i64; + while (start + end) / 2 < potions.len() { + if potions[(start + end) / 2] as i64 >= min && potions[(start + end) / 2 - 1] as i64 < min { + nums[i]+=1; + break; + } else if potions[(start + end) / 2] as i64 < min { + start = (start + end) / 2; + } else if potions[(start + end) / 2] as i64 < min { + end = (start + end) / 2; + } + } + } + nums + } +} From e9c8f7adab6713c71b04b2544d39d4e0fc9f0d51 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:42 +0800 Subject: [PATCH 0177/1556] src/bin/add-one-row-to-tree.rs --- src/bin/add-one-row-to-tree.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/bin/add-one-row-to-tree.rs b/src/bin/add-one-row-to-tree.rs index 53736192..a69f6362 100644 --- a/src/bin/add-one-row-to-tree.rs +++ b/src/bin/add-one-row-to-tree.rs @@ -21,15 +21,24 @@ impl TreeNode { } } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { - pub fn add_one_row(root: Option>>, val: i32, depth: i32) -> Option>> { + pub fn add_one_row( + root: Option>>, + val: i32, + depth: i32, + ) -> Option>> { Self::add(root, val, depth, true) } - fn add(root: Option>>, val: i32, depth: i32, is_left: bool) -> Option>> { + fn add( + root: Option>>, + val: i32, + depth: i32, + is_left: bool, + ) -> Option>> { if depth == 1 { let mut node = TreeNode::new(val); if is_left { @@ -39,7 +48,6 @@ impl Solution { } Some(Rc::new(RefCell::new(node))) } else { - if root.is_none() { return None; } From c5d8ea9eeb784612e06ca5c1bc49145eec780054 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:42 +0800 Subject: [PATCH 0178/1556] src/bin/average-of-levels-in-binary-tree.rs --- src/bin/average-of-levels-in-binary-tree.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/average-of-levels-in-binary-tree.rs b/src/bin/average-of-levels-in-binary-tree.rs index 21f88044..d4c635a5 100644 --- a/src/bin/average-of-levels-in-binary-tree.rs +++ b/src/bin/average-of-levels-in-binary-tree.rs @@ -21,8 +21,8 @@ impl TreeNode { } } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn average_of_levels(root: Option>>) -> Vec { From 5d797340f7d99139145c5e486fa5ce49b5c47970 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:43 +0800 Subject: [PATCH 0179/1556] src/bin/design-circular-queue.rs --- src/bin/design-circular-queue.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bin/design-circular-queue.rs b/src/bin/design-circular-queue.rs index a01797fb..d8d5720d 100644 --- a/src/bin/design-circular-queue.rs +++ b/src/bin/design-circular-queue.rs @@ -18,7 +18,6 @@ struct MyCircularQueue { data: Vec, } - /** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. @@ -81,7 +80,11 @@ impl MyCircularQueue { return -1; } - self.data[if self.start == 0 { self.cap - 1 } else { self.start - 1 }] + self.data[if self.start == 0 { + self.cap - 1 + } else { + self.start - 1 + }] } fn is_empty(&self) -> bool { From 32f3445615741e72af74fad0182e827f858cea28 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:44 +0800 Subject: [PATCH 0180/1556] src/bin/encode-and-decode-tinyurl.rs --- src/bin/encode-and-decode-tinyurl.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/bin/encode-and-decode-tinyurl.rs b/src/bin/encode-and-decode-tinyurl.rs index b2f87327..91d76e24 100644 --- a/src/bin/encode-and-decode-tinyurl.rs +++ b/src/bin/encode-and-decode-tinyurl.rs @@ -9,30 +9,36 @@ struct Solution; * let ans: VecVec = obj.decode(s); */ struct Codec { - hash: std::collections::HashMap::, + hash: std::collections::HashMap, } -/** +/** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. */ impl Codec { fn new() -> Self { - Self { hash: std::collections::HashMap::new() } + Self { + hash: std::collections::HashMap::new(), + } } // Encodes a URL to a shortened URL. fn encode(&mut self, longURL: String) -> String { let mut s = std::collections::hash_map::DefaultHasher::new(); ::hash(&longURL, &mut s); - let hash_code = ::finish(&s); + let hash_code = + ::finish(&s); self.hash.insert(hash_code, longURL); format!("http://tinyurl.com/{}", hash_code) } // Decodes a shortened URL to its original URL. fn decode(&self, shortURL: String) -> String { - let hash_code = shortURL.trim_start_matches("http://tinyurl.com/").parse::().unwrap(); + let hash_code = shortURL + .trim_start_matches("http://tinyurl.com/") + .parse::() + .unwrap(); self.hash.get(&hash_code).unwrap().to_string() } } From 8d31ce563ae97000474670086195bbdadeaea0d1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:44 +0800 Subject: [PATCH 0181/1556] src/bin/find-all-duplicates-in-an-array.rs --- src/bin/find-all-duplicates-in-an-array.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bin/find-all-duplicates-in-an-array.rs b/src/bin/find-all-duplicates-in-an-array.rs index ef2f21a0..2e8d6683 100644 --- a/src/bin/find-all-duplicates-in-an-array.rs +++ b/src/bin/find-all-duplicates-in-an-array.rs @@ -1,5 +1,8 @@ fn main() { - println!("{:?}", Solution::find_duplicates(vec![4, 3, 2, 7, 8, 2, 3, 1])) + println!( + "{:?}", + Solution::find_duplicates(vec![4, 3, 2, 7, 8, 2, 3, 1]) + ) } struct Solution; @@ -14,8 +17,7 @@ impl Solution { nums[index] += a as i32; } - nums - .into_iter() + nums.into_iter() .enumerate() .filter(|&(i, x)| x / (a as i32) == 2) .map(|(i, x)| i as i32 + 1) From e2a5df05df853092f6a9a8395f01130a39c2ba16 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:44 +0800 Subject: [PATCH 0182/1556] src/bin/find-bottom-left-tree-value.rs --- src/bin/find-bottom-left-tree-value.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/find-bottom-left-tree-value.rs b/src/bin/find-bottom-left-tree-value.rs index 3123a60d..62b4bd5a 100644 --- a/src/bin/find-bottom-left-tree-value.rs +++ b/src/bin/find-bottom-left-tree-value.rs @@ -21,8 +21,8 @@ impl TreeNode { } } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn find_bottom_left_value(root: Option>>) -> i32 { From 74ca2312acfcbb172e33b597edc63b9b21445590 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:45 +0800 Subject: [PATCH 0183/1556] src/bin/find-largest-value-in-each-tree-row.rs --- src/bin/find-largest-value-in-each-tree-row.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bin/find-largest-value-in-each-tree-row.rs b/src/bin/find-largest-value-in-each-tree-row.rs index d8a6006f..916e02f1 100644 --- a/src/bin/find-largest-value-in-each-tree-row.rs +++ b/src/bin/find-largest-value-in-each-tree-row.rs @@ -21,12 +21,14 @@ impl TreeNode { } } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn largest_values(root: Option>>) -> Vec { - if root.is_none() { return vec![]; } + if root.is_none() { + return vec![]; + } let mut stack = vec![root]; let mut result = vec![]; while !stack.is_empty() { From 46714ca69d3a4610b1f19c7379df316bc16f6e38 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:45 +0800 Subject: [PATCH 0184/1556] src/bin/insert-into-a-binary-search-tree.rs --- src/bin/insert-into-a-binary-search-tree.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bin/insert-into-a-binary-search-tree.rs b/src/bin/insert-into-a-binary-search-tree.rs index c2346366..99ee165c 100644 --- a/src/bin/insert-into-a-binary-search-tree.rs +++ b/src/bin/insert-into-a-binary-search-tree.rs @@ -21,11 +21,14 @@ impl TreeNode { } } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { - pub fn insert_into_bst(root: Option>>, val: i32) -> Option>> { + pub fn insert_into_bst( + root: Option>>, + val: i32, + ) -> Option>> { if root.is_none() { return Some(Rc::new(RefCell::new(TreeNode::new(val)))); } @@ -41,4 +44,4 @@ impl Solution { root } -} \ No newline at end of file +} From 23b5bb0320fee20a2649c9e038666e96e3cb245d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:46 +0800 Subject: [PATCH 0185/1556] src/bin/jewels-and-stones.rs --- src/bin/jewels-and-stones.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bin/jewels-and-stones.rs b/src/bin/jewels-and-stones.rs index 454223a9..660fc350 100644 --- a/src/bin/jewels-and-stones.rs +++ b/src/bin/jewels-and-stones.rs @@ -4,7 +4,10 @@ struct Solution; impl Solution { pub fn num_jewels_in_stones(jewels: String, stones: String) -> i32 { - let j = jewels.bytes().into_iter().collect::>(); + let j = jewels + .bytes() + .into_iter() + .collect::>(); stones.bytes().into_iter().filter(|x| j.contains(x)).count() as i32 } } From f6859bf2ef712486c91f8c6a34adc5fd484afd38 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:46 +0800 Subject: [PATCH 0186/1556] src/bin/maximum-length-of-repeated-subarray.rs --- src/bin/maximum-length-of-repeated-subarray.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/maximum-length-of-repeated-subarray.rs b/src/bin/maximum-length-of-repeated-subarray.rs index 0395c45b..56a397f9 100644 --- a/src/bin/maximum-length-of-repeated-subarray.rs +++ b/src/bin/maximum-length-of-repeated-subarray.rs @@ -4,7 +4,7 @@ struct Solution; impl Solution { pub fn find_length(nums1: Vec, nums2: Vec) -> i32 { - let mut v = vec![vec![0;nums1.len()]; nums2.len()]; + let mut v = vec![vec![0; nums1.len()]; nums2.len()]; let mut res = 0; for (i, &v1) in nums1.iter().enumerate() { for (j, &v2) in nums2.iter().enumerate() { From af75adfd58792d148b367c00af5a18f619887cfd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:47 +0800 Subject: [PATCH 0187/1556] src/bin/minimum-absolute-difference-in-bst.rs --- src/bin/minimum-absolute-difference-in-bst.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/minimum-absolute-difference-in-bst.rs b/src/bin/minimum-absolute-difference-in-bst.rs index 415b3443..909e109a 100644 --- a/src/bin/minimum-absolute-difference-in-bst.rs +++ b/src/bin/minimum-absolute-difference-in-bst.rs @@ -21,8 +21,8 @@ impl TreeNode { } } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn get_minimum_difference(root: Option>>) -> i32 { From 4ac9ea9896a5c8f252dc6e8d5464bf10cf1a894f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:47 +0800 Subject: [PATCH 0188/1556] src/bin/most-frequent-subtree-sum.rs --- src/bin/most-frequent-subtree-sum.rs | 33 +++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/bin/most-frequent-subtree-sum.rs b/src/bin/most-frequent-subtree-sum.rs index 761a4fa9..e0b53860 100644 --- a/src/bin/most-frequent-subtree-sum.rs +++ b/src/bin/most-frequent-subtree-sum.rs @@ -21,8 +21,8 @@ impl TreeNode { } } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn find_frequent_tree_sum(root: Option>>) -> Vec { @@ -31,17 +31,38 @@ impl Solution { let mut max = 0; Self::get_sum(&mut root, &mut h, &mut max); - h.iter().filter(|&(_, y)| *y == max).map(|(&x, _)| x).collect() + h.iter() + .filter(|&(_, y)| *y == max) + .map(|(&x, _)| x) + .collect() } - fn get_sum(root: &mut Option>>, h: &mut std::collections::HashMap, max: &mut i32) { - if root.is_none() { return; } + fn get_sum( + root: &mut Option>>, + h: &mut std::collections::HashMap, + max: &mut i32, + ) { + if root.is_none() { + return; + } Self::get_sum(&mut root.as_mut().unwrap().borrow_mut().left, h, max); Self::get_sum(&mut root.as_mut().unwrap().borrow_mut().right, h, max); - let sum = root.as_ref().unwrap().borrow().left.as_ref().map_or(0, |x| x.borrow().val) - + root.as_ref().unwrap().borrow().right.as_ref().map_or(0, |x| x.borrow().val) + let sum = root + .as_ref() + .unwrap() + .borrow() + .left + .as_ref() + .map_or(0, |x| x.borrow().val) + + root + .as_ref() + .unwrap() + .borrow() + .right + .as_ref() + .map_or(0, |x| x.borrow().val) + root.as_ref().unwrap().borrow().val; root.as_mut().unwrap().borrow_mut().val = sum; From e53064b03f2a0232a74ea875e377270f3b56e51b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:48 +0800 Subject: [PATCH 0189/1556] src/bin/online-election.rs --- src/bin/online-election.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin/online-election.rs b/src/bin/online-election.rs index 7be65526..816de3cd 100644 --- a/src/bin/online-election.rs +++ b/src/bin/online-election.rs @@ -30,7 +30,6 @@ struct TopVotedCandidate { times: Vec, } - /** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. From 7c217789d22471d4bb47a8bc3025d9112ad95b5c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:48 +0800 Subject: [PATCH 0190/1556] src/bin/robot-return-to-origin.rs --- src/bin/robot-return-to-origin.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin/robot-return-to-origin.rs b/src/bin/robot-return-to-origin.rs index f79b69b0..c25be7db 100644 --- a/src/bin/robot-return-to-origin.rs +++ b/src/bin/robot-return-to-origin.rs @@ -16,7 +16,6 @@ impl Solution { } } - v == (0, 0) } } From 820d7f32e49797ac40d88723c8a061be50fffe57 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:49 +0800 Subject: [PATCH 0191/1556] src/bin/search-in-a-binary-search-tree.rs --- src/bin/search-in-a-binary-search-tree.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bin/search-in-a-binary-search-tree.rs b/src/bin/search-in-a-binary-search-tree.rs index dd12ad6f..c89e0866 100644 --- a/src/bin/search-in-a-binary-search-tree.rs +++ b/src/bin/search-in-a-binary-search-tree.rs @@ -21,11 +21,14 @@ impl TreeNode { } } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { - pub fn search_bst(root: Option>>, val: i32) -> Option>> { + pub fn search_bst( + root: Option>>, + val: i32, + ) -> Option>> { let mut root = root; while let Some(r) = root { let v = r.borrow().val; From af73c9ef085fba14050b2c62fe353bfb42627509 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:49 +0800 Subject: [PATCH 0192/1556] src/bin/successful-pairs-of-spells-and-potions.rs --- .../successful-pairs-of-spells-and-potions.rs | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/bin/successful-pairs-of-spells-and-potions.rs b/src/bin/successful-pairs-of-spells-and-potions.rs index 45a2e5a6..9e990851 100644 --- a/src/bin/successful-pairs-of-spells-and-potions.rs +++ b/src/bin/successful-pairs-of-spells-and-potions.rs @@ -1,4 +1,12 @@ -fn main() {} +fn main() { + let s = Solution::successful_pairs(vec![5, 1, 3], vec![1, 2, 3, 4, 5], 7); + println!("{s:?}"); + + let s = Solution::successful_pairs(vec![3, 1, 2], vec![8, 5, 8], 16); + println!("{s:?}"); + let s = Solution::successful_pairs(vec![1, 2, 3, 4, 5, 6, 7], vec![1, 2, 3, 4, 5, 6, 7], 25); + println!("{s:?}"); +} struct Solution; @@ -11,18 +19,30 @@ impl Solution { for (i, v) in spells.into_iter().enumerate() { let (mut start, mut end) = (0, potions.len() - 1); - let min = success / v as i64; - while (start + end) / 2 < potions.len() { - if potions[(start + end) / 2] as i64 >= min && potions[(start + end) / 2 - 1] as i64 < min { - nums[i]+=1; - break; - } else if potions[(start + end) / 2] as i64 < min { - start = (start + end) / 2; - } else if potions[(start + end) / 2] as i64 < min { - end = (start + end) / 2; + let min = if success % v as i64 == 0 { + success / v as i64 + } else { + success / v as i64 + 1 + }; + + while start <= end && (start + end) / 2 < potions.len() { + let middile = (start + end) / 2; + + if potions[middile] as i64 >= min { + if middile == 0 { + nums[i] = potions.len() as i32; + break; + } else if (potions[middile - 1] as i64) < min { + nums[i] = (potions.len() - middile) as i32; + break; + } else { + end = middile; + } + } else { + start = middile + 1; } } } - nums + nums } } From 69c1232c5d201fd404692e0c8739fcc48b54853e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Jul 2022 23:06:50 +0800 Subject: [PATCH 0193/1556] README.md --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c6d9a03..e4b51ebb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 305 | 143 | 155 | 7 | +| 321 | 148 | 166 | 7 | ### 题目 @@ -199,6 +199,7 @@ |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | |442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | +|442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | |445 | 两数相加 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers-ii.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers-ii/) | Medium | |448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | |449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | @@ -210,12 +211,17 @@ |504 | 七进制数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/base-7.rs) | [leetcode](https://leetcode-cn.com/problems/base-7/) | Easy | |507 | 完美数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-number.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-number/) | Easy | |508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | +|508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | |513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | +|513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | +|515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | |515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | |530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | |530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | +|530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | +|535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | @@ -224,24 +230,32 @@ |605 | 种花问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/can-place-flowers.rs) | [leetcode](https://leetcode-cn.com/problems/can-place-flowers/) | Easy | |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | |623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | +|623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | +|637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | |637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | |643 | 子数组最大平均数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-average-subarray-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-average-subarray-i/) | Easy | |649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | |650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | |653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | |657 | 机器人能否返回原点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-return-to-origin.rs) | [leetcode](https://leetcode-cn.com/problems/robot-return-to-origin/) | Easy | +|657 | 机器人能否返回原点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-return-to-origin.rs) | [leetcode](https://leetcode-cn.com/problems/robot-return-to-origin/) | Easy | |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | |718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | +|718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | |742 | 转换成小写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/to-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/to-lower-case/) | Easy | |782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | +|782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | +|783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | |783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | |784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | +|784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | +|860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | |917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | |921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | @@ -249,6 +263,7 @@ |925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | +|947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | |981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | |982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Medium | @@ -300,6 +315,7 @@ |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | +|2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | From 4754bf79ca99609a450bf6523c77fa52125c9f85 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 12 Jul 2022 07:46:01 +0800 Subject: [PATCH 0194/1556] feat(leetcode): update dependencies --- Cargo.lock | 597 ++++++++++++++++++++++++++++++----------------------- src/lib.rs | 2 +- 2 files changed, 336 insertions(+), 263 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bd397e9f..4378e4ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,9 +24,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "base64" @@ -72,9 +72,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.7.1" +version = "3.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9df67f7bf9ef8498769f994239c45613ef0c5899415fb58e9add412d2c1a538" +checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" [[package]] name = "byte-tools" @@ -102,9 +102,9 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "cc" -version = "1.0.70" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d26a6ce4b6a484fa3edb70f7efa6fc430fd2b87285fe8b84304fd0936faa0dc0" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" dependencies = [ "jobserver", ] @@ -135,50 +135,55 @@ dependencies = [ [[package]] name = "chrono-tz" -version = "0.5.3" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2554a3155fec064362507487171dcc4edc3df60cb10f3a1fb10ed8094822b120" +checksum = "58549f1842da3080ce63002102d5bc954c7bc843d4f47818e642abdc36253552" dependencies = [ "chrono", + "chrono-tz-build", + "phf", +] + +[[package]] +name = "chrono-tz-build" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db058d493fb2f65f41861bfed7e3fe6335264a9f0f92710cab5bdf01fef09069" +dependencies = [ "parse-zoneinfo", + "phf", + "phf_codegen", ] [[package]] name = "clap" -version = "3.0.0-beta.4" +version = "3.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcd70aa5597dbc42f7217a543f9ef2768b2ef823ba29036072d30e1d88e98406" +checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83" dependencies = [ "atty", "bitflags", - "clap_derive", + "clap_lex", "indexmap", - "lazy_static", - "os_str_bytes", "strsim", "termcolor", "textwrap", - "vec_map", ] [[package]] -name = "clap_derive" -version = "3.0.0-beta.4" +name = "clap_lex" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b5bb0d655624a0b8770d1c178fb8ffcb1f91cc722cb08f451e3dc72465421ac" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", + "os_str_bytes", ] [[package]] name = "core-foundation" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a89e2ae426ea83155dccf10c0fa6b1463ef6d5fcb44cee0b224a408fa640a62" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" dependencies = [ "core-foundation-sys", "libc", @@ -186,18 +191,18 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "crossbeam-utils" -version = "0.8.5" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83" dependencies = [ "cfg-if 1.0.0", - "lazy_static", + "once_cell", ] [[package]] @@ -217,9 +222,9 @@ dependencies = [ [[package]] name = "encoding_rs" -version = "0.8.28" +version = "0.8.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" dependencies = [ "cfg-if 1.0.0", ] @@ -230,6 +235,15 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +[[package]] +name = "fastrand" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +dependencies = [ + "instant", +] + [[package]] name = "fnv" version = "1.0.7" @@ -279,49 +293,48 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "futures-channel" -version = "0.3.17" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" +checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.17" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" +checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" [[package]] name = "futures-io" -version = "0.3.17" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" +checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" [[package]] name = "futures-sink" -version = "0.3.17" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" +checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" [[package]] name = "futures-task" -version = "0.3.17" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" +checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" [[package]] name = "futures-util" -version = "0.3.17" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" +checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" dependencies = [ - "autocfg", "futures-core", "futures-io", "futures-task", "memchr", - "pin-project-lite 0.2.7", + "pin-project-lite 0.2.9", "pin-utils", "slab", ] @@ -337,9 +350,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.3" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ "cfg-if 1.0.0", "libc", @@ -348,9 +361,9 @@ dependencies = [ [[package]] name = "git2" -version = "0.13.22" +version = "0.13.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c1cbbfc9a1996c6af82c2b4caf828d2c653af4fcdbb0e5674cc966eee5a4197" +checksum = "f29229cc1b24c0e6062f6e742aa3e256492a5323365e5ed3413599f8a5eff7d6" dependencies = [ "bitflags", "libc", @@ -363,9 +376,9 @@ dependencies = [ [[package]] name = "globset" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd" +checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" dependencies = [ "aho-corasick", "bstr", @@ -407,18 +420,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" - -[[package]] -name = "heck" -version = "0.3.3" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022" [[package]] name = "hermit-abi" @@ -431,13 +435,13 @@ dependencies = [ [[package]] name = "http" -version = "0.2.5" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" +checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" dependencies = [ "bytes 1.1.0", "fnv", - "itoa", + "itoa 1.0.2", ] [[package]] @@ -452,9 +456,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.5.1" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" +checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" [[package]] name = "httpdate" @@ -483,7 +487,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa", + "itoa 0.4.8", "pin-project", "socket2", "tokio", @@ -536,14 +540,23 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.7.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", "hashbrown", ] +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "iovec" version = "0.1.4" @@ -555,9 +568,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.3.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" +checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" [[package]] name = "itoa" @@ -565,6 +578,12 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" +[[package]] +name = "itoa" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" + [[package]] name = "jobserver" version = "0.1.24" @@ -576,9 +595,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.55" +version = "0.3.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" +checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" dependencies = [ "wasm-bindgen", ] @@ -616,15 +635,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.102" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2a5ac8f984bfcf3a823267e5fde638acc3325f6496633a5da6bb6eb2171e103" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "libgit2-sys" -version = "0.12.23+1.2.0" +version = "0.12.26+1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29730a445bae719db3107078b46808cc45a5b7a6bae3f31272923af969453356" +checksum = "19e1c899248e606fbfe68dcb31d8b0176ebab833b103824af31bddf4b7457494" dependencies = [ "cc", "libc", @@ -636,9 +655,9 @@ dependencies = [ [[package]] name = "libssh2-sys" -version = "0.2.21" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0186af0d8f171ae6b9c4c90ec51898bad5d08a2d5e470903a50d9ad8959cbee" +checksum = "b094a36eb4b8b8c8a7b4b8ae43b2944502be3e59cd87687595cf6b0a71b3f4ca" dependencies = [ "cc", "libc", @@ -650,9 +669,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.3" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de5435b8549c16d423ed0c03dbaafe57cf6c3344744f1242520d59c9d8ecec66" +checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" dependencies = [ "cc", "libc", @@ -662,9 +681,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if 1.0.0", ] @@ -683,9 +702,9 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "memchr" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mime" @@ -695,9 +714,9 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] name = "mime_guess" -version = "2.0.3" +version = "2.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" dependencies = [ "mime", "unicase", @@ -736,9 +755,9 @@ dependencies = [ [[package]] name = "native-tls" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" +checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" dependencies = [ "lazy_static", "libc", @@ -765,9 +784,9 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ "autocfg", "num-traits", @@ -775,18 +794,18 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", ] [[package]] name = "num_cpus" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" dependencies = [ "hermit-abi", "libc", @@ -794,9 +813,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.8.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" [[package]] name = "opaque-debug" @@ -806,29 +825,41 @@ checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" [[package]] name = "openssl" -version = "0.10.36" +version = "0.10.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d9facdb76fec0b73c406f125d44d86fdad818d66fef0531eec9233ca425ff4a" +checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" dependencies = [ "bitflags", "cfg-if 1.0.0", "foreign-types", "libc", "once_cell", + "openssl-macros", "openssl-sys", ] +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "openssl-probe" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.67" +version = "0.9.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69df2d8dfc6ce3aaf44b40dec6f487d5a886516cf6879c49e98e0710f310a058" +checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" dependencies = [ "autocfg", "cc", @@ -839,9 +870,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "3.1.0" +version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6acbef58a60fe69ab50510a55bc8cdd4d6cf2283d27ad338f54cb52747a9cf2d" +checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" [[package]] name = "parse-zoneinfo" @@ -901,20 +932,59 @@ dependencies = [ "sha-1", ] +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator", + "phf_shared", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", + "uncased", +] + [[package]] name = "pin-project" -version = "1.0.8" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08" +checksum = "78203e83c48cffbe01e4a2d35d566ca4de445d79a85372fc64e378bfc812a260" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.8" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389" +checksum = "710faf75e1b33345361201d36d04e98ac1ed8909151a017ed384700836104c74" dependencies = [ "proc-macro2", "quote", @@ -929,9 +999,9 @@ checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" [[package]] name = "pin-project-lite" -version = "0.2.7" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" [[package]] name = "pin-utils" @@ -941,68 +1011,43 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.20" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c9b1041b4387893b91ee6746cddfc28516aff326a3519fb2adf820932c5e6cb" +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "ppv-lite86" -version = "0.2.10" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "proc-macro2" -version = "1.0.29" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" +checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.9" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" dependencies = [ "proc-macro2", ] [[package]] name = "rand" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", "rand_core", - "rand_hc", ] [[package]] @@ -1024,29 +1069,20 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rand_hc" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7" -dependencies = [ - "rand_core", -] - [[package]] name = "redox_syscall" -version = "0.2.10" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" +checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" dependencies = [ "bitflags", ] [[package]] name = "regex" -version = "1.5.4" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" dependencies = [ "aho-corasick", "memchr", @@ -1055,9 +1091,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" [[package]] name = "remove_dir_all" @@ -1091,7 +1127,7 @@ dependencies = [ "mime_guess", "native-tls", "percent-encoding", - "pin-project-lite 0.2.7", + "pin-project-lite 0.2.9", "serde", "serde_json", "serde_urlencoded", @@ -1106,9 +1142,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.5" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" [[package]] name = "same-file" @@ -1121,19 +1157,19 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" dependencies = [ "lazy_static", - "winapi 0.3.9", + "windows-sys", ] [[package]] name = "security-framework" -version = "2.4.2" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87" +checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" dependencies = [ "bitflags", "core-foundation", @@ -1144,9 +1180,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.4.2" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" dependencies = [ "core-foundation-sys", "libc", @@ -1154,18 +1190,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.130" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.130" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb" dependencies = [ "proc-macro2", "quote", @@ -1174,23 +1210,23 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.68" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" +checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" dependencies = [ - "itoa", + "itoa 1.0.2", "ryu", "serde", ] [[package]] name = "serde_urlencoded" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa", + "itoa 1.0.2", "ryu", "serde", ] @@ -1207,11 +1243,17 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "siphasher" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" + [[package]] name = "slab" -version = "0.4.4" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c307a32c1c5c437f38c7fd45d753050587732ba8628319fbdf12a7e289ccc590" +checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" [[package]] name = "slug" @@ -1241,24 +1283,24 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.77" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5239bc68e0fef57495900cfea4e8dc75596d9a319d7e16b1e0a440d24e6fe0a0" +checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] name = "tempfile" -version = "3.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ "cfg-if 1.0.0", + "fastrand", "libc", - "rand", "redox_syscall", "remove_dir_all", "winapi 0.3.9", @@ -1266,9 +1308,9 @@ dependencies = [ [[package]] name = "tera" -version = "1.12.1" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf95b0d8a46da5fe3ea119394a6c7f1e745f9de359081641c99946e2bf55d4f2" +checksum = "7c9783d6ff395ae80cf17ed9a25360e7ba37742a79fa8fddabb073c5c7c8856d" dependencies = [ "chrono", "chrono-tz", @@ -1288,36 +1330,33 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] [[package]] name = "textwrap" -version = "0.14.2" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" -dependencies = [ - "unicode-width", -] +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "thread_local" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" dependencies = [ "once_cell", ] [[package]] name = "tinyvec" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" dependencies = [ "tinyvec_macros", ] @@ -1372,29 +1411,29 @@ dependencies = [ [[package]] name = "tower-service" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.28" +version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84f96e095c0c82419687c20ddf5cb3eadb61f4e1405923c9dc8e53a1adacbda8" +checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" dependencies = [ "cfg-if 1.0.0", "log", - "pin-project-lite 0.2.7", + "pin-project-lite 0.2.9", "tracing-core", ] [[package]] name = "tracing-core" -version = "0.1.20" +version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46125608c26121c81b0c6d693eab5a420e416da7e43c426d2e8f7df8da8a3acf" +checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" dependencies = [ - "lazy_static", + "once_cell", ] [[package]] @@ -1415,15 +1454,24 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "typenum" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "ucd-trie" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" +checksum = "89570599c4fe5585de2b388aab47e99f7fa4e9238a1399f707a02e356058141c" + +[[package]] +name = "uncased" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" +dependencies = [ + "version_check", +] [[package]] name = "unic-char-property" @@ -1486,37 +1534,25 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.6" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" + +[[package]] +name = "unicode-ident" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "246f4c42e67e7a4e3c6106ff716a5d067d4132a642840b242e357e468a2a0085" +checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" [[package]] name = "unicode-normalization" -version = "0.1.19" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" - -[[package]] -name = "unicode-width" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" - -[[package]] -name = "unicode-xid" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - [[package]] name = "url" version = "2.2.2" @@ -1535,17 +1571,11 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "walkdir" @@ -1570,15 +1600,15 @@ dependencies = [ [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.78" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" +checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" dependencies = [ "cfg-if 1.0.0", "serde", @@ -1588,9 +1618,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.78" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" +checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" dependencies = [ "bumpalo", "lazy_static", @@ -1603,9 +1633,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.28" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" +checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -1615,9 +1645,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.78" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" +checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1625,9 +1655,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.78" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" +checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" dependencies = [ "proc-macro2", "quote", @@ -1638,15 +1668,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.78" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" +checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" [[package]] name = "web-sys" -version = "0.3.55" +version = "0.3.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" +checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" dependencies = [ "js-sys", "wasm-bindgen", @@ -1695,6 +1725,49 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + [[package]] name = "winreg" version = "0.7.0" diff --git a/src/lib.rs b/src/lib.rs index 51c70da9..d31caef7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ pub fn run() { .subcommand( App::new("new").about("get a new leetcode question").arg( Arg::new("question_name") - .about("The configuration file to use") + .help("The configuration file to use") .index(1), ), ) From 01f0a59583ef0b761b0e9922f7b60e04b7f964ad Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 13 Jul 2022 21:59:03 +0800 Subject: [PATCH 0195/1556] src/bin/how-many-numbers-are-smaller-than-the-current-number.rs --- ...ers-are-smaller-than-the-current-number.rs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/bin/how-many-numbers-are-smaller-than-the-current-number.rs diff --git a/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs b/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs new file mode 100644 index 00000000..eb577bb3 --- /dev/null +++ b/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs @@ -0,0 +1,49 @@ +fn main() { + let s = Solution::smaller_numbers_than_current(vec![8, 1, 2, 2, 3]); + println!("{s:?}"); + + let s = Solution::smaller_numbers_than_current(vec![6, 5, 4, 8]); + println!("{s:?}"); + + let s = Solution::smaller_numbers_than_current(vec![7, 7, 7, 7]); + println!("{s:?}"); +} + +struct Solution; + +impl Solution { + pub fn smaller_numbers_than_current(mut nums: Vec) -> Vec { + let mut result = nums.clone(); + result.sort(); + + 'out_loop: for i in nums.iter_mut() { + if *i <= result[0] { + *i = 0; + } else if *i > result[result.len() - 1] { + *i = result.len() as i32; + } else { + let (mut start, mut end) = (0, result.len() - 1); + let mut middle = (start + end) / 2; + + while start <= end { + if *i > result[middle] { + start = middle + 1; + } else if *i == result[middle] { + if middle == 0 || result[middle - 1] < *i { + *i = middle as i32; + continue 'out_loop; + } else if result[middle - 1] == *i { + end = middle - 1; + } else { + start = middle + 1; + } + } else { + end = middle - 1; + } + middle = (start + end) / 2; + } + } + } + nums + } +} From 763c988a243a87707bf898b371e8b52aa36b019f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 13 Jul 2022 21:59:03 +0800 Subject: [PATCH 0196/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e4b51ebb..79858cdd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 321 | 148 | 166 | 7 | +| 322 | 149 | 166 | 7 | ### 题目 @@ -296,6 +296,7 @@ |1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | Easy | |1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | |1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | +|1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | |1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | |1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | From 6fa9b582c586f8ff14f9e583dd738d3f40876799 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 14 Jul 2022 23:25:37 +0800 Subject: [PATCH 0197/1556] src/bin/rle-iterator.rs --- src/bin/rle-iterator.rs | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/bin/rle-iterator.rs diff --git a/src/bin/rle-iterator.rs b/src/bin/rle-iterator.rs new file mode 100644 index 00000000..88d7f20b --- /dev/null +++ b/src/bin/rle-iterator.rs @@ -0,0 +1,54 @@ +fn main() { + let mut s = RLEIterator::new(vec![3, 8, 0, 9, 2, 5]); + println!("{}", s.next(2)); + println!("{}", s.next(1)); + println!("{}", s.next(1)); + println!("{}", s.next(2)); +} + +struct Solution; + +#[derive(Debug)] +struct RLEIterator { + encoding: Vec, + index: usize, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl RLEIterator { + fn new(encoding: Vec) -> Self { + Self { encoding, index: 0 } + } + + fn next(&mut self, n: i32) -> i32 { + let mut n = n; + + for i in self.encoding.iter().skip(self.index).step_by(2) { + if *i == 0 { + self.index += 2; + continue; + } + + match n.cmp(i) { + std::cmp::Ordering::Equal => { + let r = self.encoding[self.index + 1]; + self.index += 2; + return r; + } + std::cmp::Ordering::Greater => { + self.index += 2; + n -= *i; + } + std::cmp::Ordering::Less => { + self.encoding[self.index] -= n; + return self.encoding[self.index + 1]; + } + } + } + + -1 + } +} From 9f270f8d6be6b4d22125847ecdf03bbcd5f08fa7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 14 Jul 2022 23:25:37 +0800 Subject: [PATCH 0198/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 79858cdd..7424088d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 322 | 149 | 166 | 7 | +| 323 | 149 | 167 | 7 | ### 题目 @@ -262,6 +262,7 @@ |924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | |925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | +|936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | |947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | |947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | From d4bdf7c519a65fcece186a396166124f6c8c4c40 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 15 Jul 2022 22:26:04 +0800 Subject: [PATCH 0199/1556] src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs --- .../shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs diff --git a/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs b/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs new file mode 100644 index 00000000..3d055e5a --- /dev/null +++ b/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs @@ -0,0 +1,37 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_repeat_number1(nums: Vec) -> i32 { + let mut count = vec![0; nums.len()]; + for i in nums { + if count[i as usize] == 1 { + return i; + } else { + count[i as usize] = 1; + } + } + + -1 + } + + pub fn find_repeat_number(mut nums: Vec) -> i32 { + 'out: for i in 0..nums.len() { + loop { + let x = nums[i] as usize; + if i == x { + continue 'out; + } + + if nums[x] == x as i32 { + return nums[x]; + } + + nums.swap(i, x); + } + } + + -1 + } +} From f5b9a91d09aa32c696aba8995f4bcfefd7cb17a3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 15 Jul 2022 22:26:04 +0800 Subject: [PATCH 0200/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7424088d..1e8158e6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 323 | 149 | 167 | 7 | +| 324 | 150 | 167 | 7 | ### 题目 @@ -320,6 +320,7 @@ |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | +|100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From b654c9327a307af5e63c01ace28f112d8d41f966 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 17 Jul 2022 23:22:25 +0800 Subject: [PATCH 0201/1556] src/bin/ti-huan-kong-ge-lcof.rs --- src/bin/ti-huan-kong-ge-lcof.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/bin/ti-huan-kong-ge-lcof.rs diff --git a/src/bin/ti-huan-kong-ge-lcof.rs b/src/bin/ti-huan-kong-ge-lcof.rs new file mode 100644 index 00000000..bf3a9574 --- /dev/null +++ b/src/bin/ti-huan-kong-ge-lcof.rs @@ -0,0 +1,18 @@ +fn main() {} + +struct Solution; + +impl Solution { + pub fn replace_space(s: String) -> String { + let mut result = String::new(); + for i in s.chars() { + if i == ' ' { + result.push_str("%20"); + } else { + result.push(i); + } + } + + result + } +} From 226c4206821217f2a288798e332a84e615c509a4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 17 Jul 2022 23:22:25 +0800 Subject: [PATCH 0202/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e8158e6..e4126dc4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 324 | 150 | 167 | 7 | +| 325 | 151 | 167 | 7 | ### 题目 @@ -321,6 +321,7 @@ |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | +|100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From 94c8d9f0f28247e847e2bc0f2997a7e35fed118f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 20 Jul 2022 21:19:14 +0800 Subject: [PATCH 0203/1556] src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs --- .../cong-wei-dao-tou-da-yin-lian-biao-lcof.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs diff --git a/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs b/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs new file mode 100644 index 00000000..745e54e7 --- /dev/null +++ b/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs @@ -0,0 +1,34 @@ +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} + +impl Solution { + pub fn reverse_print(head: Option>) -> Vec { + let mut result = vec![]; + let mut head = head; + + while head.is_some() { + let h = head.unwrap(); + result.push(h.val); + head = h.next; + } + + result.reverse(); + + result + } +} From 5bd18cd01ccddd1e7be5e7affad4c19bc57f4ed9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 20 Jul 2022 21:19:15 +0800 Subject: [PATCH 0204/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e4126dc4..736ebfd7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 325 | 151 | 167 | 7 | +| 326 | 152 | 167 | 7 | ### 题目 @@ -322,6 +322,7 @@ |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | |100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | +|100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From 9f6e5b61a5f4b736dbb759341ac553c4b3fa03dc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 21 Jul 2022 23:17:21 +0800 Subject: [PATCH 0205/1556] src/bin/zhong-jian-er-cha-shu-lcof.rs --- src/bin/zhong-jian-er-cha-shu-lcof.rs | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/bin/zhong-jian-er-cha-shu-lcof.rs diff --git a/src/bin/zhong-jian-er-cha-shu-lcof.rs b/src/bin/zhong-jian-er-cha-shu-lcof.rs new file mode 100644 index 00000000..8ccbd288 --- /dev/null +++ b/src/bin/zhong-jian-er-cha-shu-lcof.rs @@ -0,0 +1,60 @@ +use std::cell::RefCell; +use std::rc::Rc; + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +impl Solution { + pub fn build_tree(preorder: Vec, inorder: Vec) -> Option>> { + Self::build(&preorder[..], &inorder[..]) + } + + fn build(preorder: &[i32], inorder: &[i32]) -> Option>> { + if preorder.is_empty() { + return None; + } + + let index = inorder + .iter() + .enumerate() + .map(|(x, &y)| (y, x)) + .collect::>(); + + let node_value = preorder[0]; + let node_index = index.get(&node_value).unwrap(); + let left_len = *node_index; + let node = Rc::new(RefCell::new(TreeNode::new(node_value))); + + if left_len > 0 { + node.borrow_mut().left = + Self::build(&preorder[1..left_len + 1], &inorder[..left_len + 1]); + } + + if left_len < inorder.len() { + node.borrow_mut().right = + Self::build(&preorder[left_len + 1..], &inorder[node_index + 1..]); + } + + Some(node) + } +} From 97f242889a4976c0ae3d2d86c5f096b486af697b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 21 Jul 2022 23:17:21 +0800 Subject: [PATCH 0206/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 736ebfd7..ceb15980 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 326 | 152 | 167 | 7 | +| 327 | 152 | 168 | 7 | ### 题目 @@ -323,6 +323,7 @@ |100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | |100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | |100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | +|100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From c134982012c778015e5ce4b1eab9113613665b03 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 22 Jul 2022 10:01:34 +0800 Subject: [PATCH 0207/1556] src/bin/zhong-jian-er-cha-shu-lcof.rs --- src/bin/zhong-jian-er-cha-shu-lcof.rs | 60 ++++++++++++++++++++------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/src/bin/zhong-jian-er-cha-shu-lcof.rs b/src/bin/zhong-jian-er-cha-shu-lcof.rs index 8ccbd288..526af239 100644 --- a/src/bin/zhong-jian-er-cha-shu-lcof.rs +++ b/src/bin/zhong-jian-er-cha-shu-lcof.rs @@ -1,7 +1,13 @@ use std::cell::RefCell; use std::rc::Rc; -fn main() {} +fn main() { + println!( + "{:?}", + Solution::build_tree(vec![3, 9, 20, 15, 7], vec![9, 3, 15, 20, 7]) + ); + println!("{:?}", Solution::build_tree(vec![1, 2], vec![1, 2])); +} struct Solution; @@ -26,10 +32,6 @@ impl TreeNode { impl Solution { pub fn build_tree(preorder: Vec, inorder: Vec) -> Option>> { - Self::build(&preorder[..], &inorder[..]) - } - - fn build(preorder: &[i32], inorder: &[i32]) -> Option>> { if preorder.is_empty() { return None; } @@ -40,21 +42,49 @@ impl Solution { .map(|(x, &y)| (y, x)) .collect::>(); - let node_value = preorder[0]; - let node_index = index.get(&node_value).unwrap(); - let left_len = *node_index; - let node = Rc::new(RefCell::new(TreeNode::new(node_value))); + Self::build( + &preorder, + &inorder, + (0, preorder.len() - 1), + (0, inorder.len() - 1), + &index, + ) + } - if left_len > 0 { - node.borrow_mut().left = - Self::build(&preorder[1..left_len + 1], &inorder[..left_len + 1]); + fn build( + preorder: &Vec, + inorder: &Vec, + preorder_index: (usize, usize), + inorder_index: (usize, usize), + index: &std::collections::HashMap, + ) -> Option>> { + if preorder_index.0 > preorder_index.1 { + return None; } - if left_len < inorder.len() { - node.borrow_mut().right = - Self::build(&preorder[left_len + 1..], &inorder[node_index + 1..]); + let root_value = preorder[preorder_index.0]; + let &root_index = index.get(&root_value).unwrap(); + let left_len = root_index - inorder_index.0; + let node = Rc::new(RefCell::new(TreeNode::new(root_value))); + + if root_index > 0 { + node.borrow_mut().left = Self::build( + preorder, + inorder, + (preorder_index.0 + 1, (preorder_index.0 + left_len)), + (inorder_index.0, (root_index - 1)), + index, + ); } + node.borrow_mut().right = Self::build( + preorder, + inorder, + (preorder_index.0 + left_len + 1, preorder_index.1), + (root_index + 1, inorder_index.1), + index, + ); + Some(node) } } From 3a157551e3d75453184646158e9aea72cc27c411 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 22 Jul 2022 10:01:35 +0800 Subject: [PATCH 0208/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ceb15980..45a94c3e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 327 | 152 | 168 | 7 | +| 328 | 152 | 169 | 7 | ### 题目 @@ -324,6 +324,7 @@ |100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | |100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | +|100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From ac9ef450cc54d4754372041c4497cd20548e8013 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 22 Jul 2022 15:16:58 +0800 Subject: [PATCH 0209/1556] src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs --- src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs | 48 +++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs diff --git a/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs b/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs new file mode 100644 index 00000000..d4db6e4f --- /dev/null +++ b/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs @@ -0,0 +1,48 @@ +fn main() { + println!("{}", Solution::num_ways(2)); + println!("{}", Solution::num_ways(7)); + println!("{}", Solution::num_ways(0)); +} + +struct Solution; + +impl Solution { + pub fn num_ways1(n: i32) -> i32 { + let mut v = vec![0; n as usize + 1]; + Self::calc(n, &mut v); + *v.last().unwrap() + } + + fn calc(n: i32, map: &mut [i32]) { + if n <= 1 { + map[n as usize] = 1; + return; + } + + if map[n as usize - 1] == 0 { + Solution::calc(n - 1, map); + } + + if map[n as usize - 2] == 0 { + Solution::calc(n - 2, map); + } + + map[n as usize] = (map[n as usize - 1] + map[n as usize - 2]) % 1000000007; + } + + pub fn num_ways(n: i32) -> i32 { + if n <= 1 { + return 1; + } + + let (mut a, mut b) = (1, 1); + + for _ in 2..=n { + let x = (a + b) % 1000000007; + a = b; + b = x; + } + + b + } +} From 1f243c061d221d8e87582d508f5b1b15da14d715 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 22 Jul 2022 15:16:58 +0800 Subject: [PATCH 0210/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 45a94c3e..21ad8d20 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 328 | 152 | 169 | 7 | +| 329 | 153 | 169 | 7 | ### 题目 @@ -321,6 +321,7 @@ |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | +|100277 | 青蛙跳台阶问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) | Easy | |100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | |100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | From bedc6116d8a8ecfeb691515b3d53172b0be12cab Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:24:57 +0800 Subject: [PATCH 0211/1556] add lint ignore --- src/file.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/file.rs b/src/file.rs index 5d8ca82e..42afa948 100644 --- a/src/file.rs +++ b/src/file.rs @@ -52,7 +52,9 @@ pub fn write_question(resp: Resp) { let mut f = File::create(file.as_str()).unwrap(); let mut s = String::new(); - s.push_str("fn main() {}\n\nstruct Solution;\n\n"); + s.push_str("#![allow(dead_code, unused, unused_variables)]\n\n"); + s.push_str("fn main() {}\n\n"); + s.push_str("struct Solution;\n\n"); for i in resp.data.question.code_snippets { if i.lang == "Rust" { From 23894241fb5200dd1cd15b11a3a252983e98a263 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:27 +0800 Subject: [PATCH 0212/1556] src/bin/2-keys-keyboard.rs --- src/bin/2-keys-keyboard.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/2-keys-keyboard.rs b/src/bin/2-keys-keyboard.rs index 1c8a7c8f..0b28f797 100644 --- a/src/bin/2-keys-keyboard.rs +++ b/src/bin/2-keys-keyboard.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(3, Solution::min_steps(3)); assert_eq!(7, Solution::min_steps(10)); From ee235e72e364b906efd92038b4d2384c1d3138f5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:28 +0800 Subject: [PATCH 0213/1556] src/bin/3sum-closest.rs --- src/bin/3sum-closest.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/3sum-closest.rs b/src/bin/3sum-closest.rs index 2f82117a..ad6d4427 100644 --- a/src/bin/3sum-closest.rs +++ b/src/bin/3sum-closest.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From a9ccbaac78cf65fd9d775b9893c19f911af058d5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:28 +0800 Subject: [PATCH 0214/1556] src/bin/3sum.rs --- src/bin/3sum.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/3sum.rs b/src/bin/3sum.rs index 23bae7eb..f44cf40a 100644 --- a/src/bin/3sum.rs +++ b/src/bin/3sum.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { // println!("{:?}", Solution::three_sum(vec![0, 0, 0, 0])); // println!("{:?}", Solution::three_sum(vec![-1, 0, 1, 2, -1, -4])); From 7b3e9e70569cccded95c640306658e093ea10641 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:29 +0800 Subject: [PATCH 0215/1556] src/bin/4sum.rs --- src/bin/4sum.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/4sum.rs b/src/bin/4sum.rs index 751401f5..81e07565 100644 --- a/src/bin/4sum.rs +++ b/src/bin/4sum.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{:?}", Solution::four_sum(vec![1, 0, -1, 0, -2, 2], 0)); println!("{:?}", Solution::four_sum(vec![0, 0, 0, 0], 0)); From 2b5fe8d1087a3f3f9b6cc563694e805ad87ee3ee Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:29 +0800 Subject: [PATCH 0216/1556] src/bin/add-binary.rs --- src/bin/add-binary.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/add-binary.rs b/src/bin/add-binary.rs index 5dcd3f91..96319c52 100644 --- a/src/bin/add-binary.rs +++ b/src/bin/add-binary.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 57f84ac295103888a0fdafc3e3a85d6ad29e0c02 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:30 +0800 Subject: [PATCH 0217/1556] src/bin/add-digits.rs --- src/bin/add-digits.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/add-digits.rs b/src/bin/add-digits.rs index 383505fa..696ba075 100644 --- a/src/bin/add-digits.rs +++ b/src/bin/add-digits.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::add_digits(38)); println!("{}", Solution::add_digits(3143243)); From 66646c2a5dfc95738d08ad1d1977b021655450a4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:30 +0800 Subject: [PATCH 0218/1556] src/bin/add-one-row-to-tree.rs --- src/bin/add-one-row-to-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/add-one-row-to-tree.rs b/src/bin/add-one-row-to-tree.rs index a69f6362..e712dcda 100644 --- a/src/bin/add-one-row-to-tree.rs +++ b/src/bin/add-one-row-to-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From a5a81abdb6157b9b733a85d15ab4c540854e385f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:31 +0800 Subject: [PATCH 0219/1556] src/bin/add-strings.rs --- src/bin/add-strings.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/add-strings.rs b/src/bin/add-strings.rs index 5a61bd7e..2c6f990d 100644 --- a/src/bin/add-strings.rs +++ b/src/bin/add-strings.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 03cfc0d76e932fbb921e695e55bcb547988f634f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:31 +0800 Subject: [PATCH 0220/1556] src/bin/add-two-numbers-ii.rs --- src/bin/add-two-numbers-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/add-two-numbers-ii.rs b/src/bin/add-two-numbers-ii.rs index 63aba2af..d5151644 100644 --- a/src/bin/add-two-numbers-ii.rs +++ b/src/bin/add-two-numbers-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + use std::borrow::Borrow; fn main() {} From d6d4d8f25e1662e8448ea413cd4a99cf5e80d4a0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:32 +0800 Subject: [PATCH 0221/1556] src/bin/add-two-numbers.rs --- src/bin/add-two-numbers.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/add-two-numbers.rs b/src/bin/add-two-numbers.rs index 7f5f9452..94078959 100644 --- a/src/bin/add-two-numbers.rs +++ b/src/bin/add-two-numbers.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 33c601cfcdddfbbfbc899f8c41efbed19eaaae83 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:32 +0800 Subject: [PATCH 0222/1556] src/bin/airplane-seat-assignment-probability.rs --- src/bin/airplane-seat-assignment-probability.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/airplane-seat-assignment-probability.rs b/src/bin/airplane-seat-assignment-probability.rs index 9417cb99..eb9db8cd 100644 --- a/src/bin/airplane-seat-assignment-probability.rs +++ b/src/bin/airplane-seat-assignment-probability.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From f2504166f1eb27beb6d680621e83813d6f2765d2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:33 +0800 Subject: [PATCH 0223/1556] src/bin/alphabet-board-path.rs --- src/bin/alphabet-board-path.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/alphabet-board-path.rs b/src/bin/alphabet-board-path.rs index 9857dac7..c4e815f3 100644 --- a/src/bin/alphabet-board-path.rs +++ b/src/bin/alphabet-board-path.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 8ac7da78713859690b80774016570dd201ad9e60 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:34 +0800 Subject: [PATCH 0224/1556] src/bin/arithmetic-slices.rs --- src/bin/arithmetic-slices.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/arithmetic-slices.rs b/src/bin/arithmetic-slices.rs index f4a1c5d2..2c709f42 100644 --- a/src/bin/arithmetic-slices.rs +++ b/src/bin/arithmetic-slices.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!( "{}", From 48d434624cc294bcbf182b009c7cb07cd6af38ff Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:43 +0800 Subject: [PATCH 0225/1556] src/bin/array-nesting.rs --- src/bin/array-nesting.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/array-nesting.rs b/src/bin/array-nesting.rs index 137e4a1a..53151edf 100644 --- a/src/bin/array-nesting.rs +++ b/src/bin/array-nesting.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(4, Solution::array_nesting(vec![5, 4, 0, 3, 1, 6, 2])); } From 85593d25cc4efef63d155d1d9861882f6e03ee9a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:44 +0800 Subject: [PATCH 0226/1556] src/bin/average-of-levels-in-binary-tree.rs --- src/bin/average-of-levels-in-binary-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/average-of-levels-in-binary-tree.rs b/src/bin/average-of-levels-in-binary-tree.rs index d4c635a5..f3fa0aa3 100644 --- a/src/bin/average-of-levels-in-binary-tree.rs +++ b/src/bin/average-of-levels-in-binary-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 0d2756ab4d6f07fde4705d5ab09faf3169d36dbf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:44 +0800 Subject: [PATCH 0227/1556] src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs --- src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs b/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs index c3602110..3da1be8f 100644 --- a/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs +++ b/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 5b605b0811a88469a9e0a190a2f22ff2e073154d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:45 +0800 Subject: [PATCH 0228/1556] src/bin/balanced-binary-tree.rs --- src/bin/balanced-binary-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/balanced-binary-tree.rs b/src/bin/balanced-binary-tree.rs index ccd236c4..6c16aad6 100644 --- a/src/bin/balanced-binary-tree.rs +++ b/src/bin/balanced-binary-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From f4f7072795d91ea1625318b9d34e519f5841b485 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:45 +0800 Subject: [PATCH 0229/1556] src/bin/base-7.rs --- src/bin/base-7.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/base-7.rs b/src/bin/base-7.rs index 5154b788..5c19f73a 100644 --- a/src/bin/base-7.rs +++ b/src/bin/base-7.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!("202".to_string(), Solution::convert_to_base7(100)); assert_eq!("-10".to_string(), Solution::convert_to_base7(-7)); From b1e567c6d7249572eb3dc61ce82d560b1574a57b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:46 +0800 Subject: [PATCH 0230/1556] src/bin/battleships-in-a-board.rs --- src/bin/battleships-in-a-board.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/battleships-in-a-board.rs b/src/bin/battleships-in-a-board.rs index fcb5316f..0410fbc9 100644 --- a/src/bin/battleships-in-a-board.rs +++ b/src/bin/battleships-in-a-board.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From a8c8c0669fb19fe1261b364704d71aa652b0b811 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:46 +0800 Subject: [PATCH 0231/1556] src/bin/best-time-to-buy-and-sell-stock-ii.rs --- src/bin/best-time-to-buy-and-sell-stock-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/best-time-to-buy-and-sell-stock-ii.rs b/src/bin/best-time-to-buy-and-sell-stock-ii.rs index b5faa6d9..1068536d 100644 --- a/src/bin/best-time-to-buy-and-sell-stock-ii.rs +++ b/src/bin/best-time-to-buy-and-sell-stock-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(7, Solution::max_profit(vec![7, 1, 5, 3, 6, 4])); assert_eq!(4, Solution::max_profit(vec![1, 2, 3, 4, 5])); From 3fff08e61bea2d781cad398c734e3a2808291806 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:50 +0800 Subject: [PATCH 0232/1556] src/bin/best-time-to-buy-and-sell-stock.rs --- src/bin/best-time-to-buy-and-sell-stock.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/best-time-to-buy-and-sell-stock.rs b/src/bin/best-time-to-buy-and-sell-stock.rs index 84059e17..4e03c68e 100644 --- a/src/bin/best-time-to-buy-and-sell-stock.rs +++ b/src/bin/best-time-to-buy-and-sell-stock.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 465a02142cbe36170bc3cc853659fb663b6ea3c0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 11:43:50 +0800 Subject: [PATCH 0233/1556] src/bin/binary-search-tree-iterator.rs --- src/bin/binary-search-tree-iterator.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/binary-search-tree-iterator.rs b/src/bin/binary-search-tree-iterator.rs index a530936e..cd0a3604 100644 --- a/src/bin/binary-search-tree-iterator.rs +++ b/src/bin/binary-search-tree-iterator.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 2b6961de42fe289fdd0b2a67dbacb569f98a1158 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:37 +0800 Subject: [PATCH 0234/1556] src/bin/binary-tree-inorder-traversal.rs --- src/bin/binary-tree-inorder-traversal.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/binary-tree-inorder-traversal.rs b/src/bin/binary-tree-inorder-traversal.rs index 0e30d888..b5e00789 100644 --- a/src/bin/binary-tree-inorder-traversal.rs +++ b/src/bin/binary-tree-inorder-traversal.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 0f3ec2b0cabded7e5f374b527d5e1bf30f394de3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:37 +0800 Subject: [PATCH 0235/1556] src/bin/binary-tree-level-order-traversal-ii.rs --- src/bin/binary-tree-level-order-traversal-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/binary-tree-level-order-traversal-ii.rs b/src/bin/binary-tree-level-order-traversal-ii.rs index 8bdbc753..2d038797 100644 --- a/src/bin/binary-tree-level-order-traversal-ii.rs +++ b/src/bin/binary-tree-level-order-traversal-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From b7b54050682b1f0196f496b0d1b4f19fec7debdd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:38 +0800 Subject: [PATCH 0236/1556] src/bin/binary-tree-level-order-traversal.rs --- src/bin/binary-tree-level-order-traversal.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/binary-tree-level-order-traversal.rs b/src/bin/binary-tree-level-order-traversal.rs index 8e36fcd3..a944be31 100644 --- a/src/bin/binary-tree-level-order-traversal.rs +++ b/src/bin/binary-tree-level-order-traversal.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 16f60ff6285a265dda9208284bf66761821f41ef Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:38 +0800 Subject: [PATCH 0237/1556] src/bin/binary-tree-paths.rs --- src/bin/binary-tree-paths.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/binary-tree-paths.rs b/src/bin/binary-tree-paths.rs index b3f2a562..78e53652 100644 --- a/src/bin/binary-tree-paths.rs +++ b/src/bin/binary-tree-paths.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From b22e0e67e3ad3162de3a4e0e893e39e77057bd0c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:38 +0800 Subject: [PATCH 0238/1556] src/bin/binary-tree-postorder-traversal.rs --- src/bin/binary-tree-postorder-traversal.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/binary-tree-postorder-traversal.rs b/src/bin/binary-tree-postorder-traversal.rs index a32a9a6f..e9e9a6c0 100644 --- a/src/bin/binary-tree-postorder-traversal.rs +++ b/src/bin/binary-tree-postorder-traversal.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 7494329287869bab2662f4625eb51fd693e01d9f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:39 +0800 Subject: [PATCH 0239/1556] src/bin/binary-tree-preorder-traversal.rs --- src/bin/binary-tree-preorder-traversal.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/binary-tree-preorder-traversal.rs b/src/bin/binary-tree-preorder-traversal.rs index f43fb062..9e7bdc3a 100644 --- a/src/bin/binary-tree-preorder-traversal.rs +++ b/src/bin/binary-tree-preorder-traversal.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 94534a1c8460006f5ced57bd65432026c2c592ab Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:39 +0800 Subject: [PATCH 0240/1556] src/bin/binary-tree-right-side-view.rs --- src/bin/binary-tree-right-side-view.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/binary-tree-right-side-view.rs b/src/bin/binary-tree-right-side-view.rs index 54543256..3afc9304 100644 --- a/src/bin/binary-tree-right-side-view.rs +++ b/src/bin/binary-tree-right-side-view.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From f53619dd4f607ccd92fd7131c324bd9602da5aee Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:40 +0800 Subject: [PATCH 0241/1556] src/bin/binary-tree-zigzag-level-order-traversal.rs --- src/bin/binary-tree-zigzag-level-order-traversal.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/binary-tree-zigzag-level-order-traversal.rs b/src/bin/binary-tree-zigzag-level-order-traversal.rs index bbf93b88..a5290707 100644 --- a/src/bin/binary-tree-zigzag-level-order-traversal.rs +++ b/src/bin/binary-tree-zigzag-level-order-traversal.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 68b275cf97a45e50f61e52e5127a8135bbc925ac Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:40 +0800 Subject: [PATCH 0242/1556] src/bin/bisect-squares-lcci.rs --- src/bin/bisect-squares-lcci.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/bisect-squares-lcci.rs b/src/bin/bisect-squares-lcci.rs index 0a4e95bd..f37fd093 100644 --- a/src/bin/bisect-squares-lcci.rs +++ b/src/bin/bisect-squares-lcci.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 8c8ea5df17f299ae68b01b79d890faab47e72e11 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:40 +0800 Subject: [PATCH 0243/1556] src/bin/bitwise-and-of-numbers-range.rs --- src/bin/bitwise-and-of-numbers-range.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/bitwise-and-of-numbers-range.rs b/src/bin/bitwise-and-of-numbers-range.rs index ef69291e..90d847d4 100644 --- a/src/bin/bitwise-and-of-numbers-range.rs +++ b/src/bin/bitwise-and-of-numbers-range.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 3b43d97c63a07d9c205ee8da5b562c43e7dccf30 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:41 +0800 Subject: [PATCH 0244/1556] src/bin/boats-to-save-people.rs --- src/bin/boats-to-save-people.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/boats-to-save-people.rs b/src/bin/boats-to-save-people.rs index f1306380..53472957 100644 --- a/src/bin/boats-to-save-people.rs +++ b/src/bin/boats-to-save-people.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { // assert_eq!(3, Solution::num_rescue_boats(vec![3, 2, 2, 1], 3)); // assert_eq!(1, Solution::num_rescue_boats(vec![2, 2], 6)); From e5c697a32346dae6fca0c86685782ab81bae0d70 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:41 +0800 Subject: [PATCH 0245/1556] src/bin/build-an-array-with-stack-operations.rs --- src/bin/build-an-array-with-stack-operations.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/build-an-array-with-stack-operations.rs b/src/bin/build-an-array-with-stack-operations.rs index 1948fb1b..d583f5ad 100644 --- a/src/bin/build-an-array-with-stack-operations.rs +++ b/src/bin/build-an-array-with-stack-operations.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From e8cc5a5182d0572d773391ea7cddb432abdbdbbf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:42 +0800 Subject: [PATCH 0246/1556] src/bin/bulb-switcher.rs --- src/bin/bulb-switcher.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/bulb-switcher.rs b/src/bin/bulb-switcher.rs index 1211d912..511ee708 100644 --- a/src/bin/bulb-switcher.rs +++ b/src/bin/bulb-switcher.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 31e7c05cacef8762c5e2bb584008a6b48c5fb8b2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:42 +0800 Subject: [PATCH 0247/1556] src/bin/can-place-flowers.rs --- src/bin/can-place-flowers.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/can-place-flowers.rs b/src/bin/can-place-flowers.rs index 05822368..f559d60f 100644 --- a/src/bin/can-place-flowers.rs +++ b/src/bin/can-place-flowers.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 793103c6f572104995ea2dff0e2fad49e035b737 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:42 +0800 Subject: [PATCH 0248/1556] src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs --- ...ck-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs b/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs index f7adbef8..76183eaf 100644 --- a/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs +++ b/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!( 2, From e183525a9b12dccc050694f4ae4d9348ac34afe5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:43 +0800 Subject: [PATCH 0249/1556] src/bin/check-if-array-pairs-are-divisible-by-k.rs --- src/bin/check-if-array-pairs-are-divisible-by-k.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/check-if-array-pairs-are-divisible-by-k.rs b/src/bin/check-if-array-pairs-are-divisible-by-k.rs index f019bd7d..75232925 100644 --- a/src/bin/check-if-array-pairs-are-divisible-by-k.rs +++ b/src/bin/check-if-array-pairs-are-divisible-by-k.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 8b3ba331fff622cb5c7afbcb7d23cda1c618c860 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:43 +0800 Subject: [PATCH 0250/1556] src/bin/check-if-n-and-its-double-exist.rs --- src/bin/check-if-n-and-its-double-exist.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/check-if-n-and-its-double-exist.rs b/src/bin/check-if-n-and-its-double-exist.rs index 03236e99..0ff2faa8 100644 --- a/src/bin/check-if-n-and-its-double-exist.rs +++ b/src/bin/check-if-n-and-its-double-exist.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From b0ceba436f1c22603ca2553eec21c0bb47105190 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:44 +0800 Subject: [PATCH 0251/1556] src/bin/chuan-di-xin-xi.rs --- src/bin/chuan-di-xin-xi.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/chuan-di-xin-xi.rs b/src/bin/chuan-di-xin-xi.rs index f3a84b30..26fb8a94 100644 --- a/src/bin/chuan-di-xin-xi.rs +++ b/src/bin/chuan-di-xin-xi.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let relation = vec![ vec![0, 2], From 39cf1ac36a1f31a72ef2d6d801432180497df5f7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:44 +0800 Subject: [PATCH 0252/1556] src/bin/climbing-stairs.rs --- src/bin/climbing-stairs.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/climbing-stairs.rs b/src/bin/climbing-stairs.rs index e887afd8..6bb8a202 100644 --- a/src/bin/climbing-stairs.rs +++ b/src/bin/climbing-stairs.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 337ae0704d9ace5e8177db666eac7081dc3084bb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:45 +0800 Subject: [PATCH 0253/1556] src/bin/coin-change.rs --- src/bin/coin-change.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/coin-change.rs b/src/bin/coin-change.rs index 4bb09c54..f3974ba5 100644 --- a/src/bin/coin-change.rs +++ b/src/bin/coin-change.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::coin_change(vec![1, 2, 5], 11)); println!("{}", Solution::coin_change(vec![1], 1)); From e2f3fc882aa74836075496088fb52a2537e376f0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:45 +0800 Subject: [PATCH 0254/1556] src/bin/combination-sum-iii.rs --- src/bin/combination-sum-iii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/combination-sum-iii.rs b/src/bin/combination-sum-iii.rs index 8fd8108d..b7b4c4c3 100644 --- a/src/bin/combination-sum-iii.rs +++ b/src/bin/combination-sum-iii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{:?}", Solution::combination_sum3(3, 9)); println!("{:?}", Solution::combination_sum3(3, 7)); From 1ff3f8178e54a062ab838b56e2cb9725faaf6035 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:45 +0800 Subject: [PATCH 0255/1556] src/bin/combination-sum.rs --- src/bin/combination-sum.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/combination-sum.rs b/src/bin/combination-sum.rs index 42b0463e..fc53fa78 100644 --- a/src/bin/combination-sum.rs +++ b/src/bin/combination-sum.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From e4df0d30a693fa3117e7ada12d58c3eb7b58a304 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:46 +0800 Subject: [PATCH 0256/1556] src/bin/combinations.rs --- src/bin/combinations.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/combinations.rs b/src/bin/combinations.rs index 72f6724b..6a36b1bc 100644 --- a/src/bin/combinations.rs +++ b/src/bin/combinations.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{:?}", Solution::combine(4, 2)); } From ab6b6c7e7d960fd397047581a58a8c62f672c7c4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:46 +0800 Subject: [PATCH 0257/1556] src/bin/compare-version-numbers.rs --- src/bin/compare-version-numbers.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/compare-version-numbers.rs b/src/bin/compare-version-numbers.rs index 5e5b3baf..f3e0c014 100644 --- a/src/bin/compare-version-numbers.rs +++ b/src/bin/compare-version-numbers.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From b69c3b8336627fba9a9d33749e0d5806e422ef12 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:47 +0800 Subject: [PATCH 0258/1556] src/bin/complement-of-base-10-integer.rs --- src/bin/complement-of-base-10-integer.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/complement-of-base-10-integer.rs b/src/bin/complement-of-base-10-integer.rs index bfeeb9ef..de84fa38 100644 --- a/src/bin/complement-of-base-10-integer.rs +++ b/src/bin/complement-of-base-10-integer.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 615fee498248e823337486afaf1e6f6386237e9f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:47 +0800 Subject: [PATCH 0259/1556] src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs --- src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs b/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs index 745e54e7..ca794c45 100644 --- a/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs +++ b/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From bcbcb33317fa679bdf702556a23d1160b2ef7900 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:48 +0800 Subject: [PATCH 0260/1556] src/bin/construct-binary-search-tree-from-preorder-traversal.rs --- src/bin/construct-binary-search-tree-from-preorder-traversal.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/construct-binary-search-tree-from-preorder-traversal.rs b/src/bin/construct-binary-search-tree-from-preorder-traversal.rs index 8c505305..5c550eae 100644 --- a/src/bin/construct-binary-search-tree-from-preorder-traversal.rs +++ b/src/bin/construct-binary-search-tree-from-preorder-traversal.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let v = vec![1, 23, 2, 25, 12, 6]; Solution::bst_from_preorder(v); From 82414945b502d89319d70bc20ec56c459f62157b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:48 +0800 Subject: [PATCH 0261/1556] src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs --- ...onstruct-binary-tree-from-inorder-and-postorder-traversal.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs b/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs index 317993af..598edecb 100644 --- a/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs +++ b/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 4d9accaed266f11d990b7f201769f65ba3441f08 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:49 +0800 Subject: [PATCH 0262/1556] src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs --- ...construct-binary-tree-from-preorder-and-inorder-traversal.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs b/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs index 691d4315..dbc49560 100644 --- a/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs +++ b/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From b266aac44614fba5bbde06972483bb8e40069a0b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:49 +0800 Subject: [PATCH 0263/1556] src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs --- ...nstruct-binary-tree-from-preorder-and-postorder-traversal.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs b/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs index 260bbacd..2cbbd280 100644 --- a/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs +++ b/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { Solution::construct_from_pre_post(vec![1, 2, 4, 5, 3, 6, 7], vec![4, 5, 2, 6, 7, 3, 1]); } From b89d32218bbaa1c9892b69830431d4655dea1b8f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:49 +0800 Subject: [PATCH 0264/1556] src/bin/container-with-most-water.rs --- src/bin/container-with-most-water.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/container-with-most-water.rs b/src/bin/container-with-most-water.rs index 5abba608..029da294 100644 --- a/src/bin/container-with-most-water.rs +++ b/src/bin/container-with-most-water.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(49, Solution::max_area(vec![1, 8, 6, 2, 5, 4, 8, 3, 7])); assert_eq!(16, Solution::max_area(vec![4, 3, 2, 1, 4])); From 070aa2d4939a74a6610132de91be5fdafb318ddb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:50 +0800 Subject: [PATCH 0265/1556] src/bin/contains-duplicate-ii.rs --- src/bin/contains-duplicate-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/contains-duplicate-ii.rs b/src/bin/contains-duplicate-ii.rs index ec5822f1..830918fd 100644 --- a/src/bin/contains-duplicate-ii.rs +++ b/src/bin/contains-duplicate-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 88993bf05f04035d9f08bc9a89dce273aae2938e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:50 +0800 Subject: [PATCH 0266/1556] src/bin/contains-duplicate.rs --- src/bin/contains-duplicate.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/contains-duplicate.rs b/src/bin/contains-duplicate.rs index 0635fb30..e9844409 100644 --- a/src/bin/contains-duplicate.rs +++ b/src/bin/contains-duplicate.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From b78f0abfed738af149216608b1ed2c6ca41d2155 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:51 +0800 Subject: [PATCH 0267/1556] src/bin/convert-binary-number-in-a-linked-list-to-integer.rs --- src/bin/convert-binary-number-in-a-linked-list-to-integer.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs b/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs index 17f331a5..de813ef5 100644 --- a/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs +++ b/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 45edb2603cb882564ee78b7de89df0bc5bbab687 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:51 +0800 Subject: [PATCH 0268/1556] src/bin/convert-sorted-array-to-binary-search-tree.rs --- src/bin/convert-sorted-array-to-binary-search-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/convert-sorted-array-to-binary-search-tree.rs b/src/bin/convert-sorted-array-to-binary-search-tree.rs index f4e288d3..a6cf1bbc 100644 --- a/src/bin/convert-sorted-array-to-binary-search-tree.rs +++ b/src/bin/convert-sorted-array-to-binary-search-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 8bfcdd55ddc3275d6ccd1ba3d3112567bc843bf8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:51 +0800 Subject: [PATCH 0269/1556] src/bin/count-and-say.rs --- src/bin/count-and-say.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/count-and-say.rs b/src/bin/count-and-say.rs index 7e9b0065..7a3ab124 100644 --- a/src/bin/count-and-say.rs +++ b/src/bin/count-and-say.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!("1211".to_string(), Solution::count_and_say(4)); } From 8d22b0264d0168625fdf38c1d0558a4cebb472ec Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:52 +0800 Subject: [PATCH 0270/1556] src/bin/count-complete-tree-nodes.rs --- src/bin/count-complete-tree-nodes.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/count-complete-tree-nodes.rs b/src/bin/count-complete-tree-nodes.rs index d321065e..342a5739 100644 --- a/src/bin/count-complete-tree-nodes.rs +++ b/src/bin/count-complete-tree-nodes.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 288fec7ee1f8d18142fa384ad6cac4bf2d29d2eb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:52 +0800 Subject: [PATCH 0271/1556] src/bin/count-good-triplets.rs --- src/bin/count-good-triplets.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/count-good-triplets.rs b/src/bin/count-good-triplets.rs index 8ff70bef..3b0120d3 100644 --- a/src/bin/count-good-triplets.rs +++ b/src/bin/count-good-triplets.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", !10); } From 93adabefba9a3e57bdec6b1be6a59a212034d6fe Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:53 +0800 Subject: [PATCH 0272/1556] src/bin/count-number-of-nice-subarrays.rs --- src/bin/count-number-of-nice-subarrays.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/count-number-of-nice-subarrays.rs b/src/bin/count-number-of-nice-subarrays.rs index a809e08d..0759e1a4 100644 --- a/src/bin/count-number-of-nice-subarrays.rs +++ b/src/bin/count-number-of-nice-subarrays.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!( "{}", From a56b77a40e43248e1ff4a0696eaffcd6ad024497 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:53 +0800 Subject: [PATCH 0273/1556] src/bin/count-numbers-with-unique-digits.rs --- src/bin/count-numbers-with-unique-digits.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/count-numbers-with-unique-digits.rs b/src/bin/count-numbers-with-unique-digits.rs index f0d7ce3f..8ec37450 100644 --- a/src/bin/count-numbers-with-unique-digits.rs +++ b/src/bin/count-numbers-with-unique-digits.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::count_numbers_with_unique_digits(2)); println!("{}", Solution::count_numbers_with_unique_digits(8)); From 4a57b320751ce62c46b748c97fa18cab234aefac Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:54 +0800 Subject: [PATCH 0274/1556] src/bin/count-of-matches-in-tournament.rs --- src/bin/count-of-matches-in-tournament.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/count-of-matches-in-tournament.rs b/src/bin/count-of-matches-in-tournament.rs index 0800063a..184744ac 100644 --- a/src/bin/count-of-matches-in-tournament.rs +++ b/src/bin/count-of-matches-in-tournament.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(6, Solution::number_of_matches(7)); } From 6b927356b78200be2ed6d6009fc1a4d2a8a3640b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:54 +0800 Subject: [PATCH 0275/1556] src/bin/count-primes.rs --- src/bin/count-primes.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/count-primes.rs b/src/bin/count-primes.rs index ba748b68..20b2a22e 100644 --- a/src/bin/count-primes.rs +++ b/src/bin/count-primes.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(4, Solution::count_primes(10)); } From 689162722ee3ba2ea94116b70a39d033c16bdac3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:54 +0800 Subject: [PATCH 0276/1556] src/bin/decode-ways.rs --- src/bin/decode-ways.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/decode-ways.rs b/src/bin/decode-ways.rs index 36b1cf10..f7ded205 100644 --- a/src/bin/decode-ways.rs +++ b/src/bin/decode-ways.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::num_decodings("12".to_string())); println!("{}", Solution::num_decodings("06".to_string())); From bfdeecdb0c273e437666b6b4b326e4dd6ea96d53 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:55 +0800 Subject: [PATCH 0277/1556] src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs --- src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs b/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs index cf02432e..a427e181 100644 --- a/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs +++ b/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::freq_alphabets("10#11#12".to_string())); println!("{}", Solution::freq_alphabets("1326#".to_string())); From 66e7835e6e1cdd91bcdeab06884e8c0a21489edf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:55 +0800 Subject: [PATCH 0278/1556] src/bin/delete-columns-to-make-sorted.rs --- src/bin/delete-columns-to-make-sorted.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/delete-columns-to-make-sorted.rs b/src/bin/delete-columns-to-make-sorted.rs index 013f10c0..cca62e95 100644 --- a/src/bin/delete-columns-to-make-sorted.rs +++ b/src/bin/delete-columns-to-make-sorted.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From d655280cad2b2056e952ee0c183ed2f0053622fa Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:56 +0800 Subject: [PATCH 0279/1556] src/bin/design-add-and-search-words-data-structure.rs --- src/bin/design-add-and-search-words-data-structure.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/design-add-and-search-words-data-structure.rs b/src/bin/design-add-and-search-words-data-structure.rs index f08f5eb9..0c19bae7 100644 --- a/src/bin/design-add-and-search-words-data-structure.rs +++ b/src/bin/design-add-and-search-words-data-structure.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 463ac562ca00e76c5554445c7037099bffe78807 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:56 +0800 Subject: [PATCH 0280/1556] src/bin/design-circular-queue.rs --- src/bin/design-circular-queue.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/design-circular-queue.rs b/src/bin/design-circular-queue.rs index d8d5720d..d1d3c0e2 100644 --- a/src/bin/design-circular-queue.rs +++ b/src/bin/design-circular-queue.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} /** From d97ca8dcb89d3899c50d51ed4d5e2576a7cb1877 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:57 +0800 Subject: [PATCH 0281/1556] src/bin/detect-capital.rs --- src/bin/detect-capital.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/detect-capital.rs b/src/bin/detect-capital.rs index f4344b9f..54d80216 100644 --- a/src/bin/detect-capital.rs +++ b/src/bin/detect-capital.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 3b18f8ec853af1b3f9451b368e5e1b5c7aeae78b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:57 +0800 Subject: [PATCH 0282/1556] src/bin/di-string-match.rs --- src/bin/di-string-match.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/di-string-match.rs b/src/bin/di-string-match.rs index 26a861ae..d1ed5820 100644 --- a/src/bin/di-string-match.rs +++ b/src/bin/di-string-match.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From e4ef23c6f71eb9beed446b9250453b5991c7eafe Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:57 +0800 Subject: [PATCH 0283/1556] src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs --- src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs b/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs index 1d51fec5..94d495af 100644 --- a/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs +++ b/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From e77c10ef507835f91670a19038d9bb5a5f2d6f94 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:58 +0800 Subject: [PATCH 0284/1556] src/bin/distance-between-bus-stops.rs --- src/bin/distance-between-bus-stops.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/distance-between-bus-stops.rs b/src/bin/distance-between-bus-stops.rs index 545c2c2d..e1a31e17 100644 --- a/src/bin/distance-between-bus-stops.rs +++ b/src/bin/distance-between-bus-stops.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 6af82fe1666c689114ee0ef4a603f642c7c4827e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:58 +0800 Subject: [PATCH 0285/1556] src/bin/diving-board-lcci.rs --- src/bin/diving-board-lcci.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/diving-board-lcci.rs b/src/bin/diving-board-lcci.rs index f1d58a8f..91f6529f 100644 --- a/src/bin/diving-board-lcci.rs +++ b/src/bin/diving-board-lcci.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 5ea0f67442dc533618c9d01673c980d70f4ed883 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:59 +0800 Subject: [PATCH 0286/1556] src/bin/dota2-senate.rs --- src/bin/dota2-senate.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/dota2-senate.rs b/src/bin/dota2-senate.rs index 54ee12d7..ae3cc335 100644 --- a/src/bin/dota2-senate.rs +++ b/src/bin/dota2-senate.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!( "Dire".to_string(), From 328623be6734e7a59c2df0bd13846455170d0e7f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:11:59 +0800 Subject: [PATCH 0287/1556] src/bin/encode-and-decode-tinyurl.rs --- src/bin/encode-and-decode-tinyurl.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/encode-and-decode-tinyurl.rs b/src/bin/encode-and-decode-tinyurl.rs index 91d76e24..ad695077 100644 --- a/src/bin/encode-and-decode-tinyurl.rs +++ b/src/bin/encode-and-decode-tinyurl.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 91e29615ac6a2a0c7f8906b2c4342a36fc2be9ef Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:00 +0800 Subject: [PATCH 0288/1556] src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs --- src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs b/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs index b9bfd87a..b4200298 100644 --- a/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs +++ b/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 67d93dc456f66ae9bf9b6baed7da654cda21c34c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:00 +0800 Subject: [PATCH 0289/1556] src/bin/evaluate-reverse-polish-notation.rs --- src/bin/evaluate-reverse-polish-notation.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/evaluate-reverse-polish-notation.rs b/src/bin/evaluate-reverse-polish-notation.rs index 39b2dc9f..94c913e0 100644 --- a/src/bin/evaluate-reverse-polish-notation.rs +++ b/src/bin/evaluate-reverse-polish-notation.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 968e8c5e3c94e4b362fc9504fca0564584d22c98 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:00 +0800 Subject: [PATCH 0290/1556] src/bin/excel-sheet-column-number.rs --- src/bin/excel-sheet-column-number.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/excel-sheet-column-number.rs b/src/bin/excel-sheet-column-number.rs index 8de0a947..7101263e 100644 --- a/src/bin/excel-sheet-column-number.rs +++ b/src/bin/excel-sheet-column-number.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::title_to_number("AB".to_string())); println!("{}", Solution::title_to_number("ZY".to_string())); From be65256c7dd52631938f3c0ab15091b1d5535637 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:01 +0800 Subject: [PATCH 0291/1556] src/bin/excel-sheet-column-title.rs --- src/bin/excel-sheet-column-title.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/excel-sheet-column-title.rs b/src/bin/excel-sheet-column-title.rs index 418d5fdb..74b7f4f3 100644 --- a/src/bin/excel-sheet-column-title.rs +++ b/src/bin/excel-sheet-column-title.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::convert_to_title(701)); println!("{}", Solution::convert_to_title(27)); From 795568c1d28c0811cd3146cc0f2b19f993291c53 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:01 +0800 Subject: [PATCH 0292/1556] src/bin/factorial-trailing-zeroes.rs --- src/bin/factorial-trailing-zeroes.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/factorial-trailing-zeroes.rs b/src/bin/factorial-trailing-zeroes.rs index 3257f796..865d7607 100644 --- a/src/bin/factorial-trailing-zeroes.rs +++ b/src/bin/factorial-trailing-zeroes.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 7bd19b2fd1b6f471c9d9e3567aed2cb7a4e3f990 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:02 +0800 Subject: [PATCH 0293/1556] src/bin/fair-candy-swap.rs --- src/bin/fair-candy-swap.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/fair-candy-swap.rs b/src/bin/fair-candy-swap.rs index ee84ab84..2f5ce28f 100644 --- a/src/bin/fair-candy-swap.rs +++ b/src/bin/fair-candy-swap.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 13d135a187e185b6c3b06760a07c00d18c00dbc5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:02 +0800 Subject: [PATCH 0294/1556] src/bin/fei-bo-na-qi-shu-lie-lcof.rs --- src/bin/fei-bo-na-qi-shu-lie-lcof.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/fei-bo-na-qi-shu-lie-lcof.rs b/src/bin/fei-bo-na-qi-shu-lie-lcof.rs index d46a7f45..cb987508 100644 --- a/src/bin/fei-bo-na-qi-shu-lie-lcof.rs +++ b/src/bin/fei-bo-na-qi-shu-lie-lcof.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 2698a7762cdcda99c9fc87fca9adf9e3d63e2579 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:03 +0800 Subject: [PATCH 0295/1556] src/bin/find-all-duplicates-in-an-array.rs --- src/bin/find-all-duplicates-in-an-array.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/find-all-duplicates-in-an-array.rs b/src/bin/find-all-duplicates-in-an-array.rs index 2e8d6683..ec212497 100644 --- a/src/bin/find-all-duplicates-in-an-array.rs +++ b/src/bin/find-all-duplicates-in-an-array.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!( "{:?}", From e66aa2e488eb8b193e51f43d4358c945b69ac395 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:03 +0800 Subject: [PATCH 0296/1556] src/bin/find-all-k-distant-indices-in-an-array.rs --- src/bin/find-all-k-distant-indices-in-an-array.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/find-all-k-distant-indices-in-an-array.rs b/src/bin/find-all-k-distant-indices-in-an-array.rs index 4d6ee04a..6e596bb1 100644 --- a/src/bin/find-all-k-distant-indices-in-an-array.rs +++ b/src/bin/find-all-k-distant-indices-in-an-array.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let s = Solution::find_k_distant_indices(vec![3, 4, 9, 1, 3, 9, 5], 9, 1); println!("{s:?}"); From a52aa6680452d39a31089d7b9ef3dd4b625cc21d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:03 +0800 Subject: [PATCH 0297/1556] src/bin/find-all-numbers-disappeared-in-an-array.rs --- src/bin/find-all-numbers-disappeared-in-an-array.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/find-all-numbers-disappeared-in-an-array.rs b/src/bin/find-all-numbers-disappeared-in-an-array.rs index 445285c1..dfbdf7f4 100644 --- a/src/bin/find-all-numbers-disappeared-in-an-array.rs +++ b/src/bin/find-all-numbers-disappeared-in-an-array.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From c085be5ce16202b546451c8a006f4a311e58f6d0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:04 +0800 Subject: [PATCH 0298/1556] src/bin/find-bottom-left-tree-value.rs --- src/bin/find-bottom-left-tree-value.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/find-bottom-left-tree-value.rs b/src/bin/find-bottom-left-tree-value.rs index 62b4bd5a..30960594 100644 --- a/src/bin/find-bottom-left-tree-value.rs +++ b/src/bin/find-bottom-left-tree-value.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 7e7ed0f25543c530858b3f1071dc7ee344bc91c1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:04 +0800 Subject: [PATCH 0299/1556] src/bin/find-elements-in-a-contaminated-binary-tree.rs --- src/bin/find-elements-in-a-contaminated-binary-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/find-elements-in-a-contaminated-binary-tree.rs b/src/bin/find-elements-in-a-contaminated-binary-tree.rs index 7b687867..20bea53b 100644 --- a/src/bin/find-elements-in-a-contaminated-binary-tree.rs +++ b/src/bin/find-elements-in-a-contaminated-binary-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 08d483b15724f4ba33d0dda59bf82c2e59d36e3d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:05 +0800 Subject: [PATCH 0300/1556] src/bin/find-first-and-last-position-of-element-in-sorted-array.rs --- .../find-first-and-last-position-of-element-in-sorted-array.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs b/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs index e166af08..910f11f8 100644 --- a/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs +++ b/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!( vec![3, 4], From 7841433659f17d5f1864d42e0228a235f7289a5f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:05 +0800 Subject: [PATCH 0301/1556] src/bin/find-k-closest-elements.rs --- src/bin/find-k-closest-elements.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/find-k-closest-elements.rs b/src/bin/find-k-closest-elements.rs index 3cca7127..60dbd134 100644 --- a/src/bin/find-k-closest-elements.rs +++ b/src/bin/find-k-closest-elements.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { // assert_eq!(0, Solution::split(&vec![1, 2, 3, 7, 8, 9], 1)); // assert_eq!(1, Solution::split(&vec![1, 2, 3, 7, 8, 9], 2)); From 4a29dc7d7dd416d5b70931827f01a4ccef2aab84 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:06 +0800 Subject: [PATCH 0302/1556] src/bin/find-largest-value-in-each-tree-row.rs --- src/bin/find-largest-value-in-each-tree-row.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/find-largest-value-in-each-tree-row.rs b/src/bin/find-largest-value-in-each-tree-row.rs index 916e02f1..318fa505 100644 --- a/src/bin/find-largest-value-in-each-tree-row.rs +++ b/src/bin/find-largest-value-in-each-tree-row.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From cb48b248b3539df3fc716154e65af14673d71d07 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:06 +0800 Subject: [PATCH 0303/1556] src/bin/find-minimum-in-rotated-sorted-array.rs --- src/bin/find-minimum-in-rotated-sorted-array.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/find-minimum-in-rotated-sorted-array.rs b/src/bin/find-minimum-in-rotated-sorted-array.rs index 47f98410..18fbcf5d 100644 --- a/src/bin/find-minimum-in-rotated-sorted-array.rs +++ b/src/bin/find-minimum-in-rotated-sorted-array.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(1, Solution::find_min(vec![3, 4, 5, 1, 2])); assert_eq!(0, Solution::find_min(vec![4, 5, 6, 7, 0, 1, 2])); From 0b73a97c8d5205b774f629fb09d9f8e565f151ba Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:07 +0800 Subject: [PATCH 0304/1556] src/bin/find-n-unique-integers-sum-up-to-zero.rs --- src/bin/find-n-unique-integers-sum-up-to-zero.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/find-n-unique-integers-sum-up-to-zero.rs b/src/bin/find-n-unique-integers-sum-up-to-zero.rs index 3141c2c6..297d33ec 100644 --- a/src/bin/find-n-unique-integers-sum-up-to-zero.rs +++ b/src/bin/find-n-unique-integers-sum-up-to-zero.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From dc0ab81e38a53b4e96fb97b1d10669d5b1ba7f82 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:08 +0800 Subject: [PATCH 0305/1556] src/bin/find-peak-element.rs --- src/bin/find-peak-element.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/find-peak-element.rs b/src/bin/find-peak-element.rs index f6100431..20e2693f 100644 --- a/src/bin/find-peak-element.rs +++ b/src/bin/find-peak-element.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From da2a95ff8a47dc8545a2628049885dbd1075e12f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:08 +0800 Subject: [PATCH 0306/1556] src/bin/find-the-difference.rs --- src/bin/find-the-difference.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/find-the-difference.rs b/src/bin/find-the-difference.rs index 50628a63..87e8617c 100644 --- a/src/bin/find-the-difference.rs +++ b/src/bin/find-the-difference.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 99aae4535e4a3575e3edc63dfb6a6aef2a1ab90d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:09 +0800 Subject: [PATCH 0307/1556] src/bin/first-bad-version.rs --- src/bin/first-bad-version.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/first-bad-version.rs b/src/bin/first-bad-version.rs index 23990015..7ce7a21d 100644 --- a/src/bin/first-bad-version.rs +++ b/src/bin/first-bad-version.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { // println!("{}", Solution::new(1702766719).first_bad_version(2126753390)); // println!("{}", Solution::new(1).first_bad_version(1)); From e8d5927ab662f39ec1c2fad48a723daf6ff97d92 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:09 +0800 Subject: [PATCH 0308/1556] src/bin/first-missing-positive.rs --- src/bin/first-missing-positive.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/first-missing-positive.rs b/src/bin/first-missing-positive.rs index ac1b611a..1b89468a 100644 --- a/src/bin/first-missing-positive.rs +++ b/src/bin/first-missing-positive.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 3512421c74d00a7031152878a941b045cf841351 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:09 +0800 Subject: [PATCH 0309/1556] src/bin/first-unique-character-in-a-string.rs --- src/bin/first-unique-character-in-a-string.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/first-unique-character-in-a-string.rs b/src/bin/first-unique-character-in-a-string.rs index 04b5f176..369e4eda 100644 --- a/src/bin/first-unique-character-in-a-string.rs +++ b/src/bin/first-unique-character-in-a-string.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 892c6b15a174d103c9c8bb4049fe5e3ad10bd696 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:10 +0800 Subject: [PATCH 0310/1556] src/bin/fizz-buzz.rs --- src/bin/fizz-buzz.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/fizz-buzz.rs b/src/bin/fizz-buzz.rs index 3b4d758c..84094054 100644 --- a/src/bin/fizz-buzz.rs +++ b/src/bin/fizz-buzz.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 52f7dbb0aaedfb90af6d55ab5762f45587eb703f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:10 +0800 Subject: [PATCH 0311/1556] src/bin/fraction-to-recurring-decimal.rs --- src/bin/fraction-to-recurring-decimal.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/fraction-to-recurring-decimal.rs b/src/bin/fraction-to-recurring-decimal.rs index aa1c5387..98c18da2 100644 --- a/src/bin/fraction-to-recurring-decimal.rs +++ b/src/bin/fraction-to-recurring-decimal.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::fraction_to_decimal(1, 2)); println!("{}", Solution::fraction_to_decimal(2, 1)); From eb1e3302c72710f174d4504abb72e73b02549506 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:11 +0800 Subject: [PATCH 0312/1556] src/bin/goal-parser-interpretation.rs --- src/bin/goal-parser-interpretation.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/goal-parser-interpretation.rs b/src/bin/goal-parser-interpretation.rs index 5eaccc65..bbd0fdc6 100644 --- a/src/bin/goal-parser-interpretation.rs +++ b/src/bin/goal-parser-interpretation.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 833bd16bf630fe978e6e587ed82cc84f02be774d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:11 +0800 Subject: [PATCH 0313/1556] src/bin/gray-code.rs --- src/bin/gray-code.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/gray-code.rs b/src/bin/gray-code.rs index bf065b09..4c02bc80 100644 --- a/src/bin/gray-code.rs +++ b/src/bin/gray-code.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{:?}", Solution::gray_code(2)); println!("{:?}", Solution::gray_code(0)); From 86defba56ce15e3a632ea4b7776d32ed3582e4f9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:11 +0800 Subject: [PATCH 0314/1556] src/bin/group-anagrams.rs --- src/bin/group-anagrams.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/group-anagrams.rs b/src/bin/group-anagrams.rs index 2f8aa01f..2a2b3304 100644 --- a/src/bin/group-anagrams.rs +++ b/src/bin/group-anagrams.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From ee33073fb9e99bb6f5ce508c19c56ab2e0fb2629 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:12 +0800 Subject: [PATCH 0315/1556] src/bin/gu-piao-de-zui-da-li-run-lcof.rs --- src/bin/gu-piao-de-zui-da-li-run-lcof.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/gu-piao-de-zui-da-li-run-lcof.rs b/src/bin/gu-piao-de-zui-da-li-run-lcof.rs index 82fbf82d..bbf16511 100644 --- a/src/bin/gu-piao-de-zui-da-li-run-lcof.rs +++ b/src/bin/gu-piao-de-zui-da-li-run-lcof.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 0d80982b5230d2b0de11106b4c4ccc281ff14639 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:12 +0800 Subject: [PATCH 0316/1556] src/bin/guess-number-higher-or-lower.rs --- src/bin/guess-number-higher-or-lower.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/guess-number-higher-or-lower.rs b/src/bin/guess-number-higher-or-lower.rs index c559553b..e5a623e7 100644 --- a/src/bin/guess-number-higher-or-lower.rs +++ b/src/bin/guess-number-higher-or-lower.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + struct Solution; impl Solution { From 9d2ce85a8e440b31867bff40e2f49ac0587554bd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:13 +0800 Subject: [PATCH 0317/1556] src/bin/h-index.rs --- src/bin/h-index.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/h-index.rs b/src/bin/h-index.rs index 6cee39de..56695822 100644 --- a/src/bin/h-index.rs +++ b/src/bin/h-index.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::h_index(vec![3, 0, 6, 1, 5])); println!("{}", Solution::h_index(vec![1])); From 20252d00aa4d6c927315c13141df49537cf0e71f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:13 +0800 Subject: [PATCH 0318/1556] src/bin/happy-number.rs --- src/bin/happy-number.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/happy-number.rs b/src/bin/happy-number.rs index d9625608..c05e6b3d 100644 --- a/src/bin/happy-number.rs +++ b/src/bin/happy-number.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::is_happy(19)); println!("{}", Solution::is_happy(2)); From 8f7dc6fd639620c5e89b2b6ebaa4d443878fd3aa Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:13 +0800 Subject: [PATCH 0319/1556] src/bin/house-robber-ii.rs --- src/bin/house-robber-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/house-robber-ii.rs b/src/bin/house-robber-ii.rs index 78119da5..14ca49f9 100644 --- a/src/bin/house-robber-ii.rs +++ b/src/bin/house-robber-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From e8d08c3c852df7c33d0e7a822d7f450ef0039289 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:14 +0800 Subject: [PATCH 0320/1556] src/bin/house-robber.rs --- src/bin/house-robber.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/house-robber.rs b/src/bin/house-robber.rs index 729d6585..bf80db2b 100644 --- a/src/bin/house-robber.rs +++ b/src/bin/house-robber.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From c56a9fc52f945294427df1f755d1e6406ea4d636 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:14 +0800 Subject: [PATCH 0321/1556] src/bin/how-many-numbers-are-smaller-than-the-current-number.rs --- src/bin/how-many-numbers-are-smaller-than-the-current-number.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs b/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs index eb577bb3..6f31aff0 100644 --- a/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs +++ b/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let s = Solution::smaller_numbers_than_current(vec![8, 1, 2, 2, 3]); println!("{s:?}"); From 26019fbafa7f35c5fb63562731ba3700ab7c920c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:14 +0800 Subject: [PATCH 0322/1556] src/bin/implement-queue-using-stacks.rs --- src/bin/implement-queue-using-stacks.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/implement-queue-using-stacks.rs b/src/bin/implement-queue-using-stacks.rs index 395f5e03..22efe3c0 100644 --- a/src/bin/implement-queue-using-stacks.rs +++ b/src/bin/implement-queue-using-stacks.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From db75037f9396f7309f91dd1b6f7e987820b0acdc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:15 +0800 Subject: [PATCH 0323/1556] src/bin/implement-stack-using-queues.rs --- src/bin/implement-stack-using-queues.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/implement-stack-using-queues.rs b/src/bin/implement-stack-using-queues.rs index d06a2790..9b330aa3 100644 --- a/src/bin/implement-stack-using-queues.rs +++ b/src/bin/implement-stack-using-queues.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 63ef66fd25b645ac16b18eb3629030453c5666f6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:15 +0800 Subject: [PATCH 0324/1556] src/bin/implement-strstr.rs --- src/bin/implement-strstr.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/implement-strstr.rs b/src/bin/implement-strstr.rs index 4b69eb74..9a1e6d41 100644 --- a/src/bin/implement-strstr.rs +++ b/src/bin/implement-strstr.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!( "{:?}", From 59630ad88a292438c94aa4ef604e8e26168e72d3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:16 +0800 Subject: [PATCH 0325/1556] src/bin/implement-trie-prefix-tree.rs --- src/bin/implement-trie-prefix-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/implement-trie-prefix-tree.rs b/src/bin/implement-trie-prefix-tree.rs index dfd8da47..76878cfa 100644 --- a/src/bin/implement-trie-prefix-tree.rs +++ b/src/bin/implement-trie-prefix-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 6b5367c3f4a9ebf045cf48f8ed5dd4a2a0ed40d0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:16 +0800 Subject: [PATCH 0326/1556] src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs --- src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs b/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs index c848dc29..a7db0ddc 100644 --- a/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs +++ b/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + use rand::Rng; fn main() { From bbb8ee2959e060da523f0d230ebad42825c252d2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:16 +0800 Subject: [PATCH 0327/1556] src/bin/insert-delete-getrandom-o1.rs --- src/bin/insert-delete-getrandom-o1.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/insert-delete-getrandom-o1.rs b/src/bin/insert-delete-getrandom-o1.rs index 752c40dc..c7d46cae 100644 --- a/src/bin/insert-delete-getrandom-o1.rs +++ b/src/bin/insert-delete-getrandom-o1.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 7cc4ee6540ef56bdf5f088425c2e964af66c3fa8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:17 +0800 Subject: [PATCH 0328/1556] src/bin/insert-interval.rs --- src/bin/insert-interval.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/insert-interval.rs b/src/bin/insert-interval.rs index df8913e6..c6991585 100644 --- a/src/bin/insert-interval.rs +++ b/src/bin/insert-interval.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From f51a8e1210bf37a2936b80ed73c4dee5014ec49c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:17 +0800 Subject: [PATCH 0329/1556] src/bin/insert-into-a-binary-search-tree.rs --- src/bin/insert-into-a-binary-search-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/insert-into-a-binary-search-tree.rs b/src/bin/insert-into-a-binary-search-tree.rs index 99ee165c..62ec2def 100644 --- a/src/bin/insert-into-a-binary-search-tree.rs +++ b/src/bin/insert-into-a-binary-search-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 48ed79afe585cc219a3c8410847a1645910d779a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:18 +0800 Subject: [PATCH 0330/1556] src/bin/insufficient-nodes-in-root-to-leaf-paths.rs --- src/bin/insufficient-nodes-in-root-to-leaf-paths.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs b/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs index bf06b3d7..4268ad85 100644 --- a/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs +++ b/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From eb940a3e75aa776ad56fa28ca907eb097273cd16 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:18 +0800 Subject: [PATCH 0331/1556] src/bin/integer-replacement.rs --- src/bin/integer-replacement.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/integer-replacement.rs b/src/bin/integer-replacement.rs index 132279c7..2961cb81 100644 --- a/src/bin/integer-replacement.rs +++ b/src/bin/integer-replacement.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::integer_replacement(2147483647)); } From 7373824061c4f62bad331c9f44ca261840c7aa53 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:18 +0800 Subject: [PATCH 0332/1556] src/bin/integer-to-roman.rs --- src/bin/integer-to-roman.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/integer-to-roman.rs b/src/bin/integer-to-roman.rs index 7d819096..c5b1018b 100644 --- a/src/bin/integer-to-roman.rs +++ b/src/bin/integer-to-roman.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { Solution::int_to_roman(23134); } From 81418983e4b396392902fff6924d13f8a5f95d34 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:19 +0800 Subject: [PATCH 0333/1556] src/bin/intersection-of-two-arrays-ii.rs --- src/bin/intersection-of-two-arrays-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/intersection-of-two-arrays-ii.rs b/src/bin/intersection-of-two-arrays-ii.rs index 6074515f..87c1fa0f 100644 --- a/src/bin/intersection-of-two-arrays-ii.rs +++ b/src/bin/intersection-of-two-arrays-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From e37493097a1600c593596e26567550af9bc2061b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:19 +0800 Subject: [PATCH 0334/1556] src/bin/intersection-of-two-arrays.rs --- src/bin/intersection-of-two-arrays.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/intersection-of-two-arrays.rs b/src/bin/intersection-of-two-arrays.rs index 0a6fe9d2..7be3aa5d 100644 --- a/src/bin/intersection-of-two-arrays.rs +++ b/src/bin/intersection-of-two-arrays.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 602897cb6552fb74a1822a344d1c42c0e2426a22 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:20 +0800 Subject: [PATCH 0335/1556] src/bin/invert-binary-tree.rs --- src/bin/invert-binary-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/invert-binary-tree.rs b/src/bin/invert-binary-tree.rs index 0137189c..222bd62b 100644 --- a/src/bin/invert-binary-tree.rs +++ b/src/bin/invert-binary-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From c1268974e803c2119aaafe2dba1baecf995180c0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:20 +0800 Subject: [PATCH 0336/1556] src/bin/is-subsequence.rs --- src/bin/is-subsequence.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/is-subsequence.rs b/src/bin/is-subsequence.rs index 9130871e..d5bd74b9 100644 --- a/src/bin/is-subsequence.rs +++ b/src/bin/is-subsequence.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From bc38e3d3837d1eaa49098ba62564a02dd35718dc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:20 +0800 Subject: [PATCH 0337/1556] src/bin/isomorphic-strings.rs --- src/bin/isomorphic-strings.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/isomorphic-strings.rs b/src/bin/isomorphic-strings.rs index 9e4f7297..fa78bf70 100644 --- a/src/bin/isomorphic-strings.rs +++ b/src/bin/isomorphic-strings.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From cd6c4260969a5b6e37cf974ae8241dbc4f0518f5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:21 +0800 Subject: [PATCH 0338/1556] src/bin/jewels-and-stones.rs --- src/bin/jewels-and-stones.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/jewels-and-stones.rs b/src/bin/jewels-and-stones.rs index 660fc350..ab7a7c5f 100644 --- a/src/bin/jewels-and-stones.rs +++ b/src/bin/jewels-and-stones.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 12a5a275740ffc4aac63018ea4e6e666da78e44c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:21 +0800 Subject: [PATCH 0339/1556] src/bin/jump-game-ii.rs --- src/bin/jump-game-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/jump-game-ii.rs b/src/bin/jump-game-ii.rs index e7ce9db4..a1e072a5 100644 --- a/src/bin/jump-game-ii.rs +++ b/src/bin/jump-game-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::jump(vec![2, 3, 1, 1, 4])); println!("{}", Solution::jump(vec![1, 1, 1, 1])); From 6388ad3993694bf5cac1f499b209c417705480b9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:22 +0800 Subject: [PATCH 0340/1556] src/bin/jump-game-iii.rs --- src/bin/jump-game-iii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/jump-game-iii.rs b/src/bin/jump-game-iii.rs index a21e754d..0157ec0f 100644 --- a/src/bin/jump-game-iii.rs +++ b/src/bin/jump-game-iii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(false, Solution::can_reach(vec![3, 0, 2, 1, 2], 2)); } From af1c55015441cfd2824c794a040158ba8138ffc2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:22 +0800 Subject: [PATCH 0341/1556] src/bin/jump-game.rs --- src/bin/jump-game.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/jump-game.rs b/src/bin/jump-game.rs index 7228ae16..f351350a 100644 --- a/src/bin/jump-game.rs +++ b/src/bin/jump-game.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(true, Solution::can_jump(vec![2, 3, 1, 1, 4])); assert_eq!(false, Solution::can_jump(vec![3, 2, 1, 0, 4])); From 010dcf33b3b40d387e75fc463ee8ef9cf7b700f3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:22 +0800 Subject: [PATCH 0342/1556] src/bin/keyboard-row.rs --- src/bin/keyboard-row.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/keyboard-row.rs b/src/bin/keyboard-row.rs index c87fe848..6c2c3277 100644 --- a/src/bin/keyboard-row.rs +++ b/src/bin/keyboard-row.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!( vec!["Alaska".to_string(), "Dad".to_string()], From c5917eeb42d3611b88117306e5dbd1026e10c085 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:23 +0800 Subject: [PATCH 0343/1556] src/bin/kth-largest-element-in-an-array.rs --- src/bin/kth-largest-element-in-an-array.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/kth-largest-element-in-an-array.rs b/src/bin/kth-largest-element-in-an-array.rs index a2d8b662..3636ad72 100644 --- a/src/bin/kth-largest-element-in-an-array.rs +++ b/src/bin/kth-largest-element-in-an-array.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { Solution::find_kth_largest(vec![1], 1); } From 486708ff01edc84eabe7894aac33eba3223f477b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:23 +0800 Subject: [PATCH 0344/1556] src/bin/kth-smallest-element-in-a-bst.rs --- src/bin/kth-smallest-element-in-a-bst.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/kth-smallest-element-in-a-bst.rs b/src/bin/kth-smallest-element-in-a-bst.rs index bd496c57..8c4b0d3d 100644 --- a/src/bin/kth-smallest-element-in-a-bst.rs +++ b/src/bin/kth-smallest-element-in-a-bst.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From e492f7d3d46b33e259d98d806ad441ff269dec16 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:24 +0800 Subject: [PATCH 0345/1556] src/bin/kth-smallest-element-in-a-sorted-matrix.rs --- src/bin/kth-smallest-element-in-a-sorted-matrix.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/kth-smallest-element-in-a-sorted-matrix.rs b/src/bin/kth-smallest-element-in-a-sorted-matrix.rs index 654263e1..d3b2cbe5 100644 --- a/src/bin/kth-smallest-element-in-a-sorted-matrix.rs +++ b/src/bin/kth-smallest-element-in-a-sorted-matrix.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From f8850480192bc41a282ede43f6250b5a76ce05b3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:24 +0800 Subject: [PATCH 0346/1556] src/bin/least-number-of-unique-integers-after-k-removals.rs --- src/bin/least-number-of-unique-integers-after-k-removals.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/least-number-of-unique-integers-after-k-removals.rs b/src/bin/least-number-of-unique-integers-after-k-removals.rs index 254eae6c..e18401a7 100644 --- a/src/bin/least-number-of-unique-integers-after-k-removals.rs +++ b/src/bin/least-number-of-unique-integers-after-k-removals.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 9f45a2fd15cf517f90f263275c5b5cd8aacd324e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:24 +0800 Subject: [PATCH 0347/1556] src/bin/length-of-last-word.rs --- src/bin/length-of-last-word.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/length-of-last-word.rs b/src/bin/length-of-last-word.rs index a9baca84..6e2fe888 100644 --- a/src/bin/length-of-last-word.rs +++ b/src/bin/length-of-last-word.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From d97934b00b459f994d60b91df810b71d3ceafdb1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:25 +0800 Subject: [PATCH 0348/1556] src/bin/letter-case-permutation.rs --- src/bin/letter-case-permutation.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/letter-case-permutation.rs b/src/bin/letter-case-permutation.rs index e64a96dd..66f0b723 100644 --- a/src/bin/letter-case-permutation.rs +++ b/src/bin/letter-case-permutation.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From f981e23961a95568a07051211d8f1b73ff014dcd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:25 +0800 Subject: [PATCH 0349/1556] src/bin/letter-combinations-of-a-phone-number.rs --- src/bin/letter-combinations-of-a-phone-number.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/letter-combinations-of-a-phone-number.rs b/src/bin/letter-combinations-of-a-phone-number.rs index d553b812..0bfc33b1 100644 --- a/src/bin/letter-combinations-of-a-phone-number.rs +++ b/src/bin/letter-combinations-of-a-phone-number.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 2de496f567746422ab6f8eeeeb46c1a37ed43a47 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:25 +0800 Subject: [PATCH 0350/1556] src/bin/lexicographical-numbers.rs --- src/bin/lexicographical-numbers.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/lexicographical-numbers.rs b/src/bin/lexicographical-numbers.rs index ffd7abc0..c8b92e61 100644 --- a/src/bin/lexicographical-numbers.rs +++ b/src/bin/lexicographical-numbers.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 0d8e6d8c8d6d5f9b9d591ed608c54f856706db6c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:26 +0800 Subject: [PATCH 0351/1556] src/bin/linked-list-random-node.rs --- src/bin/linked-list-random-node.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/linked-list-random-node.rs b/src/bin/linked-list-random-node.rs index 9dc9f8a7..1ac2aff1 100644 --- a/src/bin/linked-list-random-node.rs +++ b/src/bin/linked-list-random-node.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + use rand::Rng; fn main() {} From db6b3f8d9cfa3234706886c03c4e9556e5dde3c1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:27 +0800 Subject: [PATCH 0352/1556] src/bin/longest-common-prefix.rs --- src/bin/longest-common-prefix.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/longest-common-prefix.rs b/src/bin/longest-common-prefix.rs index cfa35042..06cab07b 100644 --- a/src/bin/longest-common-prefix.rs +++ b/src/bin/longest-common-prefix.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!( "fl".to_string(), From e7c9208f67a86722f620bd08ae6c2a85a2be807c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:27 +0800 Subject: [PATCH 0353/1556] src/bin/longest-continuous-increasing-subsequence.rs --- src/bin/longest-continuous-increasing-subsequence.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/longest-continuous-increasing-subsequence.rs b/src/bin/longest-continuous-increasing-subsequence.rs index 54c529a3..f314a30d 100644 --- a/src/bin/longest-continuous-increasing-subsequence.rs +++ b/src/bin/longest-continuous-increasing-subsequence.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(3, Solution::find_length_of_lcis(vec![1, 3, 5, 4, 7])); assert_eq!(1, Solution::find_length_of_lcis(vec![2, 2, 2, 2, 2])); From a90ab0b273d346da78177142d74066a6b01e24e0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:27 +0800 Subject: [PATCH 0354/1556] src/bin/longest-harmonious-subsequence.rs --- src/bin/longest-harmonious-subsequence.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/longest-harmonious-subsequence.rs b/src/bin/longest-harmonious-subsequence.rs index ecf5981c..5a875df2 100644 --- a/src/bin/longest-harmonious-subsequence.rs +++ b/src/bin/longest-harmonious-subsequence.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From b8b0215bd1674c85fdcc78670a53c3f4f01a1783 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:28 +0800 Subject: [PATCH 0355/1556] src/bin/longest-increasing-subsequence.rs --- src/bin/longest-increasing-subsequence.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/longest-increasing-subsequence.rs b/src/bin/longest-increasing-subsequence.rs index dea8a05e..6a8da25e 100644 --- a/src/bin/longest-increasing-subsequence.rs +++ b/src/bin/longest-increasing-subsequence.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!( "{}", From 600347141031315f688b33d4dcf29893f4c8c930 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:28 +0800 Subject: [PATCH 0356/1556] src/bin/longest-palindrome.rs --- src/bin/longest-palindrome.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/longest-palindrome.rs b/src/bin/longest-palindrome.rs index 99615d84..c5200c82 100644 --- a/src/bin/longest-palindrome.rs +++ b/src/bin/longest-palindrome.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 09360d519816ab70618f57118518b23c40395479 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:28 +0800 Subject: [PATCH 0357/1556] src/bin/longest-substring-without-repeating-characters.rs --- src/bin/longest-substring-without-repeating-characters.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/longest-substring-without-repeating-characters.rs b/src/bin/longest-substring-without-repeating-characters.rs index 34be7735..fbc394f4 100644 --- a/src/bin/longest-substring-without-repeating-characters.rs +++ b/src/bin/longest-substring-without-repeating-characters.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(2, Solution::length_of_longest_substring("aab".to_string())); assert_eq!( From 7df914cb1bbc2e6b884787136689a93a8243d7d1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:29 +0800 Subject: [PATCH 0358/1556] src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs --- src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs b/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs index e26564f8..7cf5b89a 100644 --- a/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs +++ b/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 5d6ab39008ccd82c537390827718e73fc8c524c5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:29 +0800 Subject: [PATCH 0359/1556] src/bin/magical-string.rs --- src/bin/magical-string.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/magical-string.rs b/src/bin/magical-string.rs index 78a2d31d..1b86193f 100644 --- a/src/bin/magical-string.rs +++ b/src/bin/magical-string.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 098eb4e947944e1dc23691b1beacdedaae43b7fc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:29 +0800 Subject: [PATCH 0360/1556] src/bin/majority-element-ii.rs --- src/bin/majority-element-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/majority-element-ii.rs b/src/bin/majority-element-ii.rs index da595299..dc27b2ca 100644 --- a/src/bin/majority-element-ii.rs +++ b/src/bin/majority-element-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let s = vec![3, 2, 3, 2, 2, 3, 1, 1, 1]; println!("{:?}", Solution::majority_element1(s)); From 62a387fb5c1db72be227af62662750b15eba0b4e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:30 +0800 Subject: [PATCH 0361/1556] src/bin/majority-element.rs --- src/bin/majority-element.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/majority-element.rs b/src/bin/majority-element.rs index aa1a755d..20362dd1 100644 --- a/src/bin/majority-element.rs +++ b/src/bin/majority-element.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 3265a05fd731062e240544c92aa8a35a3812cc08 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:30 +0800 Subject: [PATCH 0362/1556] src/bin/make-the-string-great.rs --- src/bin/make-the-string-great.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/make-the-string-great.rs b/src/bin/make-the-string-great.rs index e57dded8..d7e64f1a 100644 --- a/src/bin/make-the-string-great.rs +++ b/src/bin/make-the-string-great.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 8b6e4b896bed298a3568ac10f91e4a1a30a4cfcf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:31 +0800 Subject: [PATCH 0363/1556] src/bin/max-consecutive-ones-iii.rs --- src/bin/max-consecutive-ones-iii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/max-consecutive-ones-iii.rs b/src/bin/max-consecutive-ones-iii.rs index e1d20a94..a2730f9e 100644 --- a/src/bin/max-consecutive-ones-iii.rs +++ b/src/bin/max-consecutive-ones-iii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!( 6, From 6d8e228163553453b5762f675321c9caab6a60a2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:31 +0800 Subject: [PATCH 0364/1556] src/bin/max-consecutive-ones.rs --- src/bin/max-consecutive-ones.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/max-consecutive-ones.rs b/src/bin/max-consecutive-ones.rs index c020cd2b..1c182cde 100644 --- a/src/bin/max-consecutive-ones.rs +++ b/src/bin/max-consecutive-ones.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 6287e1a7f5a40b63c1313757b4501c33988e783b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:31 +0800 Subject: [PATCH 0365/1556] src/bin/max-increase-to-keep-city-skyline.rs --- src/bin/max-increase-to-keep-city-skyline.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/max-increase-to-keep-city-skyline.rs b/src/bin/max-increase-to-keep-city-skyline.rs index f0896c8b..69739792 100644 --- a/src/bin/max-increase-to-keep-city-skyline.rs +++ b/src/bin/max-increase-to-keep-city-skyline.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From e8fcff9c7d308acc597315df26f639619427cc5b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:32 +0800 Subject: [PATCH 0366/1556] src/bin/maximum-average-subarray-i.rs --- src/bin/maximum-average-subarray-i.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/maximum-average-subarray-i.rs b/src/bin/maximum-average-subarray-i.rs index c23e4a1b..08f5e9a4 100644 --- a/src/bin/maximum-average-subarray-i.rs +++ b/src/bin/maximum-average-subarray-i.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From aef6c15f8cc90c65b0e4fd852a9055393761a4cd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:32 +0800 Subject: [PATCH 0367/1556] src/bin/maximum-depth-of-binary-tree.rs --- src/bin/maximum-depth-of-binary-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/maximum-depth-of-binary-tree.rs b/src/bin/maximum-depth-of-binary-tree.rs index 7035a903..c080fa06 100644 --- a/src/bin/maximum-depth-of-binary-tree.rs +++ b/src/bin/maximum-depth-of-binary-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 60c7a0e6aa9b5eae6e4616f93260fd22ccb86a4e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:33 +0800 Subject: [PATCH 0368/1556] src/bin/maximum-lcci.rs --- src/bin/maximum-lcci.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/maximum-lcci.rs b/src/bin/maximum-lcci.rs index f15a6848..0aab6ce8 100644 --- a/src/bin/maximum-lcci.rs +++ b/src/bin/maximum-lcci.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(10, Solution::maximum(5, 10)); } From e7785d5ee5f9a57c08ff3c51d8951c8a33ccbf15 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:33 +0800 Subject: [PATCH 0369/1556] src/bin/maximum-length-of-repeated-subarray.rs --- src/bin/maximum-length-of-repeated-subarray.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/maximum-length-of-repeated-subarray.rs b/src/bin/maximum-length-of-repeated-subarray.rs index 56a397f9..fdf0961e 100644 --- a/src/bin/maximum-length-of-repeated-subarray.rs +++ b/src/bin/maximum-length-of-repeated-subarray.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From da933a81bc164c0895c136b667eb35fcbb79ebca Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:33 +0800 Subject: [PATCH 0370/1556] src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs --- .../maximum-number-of-vowels-in-a-substring-of-given-length.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs b/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs index 4c9fcbfd..ebdbc5bb 100644 --- a/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs +++ b/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!( 7, From 90bb1e1462e766109835c817fe86116a658eceb9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:34 +0800 Subject: [PATCH 0371/1556] src/bin/maximum-points-you-can-obtain-from-cards.rs --- src/bin/maximum-points-you-can-obtain-from-cards.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/maximum-points-you-can-obtain-from-cards.rs b/src/bin/maximum-points-you-can-obtain-from-cards.rs index 00346e9c..6688a06d 100644 --- a/src/bin/maximum-points-you-can-obtain-from-cards.rs +++ b/src/bin/maximum-points-you-can-obtain-from-cards.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!( 232, From 9da72a739536a22ce687dda010a6d712460c30a4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:34 +0800 Subject: [PATCH 0372/1556] src/bin/maximum-population-year.rs --- src/bin/maximum-population-year.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/maximum-population-year.rs b/src/bin/maximum-population-year.rs index 6e6a7e71..9ff1032b 100644 --- a/src/bin/maximum-population-year.rs +++ b/src/bin/maximum-population-year.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 7aa555f770a894ab72eb15d44bf416f219c6b217 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:35 +0800 Subject: [PATCH 0373/1556] src/bin/maximum-product-of-word-lengths.rs --- src/bin/maximum-product-of-word-lengths.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/maximum-product-of-word-lengths.rs b/src/bin/maximum-product-of-word-lengths.rs index 5a8a6686..cca9bc4c 100644 --- a/src/bin/maximum-product-of-word-lengths.rs +++ b/src/bin/maximum-product-of-word-lengths.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From ee22c147c62e7024d0f4904d53d56816faab20e7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:35 +0800 Subject: [PATCH 0374/1556] src/bin/maximum-product-subarray.rs --- src/bin/maximum-product-subarray.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/maximum-product-subarray.rs b/src/bin/maximum-product-subarray.rs index 3d40e8e8..a6d7774d 100644 --- a/src/bin/maximum-product-subarray.rs +++ b/src/bin/maximum-product-subarray.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(4, Solution::max_product(vec![3, -1, 4])); assert_eq!(0, Solution::max_product(vec![-2, 0])); From 60c70fe97e3e7a1b6a74d6cc805587742e14f6c5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:35 +0800 Subject: [PATCH 0375/1556] src/bin/maximum-score-after-splitting-a-string.rs --- src/bin/maximum-score-after-splitting-a-string.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/maximum-score-after-splitting-a-string.rs b/src/bin/maximum-score-after-splitting-a-string.rs index 0b641a22..76efae12 100644 --- a/src/bin/maximum-score-after-splitting-a-string.rs +++ b/src/bin/maximum-score-after-splitting-a-string.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 461020d09a26e400d18e2cac4efe125b2b0e1be0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:36 +0800 Subject: [PATCH 0376/1556] src/bin/maximum-subarray.rs --- src/bin/maximum-subarray.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/maximum-subarray.rs b/src/bin/maximum-subarray.rs index 41e518e2..203371ff 100644 --- a/src/bin/maximum-subarray.rs +++ b/src/bin/maximum-subarray.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From ff97eb142546267a35021505c557a49955043c89 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:36 +0800 Subject: [PATCH 0377/1556] src/bin/maximum-width-ramp.rs --- src/bin/maximum-width-ramp.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/maximum-width-ramp.rs b/src/bin/maximum-width-ramp.rs index 34c33a05..86602aaa 100644 --- a/src/bin/maximum-width-ramp.rs +++ b/src/bin/maximum-width-ramp.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From ded5cea18a45a99f1519757a9e421e9866804a1b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:36 +0800 Subject: [PATCH 0378/1556] src/bin/mean-of-array-after-removing-some-elements.rs --- src/bin/mean-of-array-after-removing-some-elements.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/mean-of-array-after-removing-some-elements.rs b/src/bin/mean-of-array-after-removing-some-elements.rs index 3b76b3d0..b118a9f4 100644 --- a/src/bin/mean-of-array-after-removing-some-elements.rs +++ b/src/bin/mean-of-array-after-removing-some-elements.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 787f851fd64ba28906fa8d3c595f1dda3398a9a7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:37 +0800 Subject: [PATCH 0379/1556] src/bin/median-of-two-sorted-arrays.rs --- src/bin/median-of-two-sorted-arrays.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/median-of-two-sorted-arrays.rs b/src/bin/median-of-two-sorted-arrays.rs index a89ed229..600f8e26 100644 --- a/src/bin/median-of-two-sorted-arrays.rs +++ b/src/bin/median-of-two-sorted-arrays.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 92a743470ce79c8e7bd17adcad0fc7dcd84fc62c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:37 +0800 Subject: [PATCH 0380/1556] src/bin/merge-intervals.rs --- src/bin/merge-intervals.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/merge-intervals.rs b/src/bin/merge-intervals.rs index cabae19a..caccbfdb 100644 --- a/src/bin/merge-intervals.rs +++ b/src/bin/merge-intervals.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 6f0e396e88410f6836022608c9f037f8dea50629 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:38 +0800 Subject: [PATCH 0381/1556] src/bin/merge-k-sorted-lists.rs --- src/bin/merge-k-sorted-lists.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/merge-k-sorted-lists.rs b/src/bin/merge-k-sorted-lists.rs index 3195ddf6..9f73933f 100644 --- a/src/bin/merge-k-sorted-lists.rs +++ b/src/bin/merge-k-sorted-lists.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 5fbaf452aa7286c4a9cb2cb4b6ba981e2465adeb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:38 +0800 Subject: [PATCH 0382/1556] src/bin/merge-sorted-array.rs --- src/bin/merge-sorted-array.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/merge-sorted-array.rs b/src/bin/merge-sorted-array.rs index 225c6e7a..9c71ca69 100644 --- a/src/bin/merge-sorted-array.rs +++ b/src/bin/merge-sorted-array.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From ec3fafe5a35e92658e8133d49d4a06100cbd78de Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:39 +0800 Subject: [PATCH 0383/1556] src/bin/merge-two-binary-trees.rs --- src/bin/merge-two-binary-trees.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/merge-two-binary-trees.rs b/src/bin/merge-two-binary-trees.rs index 6bdaaaa3..55861c70 100644 --- a/src/bin/merge-two-binary-trees.rs +++ b/src/bin/merge-two-binary-trees.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 51ea46043b2ca84bf00633c1542f8ed8976b5ce6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:39 +0800 Subject: [PATCH 0384/1556] src/bin/merge-two-sorted-lists.rs --- src/bin/merge-two-sorted-lists.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/merge-two-sorted-lists.rs b/src/bin/merge-two-sorted-lists.rs index 2da24150..6c6273d5 100644 --- a/src/bin/merge-two-sorted-lists.rs +++ b/src/bin/merge-two-sorted-lists.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 38b61655e1f4c6c580b7024c75368fd4ea0f75e5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:40 +0800 Subject: [PATCH 0385/1556] src/bin/min-stack.rs --- src/bin/min-stack.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/min-stack.rs b/src/bin/min-stack.rs index 087dd75c..d89d7676 100644 --- a/src/bin/min-stack.rs +++ b/src/bin/min-stack.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 548daea4b0489d79494e4ab3a2f882211927b414 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:40 +0800 Subject: [PATCH 0386/1556] src/bin/minimum-absolute-difference-in-bst.rs --- src/bin/minimum-absolute-difference-in-bst.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/minimum-absolute-difference-in-bst.rs b/src/bin/minimum-absolute-difference-in-bst.rs index 909e109a..8924607c 100644 --- a/src/bin/minimum-absolute-difference-in-bst.rs +++ b/src/bin/minimum-absolute-difference-in-bst.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From c90ea9c9f0ff04889611336280498b916b523842 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:40 +0800 Subject: [PATCH 0387/1556] src/bin/minimum-absolute-difference.rs --- src/bin/minimum-absolute-difference.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/minimum-absolute-difference.rs b/src/bin/minimum-absolute-difference.rs index 225a2aec..802dd8d7 100644 --- a/src/bin/minimum-absolute-difference.rs +++ b/src/bin/minimum-absolute-difference.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + use std::vec; fn main() {} From c4d3a31bbbea199db4775cf0c0717094964244aa Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:41 +0800 Subject: [PATCH 0388/1556] src/bin/minimum-depth-of-binary-tree.rs --- src/bin/minimum-depth-of-binary-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/minimum-depth-of-binary-tree.rs b/src/bin/minimum-depth-of-binary-tree.rs index 392d280e..9e8a9477 100644 --- a/src/bin/minimum-depth-of-binary-tree.rs +++ b/src/bin/minimum-depth-of-binary-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From d302ad77c4ea36427c71dace6cfd5e3b7b6f8d36 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:41 +0800 Subject: [PATCH 0389/1556] src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs --- src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs b/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs index 787da556..89c358d8 100644 --- a/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs +++ b/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(3, Solution::min_flips(2, 6, 5)); } From 6ab2acdc013e17ce9ede33e3389abf5c91266712 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:41 +0800 Subject: [PATCH 0390/1556] src/bin/minimum-increment-to-make-array-unique.rs --- src/bin/minimum-increment-to-make-array-unique.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/minimum-increment-to-make-array-unique.rs b/src/bin/minimum-increment-to-make-array-unique.rs index d14e400e..22745f8d 100644 --- a/src/bin/minimum-increment-to-make-array-unique.rs +++ b/src/bin/minimum-increment-to-make-array-unique.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(1, Solution::min_increment_for_unique(vec![1, 2, 2])); assert_eq!( From 513e100782c9b890b4e62c439389a0b6a35e13c0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:42 +0800 Subject: [PATCH 0391/1556] src/bin/minimum-path-sum.rs --- src/bin/minimum-path-sum.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/minimum-path-sum.rs b/src/bin/minimum-path-sum.rs index 77b2fa5e..7b0ae8b0 100644 --- a/src/bin/minimum-path-sum.rs +++ b/src/bin/minimum-path-sum.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 7e3ab213049a2ab53a47450ce6ad638408a260da Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:42 +0800 Subject: [PATCH 0392/1556] src/bin/minimum-remove-to-make-valid-parentheses.rs --- src/bin/minimum-remove-to-make-valid-parentheses.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/minimum-remove-to-make-valid-parentheses.rs b/src/bin/minimum-remove-to-make-valid-parentheses.rs index 183b6fa8..8ae7ab40 100644 --- a/src/bin/minimum-remove-to-make-valid-parentheses.rs +++ b/src/bin/minimum-remove-to-make-valid-parentheses.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From ea7bb6ab1585841bfbd5270cb02a4aa13edbd9ff Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:43 +0800 Subject: [PATCH 0393/1556] src/bin/missing-number.rs --- src/bin/missing-number.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/missing-number.rs b/src/bin/missing-number.rs index d770ba9d..4f54f502 100644 --- a/src/bin/missing-number.rs +++ b/src/bin/missing-number.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::missing_number1(vec![3, 0, 1])); println!( From a7a801c190ed22babfd36fd14aacd74b98de358e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:43 +0800 Subject: [PATCH 0394/1556] src/bin/monotonic-array.rs --- src/bin/monotonic-array.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/monotonic-array.rs b/src/bin/monotonic-array.rs index 1653057e..cb3bc0d4 100644 --- a/src/bin/monotonic-array.rs +++ b/src/bin/monotonic-array.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 81026621eb159e4d42ceccfd64c40e6cc3b516e6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:44 +0800 Subject: [PATCH 0395/1556] src/bin/most-frequent-subtree-sum.rs --- src/bin/most-frequent-subtree-sum.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/most-frequent-subtree-sum.rs b/src/bin/most-frequent-subtree-sum.rs index e0b53860..6dafdced 100644 --- a/src/bin/most-frequent-subtree-sum.rs +++ b/src/bin/most-frequent-subtree-sum.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From ef91e45d70b2a8ba27cb9e699e157c55c9892585 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:44 +0800 Subject: [PATCH 0396/1556] src/bin/move-zeroes.rs --- src/bin/move-zeroes.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/move-zeroes.rs b/src/bin/move-zeroes.rs index 44a59073..12dc8ff9 100644 --- a/src/bin/move-zeroes.rs +++ b/src/bin/move-zeroes.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let mut v = vec![0, 1, 0, 3, 12]; Solution::move_zeroes(&mut v); From ae0a4b4f437291a2e82b8d0565b0ca4524545e4f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:44 +0800 Subject: [PATCH 0397/1556] src/bin/multiply-strings.rs --- src/bin/multiply-strings.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/multiply-strings.rs b/src/bin/multiply-strings.rs index 795ab39d..1a03dd86 100644 --- a/src/bin/multiply-strings.rs +++ b/src/bin/multiply-strings.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!( "6".to_string(), From f01b3cdb266c334fa2a81e02b06ead23819081e3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:45 +0800 Subject: [PATCH 0398/1556] src/bin/n-queens-ii.rs --- src/bin/n-queens-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/n-queens-ii.rs b/src/bin/n-queens-ii.rs index a4ae0a28..d2e90b86 100644 --- a/src/bin/n-queens-ii.rs +++ b/src/bin/n-queens-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(92, Solution::total_n_queens(8)); } From 255c490075b3a7fceef2f9cb98d217202208ffe6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:45 +0800 Subject: [PATCH 0399/1556] src/bin/n-queens.rs --- src/bin/n-queens.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/n-queens.rs b/src/bin/n-queens.rs index ae706f06..411f3623 100644 --- a/src/bin/n-queens.rs +++ b/src/bin/n-queens.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From b2500e748bc40313d36851be87772a832bba3ff5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:46 +0800 Subject: [PATCH 0400/1556] src/bin/na-ying-bi.rs --- src/bin/na-ying-bi.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/na-ying-bi.rs b/src/bin/na-ying-bi.rs index e9cb5188..b7deeae3 100644 --- a/src/bin/na-ying-bi.rs +++ b/src/bin/na-ying-bi.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(Solution::min_count(vec![4, 2, 1]), 4); } From d38cccdefa1a5174add9be523088e50c0e2fdeb9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:46 +0800 Subject: [PATCH 0401/1556] src/bin/next-greater-node-in-linked-list.rs --- src/bin/next-greater-node-in-linked-list.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/next-greater-node-in-linked-list.rs b/src/bin/next-greater-node-in-linked-list.rs index 22de1b2b..ae100cd2 100644 --- a/src/bin/next-greater-node-in-linked-list.rs +++ b/src/bin/next-greater-node-in-linked-list.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 2d17f34fc94377eb3257410c4a86cd99a4c93a51 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:46 +0800 Subject: [PATCH 0402/1556] src/bin/next-permutation.rs --- src/bin/next-permutation.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/next-permutation.rs b/src/bin/next-permutation.rs index 5cff6ea0..2c31753c 100644 --- a/src/bin/next-permutation.rs +++ b/src/bin/next-permutation.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let mut v = vec![1, 2, 3]; Solution::next_permutation(&mut v); From 559538913df8f8604635ff00f3f4456d8171b0bb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:47 +0800 Subject: [PATCH 0403/1556] src/bin/nim-game.rs --- src/bin/nim-game.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/nim-game.rs b/src/bin/nim-game.rs index a8cdcb9c..977fcc3c 100644 --- a/src/bin/nim-game.rs +++ b/src/bin/nim-game.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From f4958a94e339b13d566273d54100e52fa841ab65 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:47 +0800 Subject: [PATCH 0404/1556] src/bin/nth-digit.rs --- src/bin/nth-digit.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/nth-digit.rs b/src/bin/nth-digit.rs index 2a98c200..7827d2c9 100644 --- a/src/bin/nth-digit.rs +++ b/src/bin/nth-digit.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::find_nth_digit(1)); println!("{}", Solution::find_nth_digit(2)); From 2f4c243e5d4fd906e558a62b2bf564dba2236e44 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:48 +0800 Subject: [PATCH 0405/1556] src/bin/number-complement.rs --- src/bin/number-complement.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/number-complement.rs b/src/bin/number-complement.rs index bd555552..0b50d95e 100644 --- a/src/bin/number-complement.rs +++ b/src/bin/number-complement.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { // assert_eq!(2, Solution::find_complement(5)); println!("{:#b}", Solution::find_complement(5)); From 028e872de821801d022d43a866b9e03480da5da0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:48 +0800 Subject: [PATCH 0406/1556] src/bin/number-of-1-bits.rs --- src/bin/number-of-1-bits.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/number-of-1-bits.rs b/src/bin/number-of-1-bits.rs index 9d63cfcc..735318c4 100644 --- a/src/bin/number-of-1-bits.rs +++ b/src/bin/number-of-1-bits.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From deaed0dadc605165d5b09cb882b252c8b6c79050 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:48 +0800 Subject: [PATCH 0407/1556] src/bin/number-of-islands.rs --- src/bin/number-of-islands.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/number-of-islands.rs b/src/bin/number-of-islands.rs index 813ff5f6..3e51bbe8 100644 --- a/src/bin/number-of-islands.rs +++ b/src/bin/number-of-islands.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 4c8d2bea5ad631869fa694a84beaa4cd84a0644f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:49 +0800 Subject: [PATCH 0408/1556] src/bin/number-of-segments-in-a-string.rs --- src/bin/number-of-segments-in-a-string.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/number-of-segments-in-a-string.rs b/src/bin/number-of-segments-in-a-string.rs index 39af396b..7994b0e8 100644 --- a/src/bin/number-of-segments-in-a-string.rs +++ b/src/bin/number-of-segments-in-a-string.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 557580f2e9c5157a1b7a50a4104d0f19edefed34 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:49 +0800 Subject: [PATCH 0409/1556] src/bin/numbers-with-same-consecutive-differences.rs --- src/bin/numbers-with-same-consecutive-differences.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/numbers-with-same-consecutive-differences.rs b/src/bin/numbers-with-same-consecutive-differences.rs index 14586834..8e37b4a6 100644 --- a/src/bin/numbers-with-same-consecutive-differences.rs +++ b/src/bin/numbers-with-same-consecutive-differences.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 1579b7dade2c73537d990e8ebd455b51e32e9602 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:49 +0800 Subject: [PATCH 0410/1556] src/bin/online-election.rs --- src/bin/online-election.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/online-election.rs b/src/bin/online-election.rs index 816de3cd..296ec617 100644 --- a/src/bin/online-election.rs +++ b/src/bin/online-election.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let s = TopVotedCandidate::new(vec![0, 1, 1, 0, 0, 1, 0], vec![0, 5, 10, 15, 20, 25, 30]); assert_eq!(s.q(3), 0); From b69e442ac817783b59d64de5d23a1336d87dfe8f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:50 +0800 Subject: [PATCH 0411/1556] src/bin/palindrome-linked-list.rs --- src/bin/palindrome-linked-list.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/palindrome-linked-list.rs b/src/bin/palindrome-linked-list.rs index e46b7a2b..036600a1 100644 --- a/src/bin/palindrome-linked-list.rs +++ b/src/bin/palindrome-linked-list.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From a6bdb5980d2870da9af59973b092e537e6728e1b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:50 +0800 Subject: [PATCH 0412/1556] src/bin/palindrome-number.rs --- src/bin/palindrome-number.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/palindrome-number.rs b/src/bin/palindrome-number.rs index a52aeb30..e3e70d82 100644 --- a/src/bin/palindrome-number.rs +++ b/src/bin/palindrome-number.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From ba5f7229ac332c15ee51bb60dcd76e095ff2cf3a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:51 +0800 Subject: [PATCH 0413/1556] src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs --- .../partitioning-into-minimum-number-of-deci-binary-numbers.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs b/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs index b8d2f6d1..73769a56 100644 --- a/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs +++ b/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 9aaec82cc270d756ed3eb69627a22e1765406cd5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:51 +0800 Subject: [PATCH 0414/1556] src/bin/pascals-triangle-ii.rs --- src/bin/pascals-triangle-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/pascals-triangle-ii.rs b/src/bin/pascals-triangle-ii.rs index 3e3fe7d8..f920994c 100644 --- a/src/bin/pascals-triangle-ii.rs +++ b/src/bin/pascals-triangle-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{:?}", Solution::get_row(6)); } From 16eb58877bb896f159a90e9e82f71d699b10ba76 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:52 +0800 Subject: [PATCH 0415/1556] src/bin/pascals-triangle.rs --- src/bin/pascals-triangle.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/pascals-triangle.rs b/src/bin/pascals-triangle.rs index 0ed73b30..2b10e60f 100644 --- a/src/bin/pascals-triangle.rs +++ b/src/bin/pascals-triangle.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 9cfec658dcc7dec8b98db946add073aec9866436 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:52 +0800 Subject: [PATCH 0416/1556] src/bin/path-sum-ii.rs --- src/bin/path-sum-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/path-sum-ii.rs b/src/bin/path-sum-ii.rs index 741ceb03..c5079545 100644 --- a/src/bin/path-sum-ii.rs +++ b/src/bin/path-sum-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 9b84dced70ed38e59495ad8b69ce2d069faa2fc0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:52 +0800 Subject: [PATCH 0417/1556] src/bin/path-sum.rs --- src/bin/path-sum.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/path-sum.rs b/src/bin/path-sum.rs index fcb90e1c..44051722 100644 --- a/src/bin/path-sum.rs +++ b/src/bin/path-sum.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 88ee7c0064c83d408e3248b11ecaf1d1e98e6252 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:53 +0800 Subject: [PATCH 0418/1556] src/bin/perfect-number.rs --- src/bin/perfect-number.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/perfect-number.rs b/src/bin/perfect-number.rs index 236b3492..5218e012 100644 --- a/src/bin/perfect-number.rs +++ b/src/bin/perfect-number.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From f17b7f9f93d1c37c945d3922df2b4655a326a030 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:53 +0800 Subject: [PATCH 0419/1556] src/bin/perfect-squares.rs --- src/bin/perfect-squares.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/perfect-squares.rs b/src/bin/perfect-squares.rs index 4f5c2003..44325cf6 100644 --- a/src/bin/perfect-squares.rs +++ b/src/bin/perfect-squares.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::num_squares(12)); println!("{}", Solution::num_squares(13)); From c155a8223a37d74765ddb968c32c0359f53d04ee Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:54 +0800 Subject: [PATCH 0420/1556] src/bin/permutations.rs --- src/bin/permutations.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/permutations.rs b/src/bin/permutations.rs index 972a3b17..15e99b6a 100644 --- a/src/bin/permutations.rs +++ b/src/bin/permutations.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From d99f1adbcb0d1d2edc3bce2447086ac00a1faeae Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:54 +0800 Subject: [PATCH 0421/1556] src/bin/plus-one.rs --- src/bin/plus-one.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/plus-one.rs b/src/bin/plus-one.rs index 86aa73f5..0c5bf075 100644 --- a/src/bin/plus-one.rs +++ b/src/bin/plus-one.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{:?}", Solution::plus_one(vec![1])); println!("{:?}", Solution::plus_one(vec![9])); From f73761af46423176008105c7a0c2e32f46ae1632 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:55 +0800 Subject: [PATCH 0422/1556] src/bin/positions-of-large-groups.rs --- src/bin/positions-of-large-groups.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/positions-of-large-groups.rs b/src/bin/positions-of-large-groups.rs index bf32b49f..7c1a62c5 100644 --- a/src/bin/positions-of-large-groups.rs +++ b/src/bin/positions-of-large-groups.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!( vec![vec![3, 6]], From f93ded73ce6647fee8ce0168bea978372d8044d2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:55 +0800 Subject: [PATCH 0423/1556] src/bin/power-of-three.rs --- src/bin/power-of-three.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/power-of-three.rs b/src/bin/power-of-three.rs index 1d36d59d..a07af5c1 100644 --- a/src/bin/power-of-three.rs +++ b/src/bin/power-of-three.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From ac5829f0d6441d14d3b3d626fe1dd41730e83d06 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:55 +0800 Subject: [PATCH 0424/1556] src/bin/power-of-two.rs --- src/bin/power-of-two.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/power-of-two.rs b/src/bin/power-of-two.rs index f402c984..576e9d56 100644 --- a/src/bin/power-of-two.rs +++ b/src/bin/power-of-two.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::is_power_of_two(16)); println!("{}", Solution::is_power_of_two(15)); From 9fb494eb4515552eeac10915c1b4f147376b8fe1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:56 +0800 Subject: [PATCH 0425/1556] src/bin/powx-n.rs --- src/bin/powx-n.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/powx-n.rs b/src/bin/powx-n.rs index 650c8d23..1fc5fdfa 100644 --- a/src/bin/powx-n.rs +++ b/src/bin/powx-n.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::my_pow(0.00001, 2147483647)); println!("{}", Solution::my_pow(2.00000, 10)); From 9e79bfcaa527aafa9b00612d065a2ff54b67cecb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:56 +0800 Subject: [PATCH 0426/1556] src/bin/product-of-array-except-self.rs --- src/bin/product-of-array-except-self.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/product-of-array-except-self.rs b/src/bin/product-of-array-except-self.rs index 94c051c7..09617877 100644 --- a/src/bin/product-of-array-except-self.rs +++ b/src/bin/product-of-array-except-self.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{:?}", Solution::product_except_self(vec![1, 2, 3, 4])); } From ed33a1ab5aa63a09b2f66ffac9ff78b15079bd51 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:57 +0800 Subject: [PATCH 0427/1556] src/bin/push-dominoes.rs --- src/bin/push-dominoes.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/push-dominoes.rs b/src/bin/push-dominoes.rs index 9d7d7a9b..4f89fbce 100644 --- a/src/bin/push-dominoes.rs +++ b/src/bin/push-dominoes.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::push_dominoes(".L.R...LR..L..".to_string())); } From df1b99509e66dd569fdec4cc9cd4f8cba6cccc5c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:57 +0800 Subject: [PATCH 0428/1556] src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs --- src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs b/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs index d4db6e4f..821b5550 100644 --- a/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs +++ b/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::num_ways(2)); println!("{}", Solution::num_ways(7)); From 925a6fdaf79cedb3684f92ff18e1546eb784fd12 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:57 +0800 Subject: [PATCH 0429/1556] src/bin/qiu-12n-lcof.rs --- src/bin/qiu-12n-lcof.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/qiu-12n-lcof.rs b/src/bin/qiu-12n-lcof.rs index deecdbe5..b44976bd 100644 --- a/src/bin/qiu-12n-lcof.rs +++ b/src/bin/qiu-12n-lcof.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 91d72de49d8387f7ad1e8f3134e825a6eb2bc2e0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:58 +0800 Subject: [PATCH 0430/1556] src/bin/random-pick-index.rs --- src/bin/random-pick-index.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/random-pick-index.rs b/src/bin/random-pick-index.rs index e0fb5882..408047b6 100644 --- a/src/bin/random-pick-index.rs +++ b/src/bin/random-pick-index.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} /** From b7e297d9eb490cb4ca20c17fcb9dc186e25b11ea Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:58 +0800 Subject: [PATCH 0431/1556] src/bin/range-sum-query-immutable.rs --- src/bin/range-sum-query-immutable.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/range-sum-query-immutable.rs b/src/bin/range-sum-query-immutable.rs index 995dda35..e75f65f1 100644 --- a/src/bin/range-sum-query-immutable.rs +++ b/src/bin/range-sum-query-immutable.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 3e040f17258602df6fa2f975fbf0daa00295d4c6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:59 +0800 Subject: [PATCH 0432/1556] src/bin/ransom-note.rs --- src/bin/ransom-note.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/ransom-note.rs b/src/bin/ransom-note.rs index 7c9bb5ad..7b7aa244 100644 --- a/src/bin/ransom-note.rs +++ b/src/bin/ransom-note.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 8f2eeb3eeab07661526ed9da6ccc12ec6791e5f7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:12:59 +0800 Subject: [PATCH 0433/1556] src/bin/reconstruct-a-2-row-binary-matrix.rs --- src/bin/reconstruct-a-2-row-binary-matrix.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/reconstruct-a-2-row-binary-matrix.rs b/src/bin/reconstruct-a-2-row-binary-matrix.rs index 7ddad78d..17805cf9 100644 --- a/src/bin/reconstruct-a-2-row-binary-matrix.rs +++ b/src/bin/reconstruct-a-2-row-binary-matrix.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 163d2acf1fc99d1f6840c8ae4d298df897c978c5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:00 +0800 Subject: [PATCH 0434/1556] src/bin/reconstruct-original-digits-from-english.rs --- src/bin/reconstruct-original-digits-from-english.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/reconstruct-original-digits-from-english.rs b/src/bin/reconstruct-original-digits-from-english.rs index 1d359c6e..5c81a4f6 100644 --- a/src/bin/reconstruct-original-digits-from-english.rs +++ b/src/bin/reconstruct-original-digits-from-english.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!( "012".to_string(), From c418ffb7583918da10b58b345cd0b2eecb7f82d7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:00 +0800 Subject: [PATCH 0435/1556] src/bin/rectangle-area.rs --- src/bin/rectangle-area.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/rectangle-area.rs b/src/bin/rectangle-area.rs index 50921008..bfe0f137 100644 --- a/src/bin/rectangle-area.rs +++ b/src/bin/rectangle-area.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From d5ff31bffc3bce70f86c3430da0da5d6331f5c85 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:00 +0800 Subject: [PATCH 0436/1556] src/bin/remove-all-adjacent-duplicates-in-string-ii.rs --- src/bin/remove-all-adjacent-duplicates-in-string-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs b/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs index eb69a396..53501d6a 100644 --- a/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs +++ b/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 266b57876ae7f9ae04d2ab44982a2c3dea92ec5c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:01 +0800 Subject: [PATCH 0437/1556] src/bin/remove-all-adjacent-duplicates-in-string.rs --- src/bin/remove-all-adjacent-duplicates-in-string.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/remove-all-adjacent-duplicates-in-string.rs b/src/bin/remove-all-adjacent-duplicates-in-string.rs index 44e82450..d809d5b7 100644 --- a/src/bin/remove-all-adjacent-duplicates-in-string.rs +++ b/src/bin/remove-all-adjacent-duplicates-in-string.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From b03c3afe190f0c7f4e22e3d3dfdf3af6e0f6b99f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:01 +0800 Subject: [PATCH 0438/1556] src/bin/remove-duplicates-from-sorted-array-ii.rs --- src/bin/remove-duplicates-from-sorted-array-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/remove-duplicates-from-sorted-array-ii.rs b/src/bin/remove-duplicates-from-sorted-array-ii.rs index af3a7e8a..04d889fb 100644 --- a/src/bin/remove-duplicates-from-sorted-array-ii.rs +++ b/src/bin/remove-duplicates-from-sorted-array-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let mut v = vec![0, 0, 1, 1, 1, 1, 2, 3, 3]; let s = Solution::remove_duplicates(&mut v); From 6d25a50fd494de7f16a7364953c77fb75c242d67 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:01 +0800 Subject: [PATCH 0439/1556] src/bin/remove-duplicates-from-sorted-array.rs --- src/bin/remove-duplicates-from-sorted-array.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/remove-duplicates-from-sorted-array.rs b/src/bin/remove-duplicates-from-sorted-array.rs index 29b75f23..38d85276 100644 --- a/src/bin/remove-duplicates-from-sorted-array.rs +++ b/src/bin/remove-duplicates-from-sorted-array.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!( 5, From 474b975374f3c27c1d99131ad692b493c3eb2fd0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:02 +0800 Subject: [PATCH 0440/1556] src/bin/remove-duplicates-from-sorted-list-ii.rs --- src/bin/remove-duplicates-from-sorted-list-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/remove-duplicates-from-sorted-list-ii.rs b/src/bin/remove-duplicates-from-sorted-list-ii.rs index e4660f51..154f6542 100644 --- a/src/bin/remove-duplicates-from-sorted-list-ii.rs +++ b/src/bin/remove-duplicates-from-sorted-list-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From f95a5c01208705fb05c39bd385b2beb0f5e55533 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:02 +0800 Subject: [PATCH 0441/1556] src/bin/remove-duplicates-from-sorted-list.rs --- src/bin/remove-duplicates-from-sorted-list.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/remove-duplicates-from-sorted-list.rs b/src/bin/remove-duplicates-from-sorted-list.rs index 30e8da9d..5e47310f 100644 --- a/src/bin/remove-duplicates-from-sorted-list.rs +++ b/src/bin/remove-duplicates-from-sorted-list.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 6a036777d21744bf35e0b4eec2de6ed13c90b8d9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:03 +0800 Subject: [PATCH 0442/1556] src/bin/remove-element.rs --- src/bin/remove-element.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/remove-element.rs b/src/bin/remove-element.rs index 90218cb7..f2395c55 100644 --- a/src/bin/remove-element.rs +++ b/src/bin/remove-element.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let mut v = vec![3, 2, 2, 3]; assert_eq!(2, Solution::remove_element(&mut v, 3)); From beece7ecab801ef48205d12753ec1f5918f5d21f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:03 +0800 Subject: [PATCH 0443/1556] src/bin/remove-linked-list-elements.rs --- src/bin/remove-linked-list-elements.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/remove-linked-list-elements.rs b/src/bin/remove-linked-list-elements.rs index 2d2eb957..e96ee6ef 100644 --- a/src/bin/remove-linked-list-elements.rs +++ b/src/bin/remove-linked-list-elements.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From b29026386e03fce699f88074204627568577c41d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:03 +0800 Subject: [PATCH 0444/1556] src/bin/remove-nth-node-from-end-of-list.rs --- src/bin/remove-nth-node-from-end-of-list.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/remove-nth-node-from-end-of-list.rs b/src/bin/remove-nth-node-from-end-of-list.rs index 899219dc..11e7acc6 100644 --- a/src/bin/remove-nth-node-from-end-of-list.rs +++ b/src/bin/remove-nth-node-from-end-of-list.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From d6c90b6fed14b6396436b8157773bfcd7e971fb0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:04 +0800 Subject: [PATCH 0445/1556] src/bin/repeated-dna-sequences.rs --- src/bin/repeated-dna-sequences.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/repeated-dna-sequences.rs b/src/bin/repeated-dna-sequences.rs index 7754bac7..ccfe06b4 100644 --- a/src/bin/repeated-dna-sequences.rs +++ b/src/bin/repeated-dna-sequences.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!( "{:?}", From 034924f41e423446a292fa2d69d247a2ffda9e4e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:04 +0800 Subject: [PATCH 0446/1556] src/bin/restore-ip-addresses.rs --- src/bin/restore-ip-addresses.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/restore-ip-addresses.rs b/src/bin/restore-ip-addresses.rs index f7f2c671..d3bba93c 100644 --- a/src/bin/restore-ip-addresses.rs +++ b/src/bin/restore-ip-addresses.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!( "{:?}", From de4cd8997bd19ec569afdc0a84ca042ec284e1a9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:04 +0800 Subject: [PATCH 0447/1556] src/bin/reverse-bits.rs --- src/bin/reverse-bits.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/reverse-bits.rs b/src/bin/reverse-bits.rs index a2635245..715785c8 100644 --- a/src/bin/reverse-bits.rs +++ b/src/bin/reverse-bits.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::reverse_bits(43261596)); println!("{}", Solution::reverse_bits(4294967293)); From 64ea4f74cada314f0b216e9e01a31e9409d5bd66 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:05 +0800 Subject: [PATCH 0448/1556] src/bin/reverse-integer.rs --- src/bin/reverse-integer.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/reverse-integer.rs b/src/bin/reverse-integer.rs index af266969..e77043be 100644 --- a/src/bin/reverse-integer.rs +++ b/src/bin/reverse-integer.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}, {}", std::i32::MAX, std::i32::MIN); } From f53f7856feba5763cb98d80c232e57b9db040ce2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:05 +0800 Subject: [PATCH 0449/1556] src/bin/reverse-linked-list.rs --- src/bin/reverse-linked-list.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/reverse-linked-list.rs b/src/bin/reverse-linked-list.rs index 6d8f19f1..b68e4f22 100644 --- a/src/bin/reverse-linked-list.rs +++ b/src/bin/reverse-linked-list.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From e1b5d8543e32ae7fcd360aac7c6e7092fa0a6f18 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:05 +0800 Subject: [PATCH 0450/1556] src/bin/reverse-nodes-in-k-group.rs --- src/bin/reverse-nodes-in-k-group.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/reverse-nodes-in-k-group.rs b/src/bin/reverse-nodes-in-k-group.rs index f8c7c142..58e1bff2 100644 --- a/src/bin/reverse-nodes-in-k-group.rs +++ b/src/bin/reverse-nodes-in-k-group.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let x = Some(Box::new(ListNode { val: 1, From 2d22e92302e3659ba9062e45062c5b4cbdd5f771 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:06 +0800 Subject: [PATCH 0451/1556] src/bin/reverse-prefix-of-word.rs --- src/bin/reverse-prefix-of-word.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/reverse-prefix-of-word.rs b/src/bin/reverse-prefix-of-word.rs index 60343a5e..9746fb4d 100644 --- a/src/bin/reverse-prefix-of-word.rs +++ b/src/bin/reverse-prefix-of-word.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From e69041b9db810813933b8480b8434cfc1d03076e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:06 +0800 Subject: [PATCH 0452/1556] src/bin/reverse-string.rs --- src/bin/reverse-string.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/reverse-string.rs b/src/bin/reverse-string.rs index 2789f7a0..c7929f7d 100644 --- a/src/bin/reverse-string.rs +++ b/src/bin/reverse-string.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 8dca9f667108236b42644dfa197edeec0d9ecbec Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:07 +0800 Subject: [PATCH 0453/1556] src/bin/reverse-words-in-a-string.rs --- src/bin/reverse-words-in-a-string.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/reverse-words-in-a-string.rs b/src/bin/reverse-words-in-a-string.rs index 9d7b1982..f22b508f 100644 --- a/src/bin/reverse-words-in-a-string.rs +++ b/src/bin/reverse-words-in-a-string.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 5de01a79d6d55751be17479bd199c456fef12b7c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:07 +0800 Subject: [PATCH 0454/1556] src/bin/richest-customer-wealth.rs --- src/bin/richest-customer-wealth.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/richest-customer-wealth.rs b/src/bin/richest-customer-wealth.rs index 49a3f4e7..68b57fbc 100644 --- a/src/bin/richest-customer-wealth.rs +++ b/src/bin/richest-customer-wealth.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From cb6f6dc0c9d1c68c84d981197e3b3ae64e5586cb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:07 +0800 Subject: [PATCH 0455/1556] src/bin/rle-iterator.rs --- src/bin/rle-iterator.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/rle-iterator.rs b/src/bin/rle-iterator.rs index 88d7f20b..afebdc63 100644 --- a/src/bin/rle-iterator.rs +++ b/src/bin/rle-iterator.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let mut s = RLEIterator::new(vec![3, 8, 0, 9, 2, 5]); println!("{}", s.next(2)); From 774a2baaf5f7fdab0def9fa4eeb1e1c5180e5953 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:08 +0800 Subject: [PATCH 0456/1556] src/bin/robot-bounded-in-circle.rs --- src/bin/robot-bounded-in-circle.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/robot-bounded-in-circle.rs b/src/bin/robot-bounded-in-circle.rs index 22c9c478..ec6e04bc 100644 --- a/src/bin/robot-bounded-in-circle.rs +++ b/src/bin/robot-bounded-in-circle.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(true, Solution::is_robot_bounded(String::from("LLGRL"))); } From 1469881f4ebf8d2cb6e6d61280202088935dddc9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:08 +0800 Subject: [PATCH 0457/1556] src/bin/robot-return-to-origin.rs --- src/bin/robot-return-to-origin.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/robot-return-to-origin.rs b/src/bin/robot-return-to-origin.rs index c25be7db..97dd8c0a 100644 --- a/src/bin/robot-return-to-origin.rs +++ b/src/bin/robot-return-to-origin.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From a94af647f96cc0ab83f6231eb3279c8dabd9c8af Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:09 +0800 Subject: [PATCH 0458/1556] src/bin/roman-to-integer.rs --- src/bin/roman-to-integer.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/roman-to-integer.rs b/src/bin/roman-to-integer.rs index d91664d0..90d83c13 100644 --- a/src/bin/roman-to-integer.rs +++ b/src/bin/roman-to-integer.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(3, Solution::roman_to_int("III".to_string())); assert_eq!(4, Solution::roman_to_int("IV".to_string())); From cfec740f2fcfbe2c90455884b8373b3eadd5eedc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:09 +0800 Subject: [PATCH 0459/1556] src/bin/rotate-image.rs --- src/bin/rotate-image.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/rotate-image.rs b/src/bin/rotate-image.rs index e825bc60..412ae1a8 100644 --- a/src/bin/rotate-image.rs +++ b/src/bin/rotate-image.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let mut v = vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]]; From 97af1e5110b3a7bdcd128b6d0d1dbd168da01e20 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:09 +0800 Subject: [PATCH 0460/1556] src/bin/running-sum-of-1d-array.rs --- src/bin/running-sum-of-1d-array.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/running-sum-of-1d-array.rs b/src/bin/running-sum-of-1d-array.rs index 2d92a864..511306ee 100644 --- a/src/bin/running-sum-of-1d-array.rs +++ b/src/bin/running-sum-of-1d-array.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 9188508d1874664cbed08196ffdc79b82a978329 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:10 +0800 Subject: [PATCH 0461/1556] src/bin/same-tree.rs --- src/bin/same-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/same-tree.rs b/src/bin/same-tree.rs index 8c16a24f..90544f36 100644 --- a/src/bin/same-tree.rs +++ b/src/bin/same-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 14d04086e129746d805186ac5d330b3a188c246f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:10 +0800 Subject: [PATCH 0462/1556] src/bin/search-a-2d-matrix.rs --- src/bin/search-a-2d-matrix.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/search-a-2d-matrix.rs b/src/bin/search-a-2d-matrix.rs index 826077cd..16caeef6 100644 --- a/src/bin/search-a-2d-matrix.rs +++ b/src/bin/search-a-2d-matrix.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 4b436791c2713f89a59ae229a64c1282774cab63 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:11 +0800 Subject: [PATCH 0463/1556] src/bin/search-in-a-binary-search-tree.rs --- src/bin/search-in-a-binary-search-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/search-in-a-binary-search-tree.rs b/src/bin/search-in-a-binary-search-tree.rs index c89e0866..0bbb42bc 100644 --- a/src/bin/search-in-a-binary-search-tree.rs +++ b/src/bin/search-in-a-binary-search-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From dac1c5b3ef6098568288ba53f721a2a2b9770c39 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:11 +0800 Subject: [PATCH 0464/1556] src/bin/search-in-rotated-sorted-array-ii.rs --- src/bin/search-in-rotated-sorted-array-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/search-in-rotated-sorted-array-ii.rs b/src/bin/search-in-rotated-sorted-array-ii.rs index efdb4dac..7bc09793 100644 --- a/src/bin/search-in-rotated-sorted-array-ii.rs +++ b/src/bin/search-in-rotated-sorted-array-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(true, Solution::search(vec![2, 5, 6, 0, 0, 1, 2], 0)); assert_eq!(false, Solution::search(vec![2, 5, 6, 0, 0, 1, 2], 3)); From 35b80f3aca14ef00c293b7104ca6d3b214eb4eb0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:11 +0800 Subject: [PATCH 0465/1556] src/bin/search-in-rotated-sorted-array.rs --- src/bin/search-in-rotated-sorted-array.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/search-in-rotated-sorted-array.rs b/src/bin/search-in-rotated-sorted-array.rs index c339cce4..de87cf0b 100644 --- a/src/bin/search-in-rotated-sorted-array.rs +++ b/src/bin/search-in-rotated-sorted-array.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(4, Solution::search(vec![4, 5, 6, 7, 8, 1, 2, 3], 8)); assert_eq!(-1, Solution::search(vec![1, 3], 0)); From 6cc16e45f609c9ded3145155daeb7783129ca693 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:12 +0800 Subject: [PATCH 0466/1556] src/bin/search-insert-position.rs --- src/bin/search-insert-position.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/search-insert-position.rs b/src/bin/search-insert-position.rs index de6e90c6..1c97a2b0 100644 --- a/src/bin/search-insert-position.rs +++ b/src/bin/search-insert-position.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { // assert_eq!(2, Solution::search_insert(vec![1, 3, 5, 6], 5)); // assert_eq!(1, Solution::search_insert(vec![1, 3, 5, 6], 2)); From efd6241e2c803febac064b0d38d9ee8ea86293f3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:12 +0800 Subject: [PATCH 0467/1556] src/bin/serialize-and-deserialize-bst.rs --- src/bin/serialize-and-deserialize-bst.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/serialize-and-deserialize-bst.rs b/src/bin/serialize-and-deserialize-bst.rs index d9c6ad9e..bc636a6d 100644 --- a/src/bin/serialize-and-deserialize-bst.rs +++ b/src/bin/serialize-and-deserialize-bst.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} // Definition for a binary tree node. From 0fd846947240a35d2427835781fbc771f54a7739 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:13 +0800 Subject: [PATCH 0468/1556] src/bin/set-matrix-zeroes.rs --- src/bin/set-matrix-zeroes.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/set-matrix-zeroes.rs b/src/bin/set-matrix-zeroes.rs index 1ecd0f25..d80698e3 100644 --- a/src/bin/set-matrix-zeroes.rs +++ b/src/bin/set-matrix-zeroes.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let mut x = vec![vec![1, 1, 1], vec![1, 0, 1], vec![1, 1, 1]]; Solution::set_zeroes(&mut x); From 22128fd51a0ba02b7f1414accff242a5de1d99c6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:13 +0800 Subject: [PATCH 0469/1556] src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs --- src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs b/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs index 778bc97f..1256307d 100644 --- a/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs +++ b/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 2a888865b9d1d9e553a13fc024570cd9089745b1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:13 +0800 Subject: [PATCH 0470/1556] src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs --- src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs b/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs index 3d055e5a..5fbb7842 100644 --- a/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs +++ b/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From c49002c44e088a9cfd0dcdf91e532a6f918e7150 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:14 +0800 Subject: [PATCH 0471/1556] src/bin/shuffle-an-array.rs --- src/bin/shuffle-an-array.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/shuffle-an-array.rs b/src/bin/shuffle-an-array.rs index e32bff34..bdb113cb 100644 --- a/src/bin/shuffle-an-array.rs +++ b/src/bin/shuffle-an-array.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} /** From 3ee7228d64a99ea55ab63c65f4a8c62271829d01 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:14 +0800 Subject: [PATCH 0472/1556] src/bin/simplify-path.rs --- src/bin/simplify-path.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/simplify-path.rs b/src/bin/simplify-path.rs index 60cfb628..7c378fe7 100644 --- a/src/bin/simplify-path.rs +++ b/src/bin/simplify-path.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From fa52e78b1e5d5b7f06fce6205948519f4e2f56aa Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:14 +0800 Subject: [PATCH 0473/1556] src/bin/single-number-ii.rs --- src/bin/single-number-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/single-number-ii.rs b/src/bin/single-number-ii.rs index 76ae368f..bf1a4220 100644 --- a/src/bin/single-number-ii.rs +++ b/src/bin/single-number-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(99, Solution::single_number(vec![0, 1, 0, 1, 0, 1, 99])); assert_eq!( From a41138b3aa2c00bbb6bcedab078b1c478b004642 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:15 +0800 Subject: [PATCH 0474/1556] src/bin/single-number.rs --- src/bin/single-number.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/single-number.rs b/src/bin/single-number.rs index bfa22b7f..de952628 100644 --- a/src/bin/single-number.rs +++ b/src/bin/single-number.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 197f2a6d80356a6e8ddcb42b4cc432e854499621 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:15 +0800 Subject: [PATCH 0475/1556] src/bin/sort-colors.rs --- src/bin/sort-colors.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/sort-colors.rs b/src/bin/sort-colors.rs index 124de5a9..7b05e88f 100644 --- a/src/bin/sort-colors.rs +++ b/src/bin/sort-colors.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let mut v = vec![2, 0, 2, 1, 1, 1, 1, 1, 0, 2, 2, 2, 2, 0, 0, 2, 1, 0]; Solution::sort_colors(&mut v); From ad489b09119a14109b0734025963176c43923137 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:16 +0800 Subject: [PATCH 0476/1556] src/bin/sort-the-matrix-diagonally.rs --- src/bin/sort-the-matrix-diagonally.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/sort-the-matrix-diagonally.rs b/src/bin/sort-the-matrix-diagonally.rs index 7a2e3bdf..18c5fc7b 100644 --- a/src/bin/sort-the-matrix-diagonally.rs +++ b/src/bin/sort-the-matrix-diagonally.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let a = vec![vec![3, 3, 1, 1], vec![2, 2, 1, 2], vec![1, 1, 1, 2]]; let b = Solution::diagonal_sort(a); From 53947fa3376eb14721d066480873ba75c6ce2b86 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:16 +0800 Subject: [PATCH 0477/1556] src/bin/spiral-matrix-iii.rs --- src/bin/spiral-matrix-iii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/spiral-matrix-iii.rs b/src/bin/spiral-matrix-iii.rs index d5166b0b..e27a093a 100644 --- a/src/bin/spiral-matrix-iii.rs +++ b/src/bin/spiral-matrix-iii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{:?}", Solution::spiral_matrix_iii(5, 4, 0, 2)); println!("{}", "[[0, 2], [0, 3], [1, 3], [1, 2], [1, 1], [0, 1], [2, 3], [2, 2], [2, 1], [2, 0], [1, 0], [0, 0], [3, 3], [3, 2], [3, 1], [3, 0], [4, 3], [4, 2], [4, 1], [4, 0]]") From e685202452abb91ff443f56682ac631bfcafac49 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:16 +0800 Subject: [PATCH 0478/1556] src/bin/split-a-string-in-balanced-strings.rs --- src/bin/split-a-string-in-balanced-strings.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/split-a-string-in-balanced-strings.rs b/src/bin/split-a-string-in-balanced-strings.rs index d37ad56e..f0e55fa1 100644 --- a/src/bin/split-a-string-in-balanced-strings.rs +++ b/src/bin/split-a-string-in-balanced-strings.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From bbe5a91f22c63660f531c2a7ff3ea58cce0fc2c3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:17 +0800 Subject: [PATCH 0479/1556] src/bin/sqrtx.rs --- src/bin/sqrtx.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/sqrtx.rs b/src/bin/sqrtx.rs index d0aa6ef9..2d0969af 100644 --- a/src/bin/sqrtx.rs +++ b/src/bin/sqrtx.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From a2d2d04c560b35d302c2abe856c96908882a950e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:17 +0800 Subject: [PATCH 0480/1556] src/bin/string-to-integer-atoi.rs --- src/bin/string-to-integer-atoi.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/string-to-integer-atoi.rs b/src/bin/string-to-integer-atoi.rs index 89e49090..fe5f3ff7 100644 --- a/src/bin/string-to-integer-atoi.rs +++ b/src/bin/string-to-integer-atoi.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(42, Solution::my_atoi("42".to_string())); assert_eq!(-42, Solution::my_atoi(" -42".to_string())); From 3bc70f4985381880bb1c4d88394602bb2e9b6dd9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:18 +0800 Subject: [PATCH 0481/1556] src/bin/student-attendance-record-i.rs --- src/bin/student-attendance-record-i.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/student-attendance-record-i.rs b/src/bin/student-attendance-record-i.rs index d4b560f1..2370757c 100644 --- a/src/bin/student-attendance-record-i.rs +++ b/src/bin/student-attendance-record-i.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 32704b19082e6f028a14f6409983b8eba511ffbb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:18 +0800 Subject: [PATCH 0482/1556] src/bin/subarray-sum-equals-k.rs --- src/bin/subarray-sum-equals-k.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/subarray-sum-equals-k.rs b/src/bin/subarray-sum-equals-k.rs index 094c9016..6af80ca9 100644 --- a/src/bin/subarray-sum-equals-k.rs +++ b/src/bin/subarray-sum-equals-k.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!( 39, From a1625d696b10a2dc71cf63d8732d18ade269b842 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:18 +0800 Subject: [PATCH 0483/1556] src/bin/subdomain-visit-count.rs --- src/bin/subdomain-visit-count.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/subdomain-visit-count.rs b/src/bin/subdomain-visit-count.rs index 836658e0..0c7573d3 100644 --- a/src/bin/subdomain-visit-count.rs +++ b/src/bin/subdomain-visit-count.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!( "{:?}", From 445b90129e99026b8976e47646ba5ef7e0588d83 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:19 +0800 Subject: [PATCH 0484/1556] src/bin/subsets.rs --- src/bin/subsets.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/subsets.rs b/src/bin/subsets.rs index c7706091..3646cf0b 100644 --- a/src/bin/subsets.rs +++ b/src/bin/subsets.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 305a039d4ae8b7b3174bbc30aafc8564b0f0d49a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:19 +0800 Subject: [PATCH 0485/1556] src/bin/successful-pairs-of-spells-and-potions.rs --- src/bin/successful-pairs-of-spells-and-potions.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/successful-pairs-of-spells-and-potions.rs b/src/bin/successful-pairs-of-spells-and-potions.rs index 9e990851..61762eb2 100644 --- a/src/bin/successful-pairs-of-spells-and-potions.rs +++ b/src/bin/successful-pairs-of-spells-and-potions.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let s = Solution::successful_pairs(vec![5, 1, 3], vec![1, 2, 3, 4, 5], 7); println!("{s:?}"); From d2d45bb6d25bf6eb8ec5bab0fb0bc4bbded3f3ef Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:19 +0800 Subject: [PATCH 0486/1556] src/bin/sum-of-left-leaves.rs --- src/bin/sum-of-left-leaves.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/sum-of-left-leaves.rs b/src/bin/sum-of-left-leaves.rs index d67e1c9f..a9b0f02f 100644 --- a/src/bin/sum-of-left-leaves.rs +++ b/src/bin/sum-of-left-leaves.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From f150a02b37b3106de84f53105afb74461b000b00 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:20 +0800 Subject: [PATCH 0487/1556] src/bin/sum-of-two-integers.rs --- src/bin/sum-of-two-integers.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/sum-of-two-integers.rs b/src/bin/sum-of-two-integers.rs index c4fe6635..3b46b038 100644 --- a/src/bin/sum-of-two-integers.rs +++ b/src/bin/sum-of-two-integers.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(10, Solution::get_sum(4, 6)); assert_eq!(10, Solution::get_sum(12, -2)); From d01b0815fe9a349a058075e42ae2645069d02eef Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:20 +0800 Subject: [PATCH 0488/1556] src/bin/sum-root-to-leaf-numbers.rs --- src/bin/sum-root-to-leaf-numbers.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/sum-root-to-leaf-numbers.rs b/src/bin/sum-root-to-leaf-numbers.rs index 20b3a0f3..38e25e21 100644 --- a/src/bin/sum-root-to-leaf-numbers.rs +++ b/src/bin/sum-root-to-leaf-numbers.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From dd799d46b70313f6019ea43b50fcc5e178e2be9b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:21 +0800 Subject: [PATCH 0489/1556] src/bin/summary-ranges.rs --- src/bin/summary-ranges.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/summary-ranges.rs b/src/bin/summary-ranges.rs index f25fc2f0..2beefec5 100644 --- a/src/bin/summary-ranges.rs +++ b/src/bin/summary-ranges.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{:?}", Solution::summary_ranges(vec![0, 1, 2, 4, 5, 7])); } From 478d83d03104de6fa641ae169261b4ae48a12b8b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:21 +0800 Subject: [PATCH 0490/1556] src/bin/swap-nodes-in-pairs.rs --- src/bin/swap-nodes-in-pairs.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/swap-nodes-in-pairs.rs b/src/bin/swap-nodes-in-pairs.rs index cc42a25a..2de6ac0f 100644 --- a/src/bin/swap-nodes-in-pairs.rs +++ b/src/bin/swap-nodes-in-pairs.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From cf3b985c4d2109540544352f4e70c82f0cfe49bb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:21 +0800 Subject: [PATCH 0491/1556] src/bin/swapping-nodes-in-a-linked-list.rs --- src/bin/swapping-nodes-in-a-linked-list.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/swapping-nodes-in-a-linked-list.rs b/src/bin/swapping-nodes-in-a-linked-list.rs index 61d8f29e..db82ac31 100644 --- a/src/bin/swapping-nodes-in-a-linked-list.rs +++ b/src/bin/swapping-nodes-in-a-linked-list.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From f0ea91ac0f1e06220918f8702c54a0bae616d719 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:22 +0800 Subject: [PATCH 0492/1556] src/bin/symmetric-tree.rs --- src/bin/symmetric-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/symmetric-tree.rs b/src/bin/symmetric-tree.rs index 924d2be2..69ac66b7 100644 --- a/src/bin/symmetric-tree.rs +++ b/src/bin/symmetric-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { let root = Some(Rc::new(RefCell::new(TreeNode { val: 1, From 52ac38d289c32e16f0eedcd74df90f5f008b1b70 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:22 +0800 Subject: [PATCH 0493/1556] src/bin/thousand-separator.rs --- src/bin/thousand-separator.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/thousand-separator.rs b/src/bin/thousand-separator.rs index 7b283da1..6a3aab04 100644 --- a/src/bin/thousand-separator.rs +++ b/src/bin/thousand-separator.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 693167183d3f3f90a0aceae3aa2362507c9f9d7a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:22 +0800 Subject: [PATCH 0494/1556] src/bin/ti-huan-kong-ge-lcof.rs --- src/bin/ti-huan-kong-ge-lcof.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/ti-huan-kong-ge-lcof.rs b/src/bin/ti-huan-kong-ge-lcof.rs index bf3a9574..97b23ed4 100644 --- a/src/bin/ti-huan-kong-ge-lcof.rs +++ b/src/bin/ti-huan-kong-ge-lcof.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 6656685d2c8355246aac954dc6a98b974d078f9f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:23 +0800 Subject: [PATCH 0495/1556] src/bin/to-lower-case.rs --- src/bin/to-lower-case.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/to-lower-case.rs b/src/bin/to-lower-case.rs index d70d968b..2bd45040 100644 --- a/src/bin/to-lower-case.rs +++ b/src/bin/to-lower-case.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + use serde::de::Unexpected::Str; fn main() {} From afa107f8c6c63f22119e7107301b959bcebcf8e2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:23 +0800 Subject: [PATCH 0496/1556] src/bin/triangle.rs --- src/bin/triangle.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/triangle.rs b/src/bin/triangle.rs index 81716ca0..2a172726 100644 --- a/src/bin/triangle.rs +++ b/src/bin/triangle.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 03bccbc7346b20ebe117c340a94815bca1a0e08d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:24 +0800 Subject: [PATCH 0497/1556] src/bin/two-sum-ii-input-array-is-sorted.rs --- src/bin/two-sum-ii-input-array-is-sorted.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/two-sum-ii-input-array-is-sorted.rs b/src/bin/two-sum-ii-input-array-is-sorted.rs index 1fc7b0a5..bd3bb0ad 100644 --- a/src/bin/two-sum-ii-input-array-is-sorted.rs +++ b/src/bin/two-sum-ii-input-array-is-sorted.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From f94bbc4058ee56a26e5b0790edb346062a6bd728 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:24 +0800 Subject: [PATCH 0498/1556] src/bin/two-sum-iv-input-is-a-bst.rs --- src/bin/two-sum-iv-input-is-a-bst.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/two-sum-iv-input-is-a-bst.rs b/src/bin/two-sum-iv-input-is-a-bst.rs index c694666f..edbfb3d6 100644 --- a/src/bin/two-sum-iv-input-is-a-bst.rs +++ b/src/bin/two-sum-iv-input-is-a-bst.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From dc9676b34f1ee898e7fafc4f70a19908c65d9792 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:24 +0800 Subject: [PATCH 0499/1556] src/bin/two-sum.rs --- src/bin/two-sum.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/two-sum.rs b/src/bin/two-sum.rs index bf7e98db..0ad05dbe 100644 --- a/src/bin/two-sum.rs +++ b/src/bin/two-sum.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 760279f9d3827b1de76805f4b159594452081559 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:25 +0800 Subject: [PATCH 0500/1556] src/bin/ugly-number.rs --- src/bin/ugly-number.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/ugly-number.rs b/src/bin/ugly-number.rs index e1c9e240..d711d81a 100644 --- a/src/bin/ugly-number.rs +++ b/src/bin/ugly-number.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 38d18a5d9f0540cd5a8064d745c89083ecaf20bc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:25 +0800 Subject: [PATCH 0501/1556] src/bin/unique-binary-search-trees-ii.rs --- src/bin/unique-binary-search-trees-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/unique-binary-search-trees-ii.rs b/src/bin/unique-binary-search-trees-ii.rs index 1b743fa1..bf84a90a 100644 --- a/src/bin/unique-binary-search-trees-ii.rs +++ b/src/bin/unique-binary-search-trees-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{:?}", Solution::generate_trees(3)) } From 6c273f338ddedfe7481d9c0c7b3b316c35d610ff Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:25 +0800 Subject: [PATCH 0502/1556] src/bin/unique-binary-search-trees.rs --- src/bin/unique-binary-search-trees.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/unique-binary-search-trees.rs b/src/bin/unique-binary-search-trees.rs index e2ff43b7..68da01a3 100644 --- a/src/bin/unique-binary-search-trees.rs +++ b/src/bin/unique-binary-search-trees.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { println!("{}", Solution::num_trees(3)); println!("{}", Solution::num_trees(4)); From 43d4f12edb5787bc205afd303ba9a4709a99481a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:26 +0800 Subject: [PATCH 0503/1556] src/bin/unique-paths-ii.rs --- src/bin/unique-paths-ii.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/unique-paths-ii.rs b/src/bin/unique-paths-ii.rs index 13563372..96fef023 100644 --- a/src/bin/unique-paths-ii.rs +++ b/src/bin/unique-paths-ii.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From d1aa2aa3c2845c34147cdba5ea1f169b61ac9b33 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:26 +0800 Subject: [PATCH 0504/1556] src/bin/unique-paths.rs --- src/bin/unique-paths.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/unique-paths.rs b/src/bin/unique-paths.rs index 5d96b708..84d31ff1 100644 --- a/src/bin/unique-paths.rs +++ b/src/bin/unique-paths.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(28, Solution::unique_paths(3, 7)); } From d8b8ece3880d16704536970225d340e3a8cc1639 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:27 +0800 Subject: [PATCH 0505/1556] src/bin/univalued-binary-tree.rs --- src/bin/univalued-binary-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/univalued-binary-tree.rs b/src/bin/univalued-binary-tree.rs index 8f1c47d5..e7a78382 100644 --- a/src/bin/univalued-binary-tree.rs +++ b/src/bin/univalued-binary-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + // Definition for a binary tree node. #[derive(Debug, PartialEq, Eq)] pub struct TreeNode { From 7cf34ed018febd8dbd85bbfd5287a3cbddd0d53a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:27 +0800 Subject: [PATCH 0506/1556] src/bin/utf-8-validation.rs --- src/bin/utf-8-validation.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/utf-8-validation.rs b/src/bin/utf-8-validation.rs index 2bb5f5b5..1c534d62 100644 --- a/src/bin/utf-8-validation.rs +++ b/src/bin/utf-8-validation.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert!(Solution::valid_utf8(vec![197, 130, 1])); assert!(!Solution::valid_utf8(vec![235, 140, 4])); From a10b0bd56980f2e798512c540b87f1f04aadb2d0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:27 +0800 Subject: [PATCH 0507/1556] src/bin/valid-anagram.rs --- src/bin/valid-anagram.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/valid-anagram.rs b/src/bin/valid-anagram.rs index f60f6785..c497d481 100644 --- a/src/bin/valid-anagram.rs +++ b/src/bin/valid-anagram.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 079c1b721b315d6fc3f4812035a6a1b2454fae9b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:28 +0800 Subject: [PATCH 0508/1556] src/bin/valid-palindrome.rs --- src/bin/valid-palindrome.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/valid-palindrome.rs b/src/bin/valid-palindrome.rs index 51a0def7..91a93535 100644 --- a/src/bin/valid-palindrome.rs +++ b/src/bin/valid-palindrome.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(true, Solution::is_palindrome("A aa".to_string())); } From 2a7a21e2ec0dfab9f01e06fb07775a6bf5fdf795 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:28 +0800 Subject: [PATCH 0509/1556] src/bin/valid-parentheses.rs --- src/bin/valid-parentheses.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/valid-parentheses.rs b/src/bin/valid-parentheses.rs index 31506fc8..98d4c1a0 100644 --- a/src/bin/valid-parentheses.rs +++ b/src/bin/valid-parentheses.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 00d977baad6332ae3325469c6e39306ebc08b573 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:29 +0800 Subject: [PATCH 0510/1556] src/bin/valid-perfect-square.rs --- src/bin/valid-perfect-square.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/valid-perfect-square.rs b/src/bin/valid-perfect-square.rs index 732f41c7..7291ee5d 100644 --- a/src/bin/valid-perfect-square.rs +++ b/src/bin/valid-perfect-square.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(true, Solution::is_perfect_square(4), "4"); assert_eq!(false, Solution::is_perfect_square(5), "5"); From 1ffa2503e3d74c6b095853cc781330b8e4e0127c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:29 +0800 Subject: [PATCH 0511/1556] src/bin/valid-sudoku.rs --- src/bin/valid-sudoku.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/valid-sudoku.rs b/src/bin/valid-sudoku.rs index 84b654b8..6726005e 100644 --- a/src/bin/valid-sudoku.rs +++ b/src/bin/valid-sudoku.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 195c0de9919026b8edd3918093e264f6fe15ffaf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:30 +0800 Subject: [PATCH 0512/1556] src/bin/validate-binary-search-tree.rs --- src/bin/validate-binary-search-tree.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/validate-binary-search-tree.rs b/src/bin/validate-binary-search-tree.rs index 7371c61b..de5d0934 100644 --- a/src/bin/validate-binary-search-tree.rs +++ b/src/bin/validate-binary-search-tree.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From c483653b13b8b2a17d34de3e2a0b8e0f439bb4b6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:30 +0800 Subject: [PATCH 0513/1556] src/bin/water-bottles.rs --- src/bin/water-bottles.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/water-bottles.rs b/src/bin/water-bottles.rs index 721c2b7a..dbd4a317 100644 --- a/src/bin/water-bottles.rs +++ b/src/bin/water-bottles.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { assert_eq!(19, Solution::num_water_bottles(15, 4)); } From 3899288b5d7869b55bb6c78d57c6f6bb33e109a4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:30 +0800 Subject: [PATCH 0514/1556] src/bin/wiggle-subsequence.rs --- src/bin/wiggle-subsequence.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/wiggle-subsequence.rs b/src/bin/wiggle-subsequence.rs index b0e0133b..87f8edf5 100644 --- a/src/bin/wiggle-subsequence.rs +++ b/src/bin/wiggle-subsequence.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From 46ab12218c34a1fc17d273b96dd04e001ee387ad Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:31 +0800 Subject: [PATCH 0515/1556] src/bin/word-pattern.rs --- src/bin/word-pattern.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/word-pattern.rs b/src/bin/word-pattern.rs index 6e7f54ab..21fdf99f 100644 --- a/src/bin/word-pattern.rs +++ b/src/bin/word-pattern.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From c2ddc6584c188456477f301d65dbd755a56f6883 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:31 +0800 Subject: [PATCH 0516/1556] src/bin/word-search.rs --- src/bin/word-search.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/word-search.rs b/src/bin/word-search.rs index da0964e1..a7a1dea6 100644 --- a/src/bin/word-search.rs +++ b/src/bin/word-search.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() {} struct Solution; From d42847340d5430007d7aacc7d7e423bcf47efa98 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:32 +0800 Subject: [PATCH 0517/1556] src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs --- src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs b/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs index f8abde3f..fcfca4fb 100644 --- a/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs +++ b/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + /// 思路: /// 栈stack1用来存放插入的数据 /// 栈stack2用来存放删除的数据 From b933df4fd8f19e11d3813d950c718c6d4a4d1b8a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:32 +0800 Subject: [PATCH 0518/1556] src/bin/zhong-jian-er-cha-shu-lcof.rs --- src/bin/zhong-jian-er-cha-shu-lcof.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/zhong-jian-er-cha-shu-lcof.rs b/src/bin/zhong-jian-er-cha-shu-lcof.rs index 526af239..fc487dfc 100644 --- a/src/bin/zhong-jian-er-cha-shu-lcof.rs +++ b/src/bin/zhong-jian-er-cha-shu-lcof.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + use std::cell::RefCell; use std::rc::Rc; From b04363b4f09fdd6e95475af27305488326a84b0a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:33 +0800 Subject: [PATCH 0519/1556] src/bin/zigzag-conversion.rs --- src/bin/zigzag-conversion.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin/zigzag-conversion.rs b/src/bin/zigzag-conversion.rs index 4d57748c..81b6cf98 100644 --- a/src/bin/zigzag-conversion.rs +++ b/src/bin/zigzag-conversion.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused, unused_variables)] + fn main() { // assert_eq!(Solution::convert("LEETCODEISHIRINGS".to_string(), 4), "LDREOEIIECIHNSTSG".to_string()); assert_eq!(Solution::convert("AB".to_string(), 1), "AB".to_string()); From 906e6b3b5e8b3dfa2eac7c0c4d5019263bb6f0ee Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:13:33 +0800 Subject: [PATCH 0520/1556] README.md --- README.md | 288 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 287 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 21ad8d20..a80948fd 100644 --- a/README.md +++ b/README.md @@ -2,338 +2,624 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 329 | 153 | 169 | 7 | +| 615 | 286 | 315 | 14 | ### 题目 | 编号 | 题目 | 代码 | 题目描述 | 难度 | | ---- | ---- | ---- | ---- | ---- | |1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | Easy | +|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | Easy | |2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | Medium | |3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | Medium | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | Medium | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Hard | |4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Hard | |6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | Medium | +|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | Medium | |7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | Easy | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | Medium | +|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | Medium | |8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | Medium | |9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number/) | Easy | +|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number/) | Easy | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | Medium | |11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | Medium | |12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) | Medium | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) | Medium | +|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer/) | Easy | |13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer/) | Easy | |14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix/) | Easy | +|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix/) | Easy | |15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum/) | Medium | |16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest/) | Medium | |17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | Medium | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | Medium | |18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | Medium | |19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Medium | +|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Medium | +|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | Easy | |20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | Easy | |21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | Easy | +|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | Easy | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Hard | |23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Hard | |24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | Medium | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | Medium | +|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Hard | |25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Hard | |26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | Easy | +|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | Easy | +|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | Easy | |27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | Easy | |28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | Easy | +|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | Easy | |31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Medium | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Medium | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Medium | |33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Medium | |34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Medium | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Medium | +|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | Easy | |35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | Easy | |36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Medium | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Medium | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Medium | |38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Medium | |39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Hard | |41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Hard | |43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Medium | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Medium | +|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Medium | |45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Medium | |46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Medium | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Medium | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | Medium | |48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | Medium | |49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | Medium | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | Medium | +|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | Medium | |50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | Medium | |51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Hard | +|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Hard | +|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Hard | |52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Hard | |53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) | Easy | +|53 | 最大子数组和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) | Easy | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | Medium | |55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | Medium | |56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | Medium | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | Medium | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | Medium | |57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | Medium | |58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word/) | Easy | +|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word/) | Easy | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths/) | Medium | |62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths/) | Medium | |63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) | Medium | +|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) | Medium | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) | Medium | |64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) | Medium | |66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | Easy | +|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | Easy | |67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary/) | Easy | |69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | Easy | +|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | Easy | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | Easy | |70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | Easy | |71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | Medium | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | Medium | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | Medium | |73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | Medium | |74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | Medium | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | Medium | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | Medium | |75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | Medium | |77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | Medium | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | Medium | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | Medium | |78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | Medium | |79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | Medium | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | Medium | +|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) | Medium | |80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) | Medium | |81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | Medium | +|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | Medium | |82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | Medium | +|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | Medium | +|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | Easy | |83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | Easy | |88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | Easy | +|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | Easy | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Medium | |89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Medium | |91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Medium | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Medium | +|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | Medium | |93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | Medium | |94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) | Easy | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) | Easy | +|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | Medium | |95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | Medium | |96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | Medium | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | Medium | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | Medium | |98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | Medium | |100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree/) | Easy | +|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree/) | Easy | +|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) | Easy | |101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) | Easy | |102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | Medium | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | Medium | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | Medium | |103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | Medium | |104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | Easy | +|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | Easy | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | Medium | |105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | Medium | |106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | Medium | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | Medium | |107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | Medium | +|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | Medium | +|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) | Easy | |108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) | Easy | |110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree/) | Easy | |111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) | Easy | +|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) | Easy | +|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum/) | Easy | |112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum/) | Easy | |113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) | Medium | +|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) | Medium | +|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle/) | Easy | |118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle/) | Easy | |119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii/) | Easy | +|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii/) | Easy | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | Medium | |120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | Medium | |121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/) | Easy | |122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | Easy | |125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | Easy | +|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | Easy | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Medium | |129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Medium | |136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | Easy | +|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | Easy | +|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Medium | |137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Medium | |144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | Easy | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | Easy | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | Easy | |145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | Easy | |150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Medium | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Medium | |151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | Medium | +|151 | 颠倒字符串中的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | Medium | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Medium | |152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Medium | |153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | Medium | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | Medium | |155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | Easy | +|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | Medium | |162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | Medium | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | Medium | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | Medium | |165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | Medium | |166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | Medium | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | Medium | |167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | Easy | +|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | Medium | +|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | Easy | |168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | Easy | |169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element/) | Easy | +|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element/) | Easy | +|171 | Excel 表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) | Easy | |171 | Excel 表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) | Easy | |172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | Easy | +|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | Medium | |173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | Medium | |187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | Medium | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | Medium | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | Easy | |190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | Easy | |191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | Easy | +|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | Easy | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | Medium | |198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | Medium | |199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | Medium | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | Medium | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | Medium | |200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | Medium | |201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | Medium | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | Medium | +|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number/) | Easy | |202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number/) | Easy | |203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) | Easy | +|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) | Easy | |204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | Easy | +|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | Medium | +|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | Easy | |205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | Easy | |206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | Easy | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | Easy | |208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | Medium | +|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | Medium | +|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | Medium | |211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | Medium | |213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | Medium | +|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | Medium | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) | Medium | |215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) | Medium | |216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) | Medium | +|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) | Medium | +|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate/) | Easy | |217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate/) | Easy | |219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii/) | Easy | +|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii/) | Easy | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) | Medium | |222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) | Medium | |223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area/) | Medium | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area/) | Medium | +|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues/) | Easy | |225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues/) | Easy | |226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree/) | Easy | +|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree/) | Easy | +|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges/) | Easy | |228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges/) | Easy | |229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) | Medium | +|229 | 多数元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) | Medium | |230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) | Medium | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) | Medium | +|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two/) | Easy | |231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two/) | Easy | |232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks/) | Easy | +|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks/) | Easy | +|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) | Easy | |234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) | Easy | |235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | Easy | +|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | Easy | |238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Medium | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Medium | +|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | Easy | |242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | Easy | |257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | Easy | +|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | Easy | |258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits/) | Easy | |263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | Easy | +|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | Easy | |268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | Easy | +|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | Easy | +|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Medium | |274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Medium | |278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | |279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | |283 | 移动零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/move-zeroes/) | Easy | +|283 | 移动零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/move-zeroes/) | Easy | +|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | |290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | |292 | Nim 游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nim-game.rs) | [leetcode](https://leetcode-cn.com/problems/nim-game/) | Easy | +|292 | Nim 游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nim-game.rs) | [leetcode](https://leetcode-cn.com/problems/nim-game/) | Easy | +|300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | |300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | |303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | +|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | |318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | |319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | +|322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | |322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | |326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | +|326 | 3 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | +|344 | 反转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string/) | Easy | |344 | 反转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string/) | Easy | |349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | +|350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | |350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | |357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | +|357 | 统计各位数字都不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | |367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | +|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | |371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | +|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | +|376 | 摆动序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wiggle-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/wiggle-subsequence/) | Medium | |376 | 摆动序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wiggle-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/wiggle-subsequence/) | Medium | |378 | 有序矩阵中第 K 小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-sorted-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/) | Medium | +|378 | 有序矩阵中第 K 小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-sorted-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/) | Medium | +|380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | |380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | |381 | O(1) 时间插入、删除和获取随机元素 - 允许重复 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed/) | Hard | +|381 | O(1) 时间插入、删除和获取随机元素 - 允许重复 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed/) | Hard | +|382 | 链表随机节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/linked-list-random-node.rs) | [leetcode](https://leetcode-cn.com/problems/linked-list-random-node/) | Medium | |382 | 链表随机节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/linked-list-random-node.rs) | [leetcode](https://leetcode-cn.com/problems/linked-list-random-node/) | Medium | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | +|383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | +|384 | 打乱数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shuffle-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/shuffle-an-array/) | Medium | |384 | 打乱数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shuffle-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/shuffle-an-array/) | Medium | |386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | |386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | +|386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | +|389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | +|392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | |392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | |393 | UTF-8 编码验证 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/utf-8-validation.rs) | [leetcode](https://leetcode-cn.com/problems/utf-8-validation/) | Medium | +|393 | UTF-8 编码验证 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/utf-8-validation.rs) | [leetcode](https://leetcode-cn.com/problems/utf-8-validation/) | Medium | |397 | 整数替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-replacement.rs) | [leetcode](https://leetcode-cn.com/problems/integer-replacement/) | Medium | +|397 | 整数替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-replacement.rs) | [leetcode](https://leetcode-cn.com/problems/integer-replacement/) | Medium | +|398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |400 | 第 N 位数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nth-digit.rs) | [leetcode](https://leetcode-cn.com/problems/nth-digit/) | Medium | +|400 | 第 N 位数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nth-digit.rs) | [leetcode](https://leetcode-cn.com/problems/nth-digit/) | Medium | +|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |409 | 最长回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindrome/) | Easy | +|409 | 最长回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindrome/) | Easy | +|412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | |412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | |413 | 等差数列划分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/arithmetic-slices.rs) | [leetcode](https://leetcode-cn.com/problems/arithmetic-slices/) | Medium | |415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | +|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | |442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | |442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | +|442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | |445 | 两数相加 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers-ii.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers-ii/) | Medium | |448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | +|448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | |449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | |449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | +|449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | +|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | |476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | +|485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | +|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | |504 | 七进制数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/base-7.rs) | [leetcode](https://leetcode-cn.com/problems/base-7/) | Easy | |507 | 完美数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-number.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-number/) | Easy | +|507 | 完美数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-number.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-number/) | Easy | +|508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | |508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | |508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | |513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | |513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | +|513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | +|515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | |515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | |515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | +|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | |530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | |530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | |530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | +|530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | +|535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | +|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | +|560 | 和为 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | |565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | |594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | +|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | |605 | 种花问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/can-place-flowers.rs) | [leetcode](https://leetcode-cn.com/problems/can-place-flowers/) | Easy | +|605 | 种花问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/can-place-flowers.rs) | [leetcode](https://leetcode-cn.com/problems/can-place-flowers/) | Easy | +|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | |623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | |623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | |637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | |637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | |643 | 子数组最大平均数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-average-subarray-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-average-subarray-i/) | Easy | +|643 | 子数组最大平均数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-average-subarray-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-average-subarray-i/) | Easy | +|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | |649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | |650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | |653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | +|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | +|657 | 机器人能否返回原点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-return-to-origin.rs) | [leetcode](https://leetcode-cn.com/problems/robot-return-to-origin/) | Easy | |657 | 机器人能否返回原点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-return-to-origin.rs) | [leetcode](https://leetcode-cn.com/problems/robot-return-to-origin/) | Easy | |657 | 机器人能否返回原点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-return-to-origin.rs) | [leetcode](https://leetcode-cn.com/problems/robot-return-to-origin/) | Easy | |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | +|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | +|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | |718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | |718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | +|718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | |742 | 转换成小写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/to-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/to-lower-case/) | Easy | +|742 | 转换成小写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/to-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/to-lower-case/) | Easy | +|782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | |782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | |782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | |783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | |783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | +|783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | +|784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | |784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | |784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | +|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | +|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | +|860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | |917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | +|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | |921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | |924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | +|924 | 公平的糖果交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | |925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | +|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | +|936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | +|947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | |947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | |947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | +|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | |981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | +|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Medium | |982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Medium | |1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | Medium | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | Medium | +|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | Easy | |1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | Easy | |1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | +|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | |1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | |1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | +|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | |1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | |1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | +|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | |1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | +|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | |1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | +|1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | +|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | +|1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | |1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | |1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | +|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | +|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | |1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | |1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | +|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | |1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | +|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | |1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | |1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | +|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | |1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | +|1426 | 和为零的 N 个不同整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | |1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Medium | +|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Medium | +|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | Easy | |1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | Easy | |1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | +|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | |1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | |1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | +|1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | +|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | |1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | +|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | |1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | |1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Medium | |1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Medium | |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | +|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | |1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | +|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | |1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | |1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | Easy | +|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | Easy | +|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | Easy | |1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | Easy | |1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | +|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | +|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | |1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | +|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | +|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | +|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | +|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | |1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | +|2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | +|2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | +|2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | +|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | +|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | +|100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | |100277 | 青蛙跳台阶问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) | Easy | +|100277 | 青蛙跳台阶问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) | Easy | +|100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | |100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | |100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | +|100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | +|100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | +|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | +|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | +|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | |100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | +|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | +|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | |100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | |100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | +|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | |100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | |1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | +|1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | +|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | From 638b74932dcc0435960b410fdf50e7a0d960ec7b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:23:00 +0800 Subject: [PATCH 0521/1556] src/bin/encode-and-decode-tinyurl.rs --- src/bin/encode-and-decode-tinyurl.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bin/encode-and-decode-tinyurl.rs b/src/bin/encode-and-decode-tinyurl.rs index ad695077..be56aeb2 100644 --- a/src/bin/encode-and-decode-tinyurl.rs +++ b/src/bin/encode-and-decode-tinyurl.rs @@ -26,18 +26,18 @@ impl Codec { } // Encodes a URL to a shortened URL. - fn encode(&mut self, longURL: String) -> String { + fn encode(&mut self, long_url: String) -> String { let mut s = std::collections::hash_map::DefaultHasher::new(); - ::hash(&longURL, &mut s); + ::hash(&long_url, &mut s); let hash_code = ::finish(&s); - self.hash.insert(hash_code, longURL); + self.hash.insert(hash_code, long_url); format!("http://tinyurl.com/{}", hash_code) } // Decodes a shortened URL to its original URL. - fn decode(&self, shortURL: String) -> String { - let hash_code = shortURL + fn decode(&self, short_url: String) -> String { + let hash_code = short_url .trim_start_matches("http://tinyurl.com/") .parse::() .unwrap(); From 71874248982db01db0907f87863b5d28fce1db9f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:23:00 +0800 Subject: [PATCH 0522/1556] src/bin/first-bad-version.rs --- src/bin/first-bad-version.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/first-bad-version.rs b/src/bin/first-bad-version.rs index 7ce7a21d..c91dbbfa 100644 --- a/src/bin/first-bad-version.rs +++ b/src/bin/first-bad-version.rs @@ -1,4 +1,4 @@ -#![allow(dead_code, unused, unused_variables)] +#![allow(dead_code, unused, unused_variables, non_snake_case)] fn main() { // println!("{}", Solution::new(1702766719).first_bad_version(2126753390)); From 5270b36ddd8d18443f6c5ff80ca9c5d5ce7594f6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:23:00 +0800 Subject: [PATCH 0523/1556] src/bin/guess-number-higher-or-lower.rs --- src/bin/guess-number-higher-or-lower.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/guess-number-higher-or-lower.rs b/src/bin/guess-number-higher-or-lower.rs index e5a623e7..181e2339 100644 --- a/src/bin/guess-number-higher-or-lower.rs +++ b/src/bin/guess-number-higher-or-lower.rs @@ -1,4 +1,4 @@ -#![allow(dead_code, unused, unused_variables)] +#![allow(dead_code, unused, unused_variables, non_snake_case)] struct Solution; From 2a255695d9600f31c71f303642a23cd19bf0d4bc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:23:01 +0800 Subject: [PATCH 0524/1556] src/bin/number-of-1-bits.rs --- src/bin/number-of-1-bits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/number-of-1-bits.rs b/src/bin/number-of-1-bits.rs index 735318c4..12c3369c 100644 --- a/src/bin/number-of-1-bits.rs +++ b/src/bin/number-of-1-bits.rs @@ -1,4 +1,4 @@ -#![allow(dead_code, unused, unused_variables)] +#![allow(dead_code, unused, unused_variables, non_snake_case)] fn main() {} From 22c91e68317a1c15d2a14e2627adf2ccfbd08b27 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:23:01 +0800 Subject: [PATCH 0525/1556] README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a80948fd..8e71da81 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 615 | 286 | 315 | 14 | +| 619 | 289 | 316 | 14 | ### 题目 @@ -106,7 +106,7 @@ |66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | Easy | |67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary/) | Easy | |69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | Easy | -|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | Easy | +|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | Easy | |70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | Easy | |70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | Easy | |71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | Medium | @@ -225,6 +225,7 @@ |190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | Easy | |191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | Easy | |191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | Easy | +|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | Easy | |198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | Medium | |198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | Medium | |199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | Medium | @@ -294,6 +295,7 @@ |274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Medium | |278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | |278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | |279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | |279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | |283 | 移动零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/move-zeroes/) | Easy | @@ -328,6 +330,7 @@ |371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | +|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | |376 | 摆动序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wiggle-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/wiggle-subsequence/) | Medium | |376 | 摆动序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wiggle-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/wiggle-subsequence/) | Medium | |378 | 有序矩阵中第 K 小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-sorted-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/) | Medium | @@ -413,6 +416,7 @@ |535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | +|535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | From b267b76bdfd7b40c37467d3a69073f6bc6dc2b00 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 12:23:14 +0800 Subject: [PATCH 0526/1556] add lint ignore --- src/file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file.rs b/src/file.rs index 42afa948..22b04648 100644 --- a/src/file.rs +++ b/src/file.rs @@ -52,7 +52,7 @@ pub fn write_question(resp: Resp) { let mut f = File::create(file.as_str()).unwrap(); let mut s = String::new(); - s.push_str("#![allow(dead_code, unused, unused_variables)]\n\n"); + s.push_str("#![allow(dead_code, unused, unused_variables, non_snake_case)]\n\n"); s.push_str("fn main() {}\n\n"); s.push_str("struct Solution;\n\n"); From db3c67781976a147fe765c8462afc1eb4bc7c7b9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 14:42:28 +0800 Subject: [PATCH 0527/1556] src/bin/find-minimum-in-rotated-sorted-array-ii.rs --- ...find-minimum-in-rotated-sorted-array-ii.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/find-minimum-in-rotated-sorted-array-ii.rs diff --git a/src/bin/find-minimum-in-rotated-sorted-array-ii.rs b/src/bin/find-minimum-in-rotated-sorted-array-ii.rs new file mode 100644 index 00000000..4d27152a --- /dev/null +++ b/src/bin/find-minimum-in-rotated-sorted-array-ii.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_min(numbers: Vec) -> i32 { + let (mut start, mut end) = (0, numbers.len() - 1); + + while start < end { + let middile = start + (end - start) / 2; + if numbers[middile] < numbers[end] { + end = middile; + } else if numbers[middile] > numbers[end] { + start = middile + 1; + } else { + end -= 1; + } + } + + numbers[start] + } +} From de6d5c5d3ec9bb3abcc0485ecb22d47003f75200 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 14:42:29 +0800 Subject: [PATCH 0528/1556] src/bin/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof.rs --- ...an-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof.rs diff --git a/src/bin/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof.rs b/src/bin/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof.rs new file mode 100644 index 00000000..bd005c7b --- /dev/null +++ b/src/bin/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_array(numbers: Vec) -> i32 { + let (mut start, mut end) = (0, numbers.len() - 1); + + while start < end { + let middile = start + (end - start) / 2; + if numbers[middile] < numbers[end] { + end = middile; + } else if numbers[middile] > numbers[end] { + start = middile + 1; + } else { + end -= 1; + } + } + + numbers[start] + } +} From 1c920dc130d0aad71e81a901889d6359072b6ff8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Jul 2022 14:42:29 +0800 Subject: [PATCH 0529/1556] README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e71da81..fc72987e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 619 | 289 | 316 | 14 | +| 621 | 290 | 316 | 15 | ### 题目 @@ -200,6 +200,7 @@ |152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Medium | |153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | Medium | |153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | Medium | +|154 | 寻找旋转排序数组中的最小值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii/) | Hard | |155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | Easy | |155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | Medium | |162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | Medium | @@ -599,6 +600,7 @@ |100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | |100277 | 青蛙跳台阶问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) | Easy | |100277 | 青蛙跳台阶问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) | Easy | +|100278 | 旋转数组的最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/) | Easy | |100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | |100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | |100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | From 8d18db010180128b64b58dc5d0dd62df6406085f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 25 Jul 2022 10:28:17 +0800 Subject: [PATCH 0530/1556] src/bin/ji-qi-ren-de-yun-dong-fan-wei-lcof.rs --- src/bin/ji-qi-ren-de-yun-dong-fan-wei-lcof.rs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/bin/ji-qi-ren-de-yun-dong-fan-wei-lcof.rs diff --git a/src/bin/ji-qi-ren-de-yun-dong-fan-wei-lcof.rs b/src/bin/ji-qi-ren-de-yun-dong-fan-wei-lcof.rs new file mode 100644 index 00000000..57e0ed92 --- /dev/null +++ b/src/bin/ji-qi-ren-de-yun-dong-fan-wei-lcof.rs @@ -0,0 +1,57 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + println!("{}", Solution::moving_count(2, 3, 1)); + println!("{}", Solution::moving_count(3, 1, 0)); + println!("{}", Solution::moving_count(3, 2, 17)); + println!("{}", Solution::moving_count(16, 8, 4)); +} + +struct Solution; + +impl Solution { + pub fn moving_count(m: i32, n: i32, k: i32) -> i32 { + let mut flags = vec![vec![0; n as usize]; m as usize]; + let mut total = 0; + for i in 0..m as usize { + for j in 0..n as usize { + if Self::sum(i, j) <= k + && ((i == 0 && j == 0) + || (i > 0 && flags[i - 1][j] == 1) + || (j > 0 && flags[i][j - 1] == 1)) + { + total += 1; + flags[i][j] = 1; + } + } + } + + total + } + + fn sum(mut x: usize, mut y: usize) -> i32 { + let mut sum = 0; + + while x >= 10 { + sum += x % 10; + x /= 10; + } + + sum += x; + + while y >= 10 { + sum += y % 10; + y /= 10; + } + + sum += y; + + sum as i32 + } +} + +#[test] +fn test_sum() { + assert_eq!(Solution::sum(14, 15), 11); + assert_eq!(Solution::sum(101, 230), 7); +} From 6f39fdecaf1d5d16d0c834d3d2ef944811ec7e35 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 25 Jul 2022 10:28:17 +0800 Subject: [PATCH 0531/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc72987e..48c54435 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 621 | 290 | 316 | 15 | +| 622 | 290 | 317 | 15 | ### 题目 @@ -603,6 +603,7 @@ |100278 | 旋转数组的最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/) | Easy | |100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | |100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | +|100281 | 机器人的运动范围 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ji-qi-ren-de-yun-dong-fan-wei-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/) | Medium | |100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | |100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | From 298a1bf3d3d20d594241228eab9cf966014cef04 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 25 Jul 2022 16:58:26 +0800 Subject: [PATCH 0532/1556] src/bin/jian-sheng-zi-lcof.rs --- src/bin/jian-sheng-zi-lcof.rs | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bin/jian-sheng-zi-lcof.rs diff --git a/src/bin/jian-sheng-zi-lcof.rs b/src/bin/jian-sheng-zi-lcof.rs new file mode 100644 index 00000000..93fd5e22 --- /dev/null +++ b/src/bin/jian-sheng-zi-lcof.rs @@ -0,0 +1,37 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::cutting_rope(10), 36); +} + +struct Solution; + +impl Solution { + /// 记住:剪成长度为3的最好 + pub fn cutting_rope1(n: i32) -> i32 { + if n <= 3 { + return n - 1; + } + + let (a, b) = (n / 3, n % 3); + match b { + 0 => 3i32.pow(a as u32), + 1 => 3i32.pow(a as u32 - 1) * 4, + 2 => 3i32.pow(a as u32) * 2, + _ => unreachable!(), + } + } + + pub fn cutting_rope(n: i32) -> i32 { + let mut dp = vec![0i32; n as usize + 1]; + dp[2] = 1; + + for i in 3..n + 1 { + for j in 2..i { + dp[i as usize] = dp[i as usize].max((j * (i - j)).max(j * dp[(i - j) as usize])); + } + } + + dp[n as usize] + } +} From 57db2736aa26388bc85e5fed074ddb031a8b9167 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 25 Jul 2022 16:58:27 +0800 Subject: [PATCH 0533/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 48c54435..c298eb9d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 622 | 290 | 317 | 15 | +| 623 | 290 | 318 | 15 | ### 题目 @@ -609,6 +609,7 @@ |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | +|100284 | 剪绳子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-lcof/) | Medium | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | From a1504a6917bb649bfbb0b5d4b0f0b786bb2f32c9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 26 Jul 2022 11:19:05 +0800 Subject: [PATCH 0534/1556] src/bin/jian-sheng-zi-ii-lcof.rs --- src/bin/jian-sheng-zi-ii-lcof.rs | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/jian-sheng-zi-ii-lcof.rs diff --git a/src/bin/jian-sheng-zi-ii-lcof.rs b/src/bin/jian-sheng-zi-ii-lcof.rs new file mode 100644 index 00000000..fefe482c --- /dev/null +++ b/src/bin/jian-sheng-zi-ii-lcof.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + println!("{}", Solution::cutting_rope(120)); +} + +struct Solution; + +impl Solution { + pub fn cutting_rope(n: i32) -> i32 { + if n <= 3 { + return n - 1; + } + + let (a, b) = (n / 3, n % 3); + + let r = match b { + 0 => Self::calc(a as u32, 1), + 1 => Self::calc(a as u32 - 1, 4), + 2 => Self::calc(a as u32, 2), + _ => unreachable!(), + }; + + (r % 1000000007) as i32 + } + + fn calc(x: u32, y: i64) -> i32 { + let mut r = 1i64; + for _i in 0..x { + r *= 3; + r %= 1000000007; + } + + (r * y % 1000000007) as i32 + } +} From a1e012f7159d598547cbfb780e1b3842491b0cbf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 26 Jul 2022 11:19:05 +0800 Subject: [PATCH 0535/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c298eb9d..598593bd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 623 | 290 | 318 | 15 | +| 624 | 290 | 319 | 15 | ### 题目 @@ -610,6 +610,7 @@ |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100284 | 剪绳子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-lcof/) | Medium | +|100285 | 剪绳子 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/) | Medium | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | From ad49926bbd0260f9d63f35fa55500325bc5b5f9a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 26 Jul 2022 12:43:42 +0800 Subject: [PATCH 0536/1556] README.md --- README.md | 315 +----------------------------------------------------- 1 file changed, 2 insertions(+), 313 deletions(-) diff --git a/README.md b/README.md index 598593bd..44d2111e 100644 --- a/README.md +++ b/README.md @@ -2,633 +2,322 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 624 | 290 | 319 | 15 | +| 313 | 141 | 164 | 8 | ### 题目 | 编号 | 题目 | 代码 | 题目描述 | 难度 | | ---- | ---- | ---- | ---- | ---- | |1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | Easy | -|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | Easy | |2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | Medium | |3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | Medium | -|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | Medium | -|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Hard | |4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Hard | |6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | Medium | -|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | Medium | -|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | Easy | |7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | Medium | |8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | Medium | -|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | Medium | |9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number/) | Easy | -|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number/) | Easy | -|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | Medium | |11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | Medium | |12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) | Medium | -|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) | Medium | |13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer/) | Easy | -|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer/) | Easy | -|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix/) | Easy | |14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix/) | Easy | |15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum/) | Medium | |16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest/) | Medium | |17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | Medium | -|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | Medium | |18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | Medium | |19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Medium | -|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Medium | -|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | Easy | |20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | Easy | |21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | Easy | -|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | Easy | -|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Hard | |23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Hard | |24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | Medium | -|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | Medium | -|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Hard | |25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Hard | |26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | Easy | -|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | Easy | -|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | Easy | |27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | Easy | |28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | Easy | -|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | Easy | -|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Medium | |31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Medium | |33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Medium | -|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Medium | |34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Medium | -|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Medium | -|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | Easy | |35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | Easy | |36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Medium | -|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Medium | -|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Medium | |38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Medium | |39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | -|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | |41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Hard | -|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Hard | -|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Medium | |43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Medium | |45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Medium | -|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Medium | -|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Medium | |46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Medium | |48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | Medium | -|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | Medium | |49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | Medium | -|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | Medium | -|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | Medium | |50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | Medium | |51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Hard | -|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Hard | -|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Hard | |52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Hard | -|53 | 最大子序和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) | Easy | |53 | 最大子数组和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) | Easy | |55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | Medium | -|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | Medium | -|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | Medium | |56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | Medium | |57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | Medium | -|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | Medium | -|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word/) | Easy | |58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word/) | Easy | |62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths/) | Medium | -|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths/) | Medium | |63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) | Medium | -|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) | Medium | -|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) | Medium | |64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) | Medium | |66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | Easy | -|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | Easy | |67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary/) | Easy | |69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | Easy | -|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | Easy | -|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | Easy | |70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | Easy | |71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | Medium | -|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | Medium | -|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | Medium | |73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | Medium | |74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | Medium | -|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | Medium | -|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | Medium | |75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | Medium | |77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | Medium | -|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | Medium | |78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | Medium | -|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | Medium | -|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | Medium | |79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | Medium | |80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) | Medium | -|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) | Medium | -|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | Medium | |81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | Medium | |82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | Medium | -|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | Medium | -|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | Easy | |83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | Easy | |88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | Easy | -|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | Easy | -|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Medium | |89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Medium | |91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Medium | -|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Medium | |93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | Medium | -|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | Medium | -|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) | Easy | |94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) | Easy | |95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | Medium | -|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | Medium | -|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | Medium | |96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | Medium | |98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | Medium | -|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | Medium | -|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree/) | Easy | |100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree/) | Easy | |101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) | Easy | -|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) | Easy | -|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | Medium | |102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | Medium | |103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | Medium | -|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | Medium | |104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | Easy | -|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | Easy | -|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | Medium | |105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | Medium | |106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | Medium | -|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | Medium | -|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | Medium | |107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | Medium | |108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) | Easy | -|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) | Easy | |110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree/) | Easy | |111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) | Easy | -|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) | Easy | |112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum/) | Easy | -|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum/) | Easy | -|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) | Medium | |113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) | Medium | |118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle/) | Easy | -|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle/) | Easy | |119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii/) | Easy | -|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii/) | Easy | -|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | Medium | |120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | Medium | |121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/) | Easy | -|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | Easy | +|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | Medium | |125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | Easy | -|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | Easy | -|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Medium | |129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Medium | |136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | Easy | -|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | Easy | |137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Medium | -|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Medium | -|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | Easy | |144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | Easy | |145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | Easy | -|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | Easy | -|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Medium | |150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Medium | -|151 | 翻转字符串里的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | Medium | |151 | 颠倒字符串中的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | Medium | |152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Medium | -|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Medium | -|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | Medium | |153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | Medium | |154 | 寻找旋转排序数组中的最小值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii/) | Hard | -|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | Easy | |155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | Medium | |162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | Medium | -|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | Medium | |165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | Medium | -|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | Medium | -|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | Medium | |166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | Medium | -|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | Easy | |167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | Medium | |168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | Easy | -|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | Easy | -|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element/) | Easy | |169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element/) | Easy | |171 | Excel 表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) | Easy | -|171 | Excel 表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) | Easy | -|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | Easy | |172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | Medium | |173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | Medium | |187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | Medium | -|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | Medium | -|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | Easy | |190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | Easy | |191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | Easy | -|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | Easy | -|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | Easy | |198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | Medium | -|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | Medium | -|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | Medium | |199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | Medium | |200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | Medium | -|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | Medium | -|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | Medium | |201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | Medium | |202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number/) | Easy | -|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number/) | Easy | -|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) | Easy | |203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) | Easy | -|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | Easy | |204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | Medium | |205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | Easy | -|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | Easy | |206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | Easy | -|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | Easy | -|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | Medium | |208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | Medium | |211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | Medium | -|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | Medium | -|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | Medium | |213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | Medium | |215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) | Medium | -|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) | Medium | -|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) | Medium | |216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) | Medium | |217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate/) | Easy | -|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate/) | Easy | -|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii/) | Easy | |219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii/) | Easy | |222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) | Medium | -|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) | Medium | |223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area/) | Medium | -|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area/) | Medium | -|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues/) | Easy | |225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues/) | Easy | |226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree/) | Easy | -|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree/) | Easy | -|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges/) | Easy | |228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges/) | Easy | -|229 | 求众数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) | Medium | |229 | 多数元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) | Medium | |230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) | Medium | -|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) | Medium | |231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two/) | Easy | -|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two/) | Easy | -|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks/) | Easy | |232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks/) | Easy | |234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) | Easy | -|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) | Easy | -|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | Easy | |235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | Easy | |238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Medium | -|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Medium | |242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | Easy | -|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | Easy | -|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | Easy | |257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | Easy | |258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits/) | Easy | |263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | Easy | -|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | Easy | -|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | Easy | |268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | Easy | |274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Medium | -|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Medium | -|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | |278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | -|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | -|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | |279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | |283 | 移动零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/move-zeroes/) | Easy | -|283 | 移动零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/move-zeroes/) | Easy | |290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | -|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | -|292 | Nim 游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nim-game.rs) | [leetcode](https://leetcode-cn.com/problems/nim-game/) | Easy | |292 | Nim 游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nim-game.rs) | [leetcode](https://leetcode-cn.com/problems/nim-game/) | Easy | |300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | -|300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | -|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | |303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | |318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | -|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | -|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | |319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | |322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | -|322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | -|326 | 3的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | |326 | 3 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | |344 | 反转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string/) | Easy | -|344 | 反转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string/) | Easy | -|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | |349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | |350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | -|350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | -|357 | 计算各个位数不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | |357 | 统计各位数字都不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | |367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | -|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | |371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | -|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | -|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | -|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | -|376 | 摆动序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wiggle-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/wiggle-subsequence/) | Medium | |376 | 摆动序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wiggle-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/wiggle-subsequence/) | Medium | |378 | 有序矩阵中第 K 小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-sorted-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/) | Medium | -|378 | 有序矩阵中第 K 小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-sorted-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/) | Medium | -|380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | |380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | |381 | O(1) 时间插入、删除和获取随机元素 - 允许重复 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed/) | Hard | -|381 | O(1) 时间插入、删除和获取随机元素 - 允许重复 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed/) | Hard | |382 | 链表随机节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/linked-list-random-node.rs) | [leetcode](https://leetcode-cn.com/problems/linked-list-random-node/) | Medium | -|382 | 链表随机节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/linked-list-random-node.rs) | [leetcode](https://leetcode-cn.com/problems/linked-list-random-node/) | Medium | -|383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | |384 | 打乱数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shuffle-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/shuffle-an-array/) | Medium | -|384 | 打乱数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shuffle-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/shuffle-an-array/) | Medium | -|386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | -|386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | |386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | -|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | -|389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | |392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | -|392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | -|393 | UTF-8 编码验证 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/utf-8-validation.rs) | [leetcode](https://leetcode-cn.com/problems/utf-8-validation/) | Medium | |393 | UTF-8 编码验证 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/utf-8-validation.rs) | [leetcode](https://leetcode-cn.com/problems/utf-8-validation/) | Medium | |397 | 整数替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-replacement.rs) | [leetcode](https://leetcode-cn.com/problems/integer-replacement/) | Medium | -|397 | 整数替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-replacement.rs) | [leetcode](https://leetcode-cn.com/problems/integer-replacement/) | Medium | -|398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | -|398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |400 | 第 N 位数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nth-digit.rs) | [leetcode](https://leetcode-cn.com/problems/nth-digit/) | Medium | -|400 | 第 N 位数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nth-digit.rs) | [leetcode](https://leetcode-cn.com/problems/nth-digit/) | Medium | -|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |409 | 最长回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindrome/) | Easy | -|409 | 最长回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindrome/) | Easy | -|412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | |412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | |413 | 等差数列划分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/arithmetic-slices.rs) | [leetcode](https://leetcode-cn.com/problems/arithmetic-slices/) | Medium | |415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | -|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | -|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | |442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | -|442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | -|442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | |445 | 两数相加 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers-ii.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers-ii/) | Medium | |448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | -|448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | |449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | -|449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | -|449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | -|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | |476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | -|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | -|485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | -|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | |504 | 七进制数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/base-7.rs) | [leetcode](https://leetcode-cn.com/problems/base-7/) | Easy | |507 | 完美数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-number.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-number/) | Easy | -|507 | 完美数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-number.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-number/) | Easy | -|508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | |508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | -|508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | -|513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | |513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | -|513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | -|515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | |515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | -|515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | -|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | -|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | -|530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | -|530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | |530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | -|530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | -|535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | -|535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | -|535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | -|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | -|560 | 和为K的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | |560 | 和为 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | |565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | |594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | -|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | -|605 | 种花问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/can-place-flowers.rs) | [leetcode](https://leetcode-cn.com/problems/can-place-flowers/) | Easy | |605 | 种花问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/can-place-flowers.rs) | [leetcode](https://leetcode-cn.com/problems/can-place-flowers/) | Easy | |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | -|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | -|623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | |623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | |637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | -|637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | |643 | 子数组最大平均数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-average-subarray-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-average-subarray-i/) | Easy | -|643 | 子数组最大平均数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-average-subarray-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-average-subarray-i/) | Easy | -|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | |649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | |650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | |653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | -|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | -|657 | 机器人能否返回原点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-return-to-origin.rs) | [leetcode](https://leetcode-cn.com/problems/robot-return-to-origin/) | Easy | |657 | 机器人能否返回原点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-return-to-origin.rs) | [leetcode](https://leetcode-cn.com/problems/robot-return-to-origin/) | Easy | -|657 | 机器人能否返回原点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-return-to-origin.rs) | [leetcode](https://leetcode-cn.com/problems/robot-return-to-origin/) | Easy | -|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | -|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | -|718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | -|718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | |718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | |742 | 转换成小写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/to-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/to-lower-case/) | Easy | -|742 | 转换成小写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/to-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/to-lower-case/) | Easy | -|782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | |782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | -|782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | -|783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | |783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | -|783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | -|784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | |784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | -|784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | -|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | -|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | -|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | -|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | -|860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | -|860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | -|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | -|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | |917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | |921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | -|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | -|924 | 公平的糖果棒交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | |924 | 公平的糖果交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | |925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | -|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | -|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | -|936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | -|947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | |947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | -|947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | -|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | |981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | -|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | |982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Medium | -|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Medium | -|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | Medium | |1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | Medium | |1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | Easy | -|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | Easy | -|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | |1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | |1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | -|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | |1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | -|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | -|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | |1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | -|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | -|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | |1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | -|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | -|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | |1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | -|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | -|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | |1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | -|1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | -|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | -|1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | |1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | |1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | -|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | -|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | |1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | |1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | -|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | -|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | |1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | |1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | -|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | -|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | |1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | -|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | -|1426 | 和为零的N个唯一整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | |1426 | 和为零的 N 个不同整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | |1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Medium | -|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Medium | -|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | Easy | |1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | Easy | |1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | -|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | -|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | |1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | |1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | -|1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | -|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | |1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | -|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | -|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | |1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | |1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | -|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | |1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Medium | -|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Medium | -|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | |1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | -|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | -|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | |1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | |1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | Easy | -|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | Easy | |1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | Easy | -|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | Easy | -|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | |1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | |1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | -|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | -|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | -|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | -|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | -|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | |1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | -|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | -|2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | -|2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | -|2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | -|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | -|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | -|100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | -|100277 | 青蛙跳台阶问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) | Easy | |100277 | 青蛙跳台阶问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) | Easy | |100278 | 旋转数组的最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/) | Easy | |100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | -|100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | |100281 | 机器人的运动范围 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ji-qi-ren-de-yun-dong-fan-wei-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/) | Medium | |100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | -|100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | -|100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | -|100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100284 | 剪绳子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-lcof/) | Medium | |100285 | 剪绳子 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/) | Medium | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | -|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | -|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | -|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | -|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | |100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | -|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | -|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | |100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | |100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | -|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | -|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | |100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | |1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | -|1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | -|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | From 6f5137eafc4d328018bd4c109ca10785f6ac584b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 27 Jul 2022 18:10:20 +0800 Subject: [PATCH 0537/1556] src/bin/ju-zhen-zhong-de-lu-jing-lcof.rs --- src/bin/ju-zhen-zhong-de-lu-jing-lcof.rs | 78 ++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/bin/ju-zhen-zhong-de-lu-jing-lcof.rs diff --git a/src/bin/ju-zhen-zhong-de-lu-jing-lcof.rs b/src/bin/ju-zhen-zhong-de-lu-jing-lcof.rs new file mode 100644 index 00000000..dd9d85b7 --- /dev/null +++ b/src/bin/ju-zhen-zhong-de-lu-jing-lcof.rs @@ -0,0 +1,78 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn exist(mut board: Vec>, word: String) -> bool { + let chars: Vec = word.chars().collect(); + for i in 0..board.len() { + for j in 0..board[i].len() { + if board[i][j] == chars[0] { + let x = board[i][j]; + board[i][j] = '0'; + if Self::scan(i, j, &mut board[..], &chars[1..]) { + return true; + } + + board[i][j] = x; + } + } + } + + false + } + + fn scan(i: usize, j: usize, board: &mut [Vec], word: &[char]) -> bool { + if word.is_empty() { + return true; + } + + if i > 0 { + if board[i - 1][j] == word[0] { + let x = board[i - 1][j]; + board[i - 1][j] = '0'; + if Self::scan(i - 1, j, board, &word[1..]) { + return true; + } + board[i - 1][j] = x; + } + } + + if j > 0 { + if board[i][j - 1] == word[0] { + let x = board[i][j - 1]; + board[i][j - 1] = '0'; + if Self::scan(i, j - 1, board, &word[1..]) { + return true; + } + board[i][j - 1] = x; + } + } + + if i < board.len() - 1 { + if board[i + 1][j] == word[0] { + let x = board[i + 1][j]; + board[i + 1][j] = '0'; + if Self::scan(i + 1, j, board, &word[1..]) { + return true; + } + board[i + 1][j] = x; + } + } + + if i <= board.len() - 1 && j < board[i].len() - 1 { + if board[i][j + 1] == word[0] { + let x = board[i][j + 1]; + board[i][j + 1] = '0'; + if Self::scan(i, j + 1, board, &word[1..]) { + return true; + } + board[i][j + 1] = x; + } + } + + false + } +} From 97a9d093b087c8df8e7601e291481728e53ce356 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 27 Jul 2022 18:10:21 +0800 Subject: [PATCH 0538/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 44d2111e..217e374b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 313 | 141 | 164 | 8 | +| 314 | 141 | 165 | 8 | ### 题目 @@ -304,6 +304,7 @@ |100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | |100277 | 青蛙跳台阶问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) | Easy | |100278 | 旋转数组的最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/) | Easy | +|100279 | 矩阵中的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ju-zhen-zhong-de-lu-jing-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ju-zhen-zhong-de-lu-jing-lcof/) | Medium | |100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | |100281 | 机器人的运动范围 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ji-qi-ren-de-yun-dong-fan-wei-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/) | Medium | |100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | From 3c4c9015e80eefbc29c3d18a28af46c849c6188d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 27 Jul 2022 18:14:46 +0800 Subject: [PATCH 0539/1556] src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs --- src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs diff --git a/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs b/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs new file mode 100644 index 00000000..c29205ad --- /dev/null +++ b/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!( + Solution::hammingWeight(0b11111111111111111111111111111101), + 31 + ); + assert_eq!( + Solution::hammingWeight(0b00000000000000000000000000001011), + 3 + ); +} + +struct Solution; + +impl Solution { + fn hammingWeight(mut num: u32) -> i32 { + let mut s = 0; + + while num > 0 { + if num & 1 == 1 { + s += 1; + } + + num >>= 1; + } + + s + } +} From e35883310ad1c716be152d00b2e715d046acda51 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 27 Jul 2022 18:14:47 +0800 Subject: [PATCH 0540/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 217e374b..efa4149a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 314 | 141 | 165 | 8 | +| 315 | 142 | 165 | 8 | ### 题目 @@ -311,6 +311,7 @@ |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100284 | 剪绳子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-lcof/) | Medium | |100285 | 剪绳子 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/) | Medium | +|100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From f90f344abc822f63696b360a0ddd7dbfa2894645 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 29 Jul 2022 23:24:55 +0800 Subject: [PATCH 0541/1556] src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs --- src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs diff --git a/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs b/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs new file mode 100644 index 00000000..0147ae9c --- /dev/null +++ b/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + println!("{}", Solution::my_pow(2.00000, 10)); + println!("{}", Solution::my_pow(2.10000, 3)); + println!("{}", Solution::my_pow(2.00000, -2)); +} + +struct Solution; + +impl Solution { + pub fn my_pow(x: f64, n: i32) -> f64 { + Self::pow(x, n as i64) + } + + fn pow(x: f64, n: i64) -> f64 { + if n == 0 { + return 1.0; + } + + let n = n as i64; + + let m = Self::pow(x, n.abs() / 2); + let mut r = if n.abs() % 2 == 1 { m * m * x } else { m * m }; + + if n < 0 { + r = 1f64 / r; + } + + r + } +} From de69239c1ae5b5bf3b7ce3debe19a16d50e231f9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 29 Jul 2022 23:24:56 +0800 Subject: [PATCH 0542/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index efa4149a..9ca53d7c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 315 | 142 | 165 | 8 | +| 316 | 142 | 166 | 8 | ### 题目 @@ -312,6 +312,7 @@ |100284 | 剪绳子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-lcof/) | Medium | |100285 | 剪绳子 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/) | Medium | |100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | +|100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From f2800f82f907deaf6da495991398921eea4447f6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 30 Jul 2022 08:21:20 +0800 Subject: [PATCH 0543/1556] src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs --- src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs b/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs index 0147ae9c..72e2f88b 100644 --- a/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs +++ b/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs @@ -18,8 +18,6 @@ impl Solution { return 1.0; } - let n = n as i64; - let m = Self::pow(x, n.abs() / 2); let mut r = if n.abs() % 2 == 1 { m * m * x } else { m * m }; From 94b4c3ed7e89f648a8ae9ce258d3e71866101d63 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 30 Jul 2022 08:21:21 +0800 Subject: [PATCH 0544/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ca53d7c..ca315eb8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 316 | 142 | 166 | 8 | +| 317 | 142 | 167 | 8 | ### 题目 @@ -313,6 +313,7 @@ |100285 | 剪绳子 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/) | Medium | |100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | |100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | +|100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From c3d213f6881d8feb00f470d6f9ecf7f6a24f6427 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 30 Jul 2022 08:27:41 +0800 Subject: [PATCH 0545/1556] src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs --- src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs diff --git a/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs b/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs new file mode 100644 index 00000000..316d300b --- /dev/null +++ b/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs @@ -0,0 +1,13 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + println!("{:?}", Solution::print_numbers(3)); +} + +struct Solution; + +impl Solution { + pub fn print_numbers(n: i32) -> Vec { + (1..=10i32.pow(n as u32) - 1).collect() + } +} From 0fda14a5f3953495b863588000a4e2a550f0747e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 30 Jul 2022 08:27:41 +0800 Subject: [PATCH 0546/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ca315eb8..514a2603 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 317 | 142 | 167 | 8 | +| 318 | 143 | 167 | 8 | ### 题目 @@ -314,6 +314,7 @@ |100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | |100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | |100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | +|100296 | 打印从1到最大的n位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From c529edddab1df6b3fd64c8cf053c79d2f7cf1697 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 30 Jul 2022 08:28:52 +0800 Subject: [PATCH 0547/1556] src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs --- src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs b/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs index 316d300b..86715bf8 100644 --- a/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs +++ b/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs @@ -8,6 +8,6 @@ struct Solution; impl Solution { pub fn print_numbers(n: i32) -> Vec { - (1..=10i32.pow(n as u32) - 1).collect() + (1..10i32.pow(n as u32)).collect() } } From 248949d2f80dc7591b84a32762be3b1d627cf3b0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 30 Jul 2022 08:28:52 +0800 Subject: [PATCH 0548/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 514a2603..6bd5ba79 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 318 | 143 | 167 | 8 | +| 319 | 144 | 167 | 8 | ### 题目 @@ -315,6 +315,7 @@ |100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | |100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | |100296 | 打印从1到最大的n位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) | Easy | +|100296 | 打印从1到最大的n位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From 40800cb0431f8b22a1ff4bc79d8a8c9d8d3e6dea Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 1 Aug 2022 22:36:03 +0800 Subject: [PATCH 0549/1556] src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs --- ...shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs diff --git a/src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs b/src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs new file mode 100644 index 00000000..71757f72 --- /dev/null +++ b/src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn exchange(nums: Vec) -> Vec { + if nums.is_empty() { + return vec![]; + } + + let mut nums = nums; + let (mut start, mut end) = (0, nums.len() - 1); + + while start < end { + while start < end && nums[start] % 2 == 1 { + start += 1; + } + while start < end && nums[end] % 2 == 0 { + end -= 1; + } + + nums.swap(start, end); + } + + nums + } +} From b6f5f636ffc4a0838c9e02234914da347046b371 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 1 Aug 2022 22:36:03 +0800 Subject: [PATCH 0550/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6bd5ba79..b1f26f3c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 319 | 144 | 167 | 8 | +| 320 | 145 | 167 | 8 | ### 题目 @@ -311,6 +311,7 @@ |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100284 | 剪绳子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-lcof/) | Medium | |100285 | 剪绳子 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/) | Medium | +|100291 | 调整数组顺序使奇数位于偶数前面 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/) | Easy | |100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | |100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | |100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | From 952d023643617c462fef1edfba915e2043118819 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 2 Aug 2022 18:20:46 +0800 Subject: [PATCH 0551/1556] src/bin/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs --- ...biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bin/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs diff --git a/src/bin/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs b/src/bin/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs new file mode 100644 index 00000000..536a9fbe --- /dev/null +++ b/src/bin/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs @@ -0,0 +1,37 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} +impl Solution { + pub fn get_kth_from_end(mut head: Option>, k: i32) -> Option> { + let mut h = head.as_ref(); + let mut len = 0; + + while h.is_some() { + len += 1; + h = h.unwrap().next.as_ref(); + } + + while len > k { + head = head.unwrap().next.take(); + len -= 1; + } + + head + } +} From fb0815b342232c87458631d06f7581573e52aac3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 2 Aug 2022 18:20:47 +0800 Subject: [PATCH 0552/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b1f26f3c..35a4c11e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 320 | 145 | 167 | 8 | +| 321 | 146 | 167 | 8 | ### 题目 @@ -313,6 +313,7 @@ |100285 | 剪绳子 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/) | Medium | |100291 | 调整数组顺序使奇数位于偶数前面 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/) | Easy | |100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | +|100294 | 链表中倒数第k个节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/) | Easy | |100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | |100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | |100296 | 打印从1到最大的n位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) | Easy | From c4c6e888d18245bb5099efd64d92ea3cf2ac7160 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Aug 2022 10:24:21 +0800 Subject: [PATCH 0553/1556] src/bin/fan-zhuan-lian-biao-lcof.rs --- src/bin/fan-zhuan-lian-biao-lcof.rs | 58 +++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/bin/fan-zhuan-lian-biao-lcof.rs diff --git a/src/bin/fan-zhuan-lian-biao-lcof.rs b/src/bin/fan-zhuan-lian-biao-lcof.rs new file mode 100644 index 00000000..fec3eda8 --- /dev/null +++ b/src/bin/fan-zhuan-lian-biao-lcof.rs @@ -0,0 +1,58 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} +impl Solution { + pub fn reverse_list1(head: Option>) -> Option> { + let mut vals = vec![]; + let mut head = head; + + while head.is_some() { + let mut h = head.unwrap(); + vals.push(h.val); + head = h.next.take(); + } + + let mut r = None; + let mut current = &mut r; + + while let Some(val) = vals.pop() { + current.replace(Box::new(ListNode::new(val))); + current = &mut current.as_mut().unwrap().next; + } + + r + } + + pub fn reverse_list(mut head: Option>) -> Option> { + if head.is_none() { + return head; + } + + let mut next = head.as_mut().unwrap().next.take(); + + while let Some(n) = next.as_mut() { + let new_head = n.next.take(); + n.next = head; + head = next; + next = new_head; + } + + head + } +} From 3c2e6f3db3c0d26487e37184820df1f7961247e6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Aug 2022 10:24:22 +0800 Subject: [PATCH 0554/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 35a4c11e..8ac75869 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 321 | 146 | 167 | 8 | +| 322 | 147 | 167 | 8 | ### 题目 @@ -318,6 +318,7 @@ |100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | |100296 | 打印从1到最大的n位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) | Easy | |100296 | 打印从1到最大的n位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) | Easy | +|100298 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fan-zhuan-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From 221643a2610f93e7c4c8f74d8ac8b18d3ffc46d1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Aug 2022 15:29:10 +0800 Subject: [PATCH 0555/1556] src/bin/he-bing-liang-ge-pai-xu-de-lian-biao-lcof.rs --- ...-bing-liang-ge-pai-xu-de-lian-biao-lcof.rs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/bin/he-bing-liang-ge-pai-xu-de-lian-biao-lcof.rs diff --git a/src/bin/he-bing-liang-ge-pai-xu-de-lian-biao-lcof.rs b/src/bin/he-bing-liang-ge-pai-xu-de-lian-biao-lcof.rs new file mode 100644 index 00000000..cfaf6da9 --- /dev/null +++ b/src/bin/he-bing-liang-ge-pai-xu-de-lian-biao-lcof.rs @@ -0,0 +1,54 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} +impl Solution { + pub fn merge_two_lists( + l1: Option>, + l2: Option>, + ) -> Option> { + let mut r = None; + let mut current = &mut r; + let (mut l1, mut l2) = (l1, l2); + + while l1.is_some() && l2.is_some() { + let v1 = l1.as_ref().unwrap().val; + let v2 = l2.as_ref().unwrap().val; + + if v1 <= v2 { + current.replace(Box::new(ListNode::new(v1))); + l1 = l1.unwrap().next.take(); + } else { + current.replace(Box::new(ListNode::new(v2))); + l2 = l2.unwrap().next.take(); + } + + current = &mut current.as_mut().unwrap().next; + } + + if l1.is_some() { + current.replace(l1.unwrap()); + } + + if l2.is_some() { + current.replace(l2.unwrap()); + } + + r + } +} From 392929ae21a9ecc21fe55b57da22bd3edb364be1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Aug 2022 15:29:10 +0800 Subject: [PATCH 0556/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8ac75869..46c16423 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 322 | 147 | 167 | 8 | +| 323 | 148 | 167 | 8 | ### 题目 @@ -311,6 +311,7 @@ |100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | |100284 | 剪绳子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-lcof/) | Medium | |100285 | 剪绳子 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/) | Medium | +|100286 | 合并两个排序的链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/he-bing-liang-ge-pai-xu-de-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/) | Easy | |100291 | 调整数组顺序使奇数位于偶数前面 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/) | Easy | |100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | |100294 | 链表中倒数第k个节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/) | Easy | From 7c3b1ddb400ab17f77456d8bf42ffce7ebcbb7a0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Aug 2022 16:51:52 +0800 Subject: [PATCH 0557/1556] src/bin/shu-de-zi-jie-gou-lcof.rs --- src/bin/shu-de-zi-jie-gou-lcof.rs | 67 +++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/bin/shu-de-zi-jie-gou-lcof.rs diff --git a/src/bin/shu-de-zi-jie-gou-lcof.rs b/src/bin/shu-de-zi-jie-gou-lcof.rs new file mode 100644 index 00000000..75441da5 --- /dev/null +++ b/src/bin/shu-de-zi-jie-gou-lcof.rs @@ -0,0 +1,67 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; + +impl Solution { + pub fn is_sub_structure( + a: Option>>, + b: Option>>, + ) -> bool { + if !(b.is_some() && a.is_some()) { + return false; + } + + if Self::recurse(a.clone(), b.clone()) { + return true; + } + + Self::is_sub_structure(a.as_ref().unwrap().borrow().left.clone(), b.clone()) + || Self::is_sub_structure(a.as_ref().unwrap().borrow().right.clone(), b.clone()) + } + + fn recurse(a: Option>>, b: Option>>) -> bool { + if b.is_none() { + return true; + } + + if a.is_none() { + return false; + } + + let a_value = a.as_ref().unwrap().borrow().val; + let b_value = b.as_ref().unwrap().borrow().val; + + if a_value != b_value { + return false; + } + + let mut b_left = b.as_ref().unwrap().borrow().left.clone(); + let mut b_right = b.as_ref().unwrap().borrow().right.clone(); + + Self::recurse(a.as_ref().unwrap().borrow().left.clone(), b_left) + && Self::recurse(a.as_ref().unwrap().borrow().right.clone(), b_right) + } +} From 01586fd8428c8d4a5a9db272758fabc183200129 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Aug 2022 16:51:53 +0800 Subject: [PATCH 0558/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 46c16423..b68315de 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 323 | 148 | 167 | 8 | +| 324 | 148 | 168 | 8 | ### 题目 @@ -312,6 +312,7 @@ |100284 | 剪绳子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-lcof/) | Medium | |100285 | 剪绳子 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/) | Medium | |100286 | 合并两个排序的链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/he-bing-liang-ge-pai-xu-de-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/) | Easy | +|100287 | 树的子结构 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-de-zi-jie-gou-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof/) | Medium | |100291 | 调整数组顺序使奇数位于偶数前面 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/) | Easy | |100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | |100294 | 链表中倒数第k个节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/) | Easy | From 911223affcabf1049afd15868410f75f3c9eb1e9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Aug 2022 16:59:28 +0800 Subject: [PATCH 0559/1556] src/bin/er-cha-shu-de-jing-xiang-lcof.rs --- src/bin/er-cha-shu-de-jing-xiang-lcof.rs | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/bin/er-cha-shu-de-jing-xiang-lcof.rs diff --git a/src/bin/er-cha-shu-de-jing-xiang-lcof.rs b/src/bin/er-cha-shu-de-jing-xiang-lcof.rs new file mode 100644 index 00000000..ce281a01 --- /dev/null +++ b/src/bin/er-cha-shu-de-jing-xiang-lcof.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn mirror_tree(root: Option>>) -> Option>> { + if root.is_none() { + return None; + } + + let left = Self::mirror_tree(root.as_ref().unwrap().borrow_mut().right.take()); + let right = Self::mirror_tree(root.as_ref().unwrap().borrow_mut().left.take()); + + root.as_ref().unwrap().borrow_mut().left = left; + root.as_ref().unwrap().borrow_mut().right = right; + + root + } +} From 6d101413bf270ece618e2bc950f3842dfc55f14d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Aug 2022 16:59:28 +0800 Subject: [PATCH 0560/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b68315de..d10a7f32 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 324 | 148 | 168 | 8 | +| 325 | 149 | 168 | 8 | ### 题目 @@ -313,6 +313,7 @@ |100285 | 剪绳子 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/) | Medium | |100286 | 合并两个排序的链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/he-bing-liang-ge-pai-xu-de-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/) | Easy | |100287 | 树的子结构 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-de-zi-jie-gou-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof/) | Medium | +|100288 | 二叉树的镜像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-jing-xiang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof/) | Easy | |100291 | 调整数组顺序使奇数位于偶数前面 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/) | Easy | |100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | |100294 | 链表中倒数第k个节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/) | Easy | From 1dedc1b46110ab0c76d343a2ef5746233dacd9ec Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 4 Aug 2022 19:57:51 +0800 Subject: [PATCH 0561/1556] src/bin/dui-cheng-de-er-cha-shu-lcof.rs --- src/bin/dui-cheng-de-er-cha-shu-lcof.rs | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/bin/dui-cheng-de-er-cha-shu-lcof.rs diff --git a/src/bin/dui-cheng-de-er-cha-shu-lcof.rs b/src/bin/dui-cheng-de-er-cha-shu-lcof.rs new file mode 100644 index 00000000..62939b36 --- /dev/null +++ b/src/bin/dui-cheng-de-er-cha-shu-lcof.rs @@ -0,0 +1,59 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::ops::Index; +use std::rc::Rc; +impl Solution { + pub fn is_symmetric(root: Option>>) -> bool { + if root.is_none() { + return true; + } + + let left = root.as_ref().unwrap().borrow_mut().left.take(); + let right = root.as_ref().unwrap().borrow_mut().right.take(); + + let mut v = vec![left, right]; + let (mut i, mut j) = (0, 1); + + while !v.is_empty() { + match (v.pop(), v.pop()) { + (Some(Some(x)), Some(Some(y))) => { + if x.borrow().val != y.borrow().val { + return false; + } + + v.push(x.borrow_mut().left.take()); + v.push(y.borrow_mut().right.take()); + v.push(x.borrow_mut().right.take()); + v.push(y.borrow_mut().left.take()); + } + (Some(None), Some(None)) => {} + _ => return false, + } + } + + true + } +} From 9383c8427873786676591426ad5667566449e4c6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 4 Aug 2022 19:57:52 +0800 Subject: [PATCH 0562/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d10a7f32..9346d8bc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 325 | 149 | 168 | 8 | +| 326 | 150 | 168 | 8 | ### 题目 @@ -314,6 +314,7 @@ |100286 | 合并两个排序的链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/he-bing-liang-ge-pai-xu-de-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/) | Easy | |100287 | 树的子结构 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-de-zi-jie-gou-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof/) | Medium | |100288 | 二叉树的镜像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-jing-xiang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof/) | Easy | +|100289 | 对称的二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dui-cheng-de-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof/) | Easy | |100291 | 调整数组顺序使奇数位于偶数前面 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/) | Easy | |100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | |100294 | 链表中倒数第k个节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/) | Easy | From e164cf2f28480ad2f19d54761d85fb1a72a4b726 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 10:14:55 +0800 Subject: [PATCH 0563/1556] src/bin/shun-shi-zhen-da-yin-ju-zhen-lcof.rs --- src/bin/shun-shi-zhen-da-yin-ju-zhen-lcof.rs | 73 ++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/bin/shun-shi-zhen-da-yin-ju-zhen-lcof.rs diff --git a/src/bin/shun-shi-zhen-da-yin-ju-zhen-lcof.rs b/src/bin/shun-shi-zhen-da-yin-ju-zhen-lcof.rs new file mode 100644 index 00000000..1aa958e2 --- /dev/null +++ b/src/bin/shun-shi-zhen-da-yin-ju-zhen-lcof.rs @@ -0,0 +1,73 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use serde::__private::de; + +fn main() {} + +struct Solution; + +enum Direction { + Right, + Down, + Left, + Up, +} + +impl Solution { + pub fn spiral_order(matrix: Vec>) -> Vec { + if matrix.is_empty() { + return vec![]; + } + + let (mut left, mut right, mut up, mut down) = (0, matrix[0].len(), 0, matrix.len()); + let mut data = Vec::with_capacity(right * down); + let (mut index1, mut index2) = (0, 0); + + let mut direction = Direction::Right; + + while left < right && up < down { + data.push(matrix[index1][index2]); + match direction { + Direction::Right => { + if index2 < right - 1 { + index2 += 1; + } else { + direction = Direction::Down; + index1 += 1; + up += 1; + } + } + + Direction::Down => { + if index1 < down - 1 { + index1 += 1; + } else { + direction = Direction::Left; + index2 -= 1; + right -= 1; + } + } + Direction::Left => { + if index2 > left + 1 { + index2 -= 1; + } else { + direction = Direction::Up; + index1 -= 1; + down -= 1; + } + } + Direction::Up => { + if index1 > up + 1 { + index1 -= 1; + } else { + direction = Direction::Right; + index2 += 1; + left += 1; + } + } + } + } + + data + } +} From d1bdb3cabcbe4b2d6a6b1c01d63791849ab58641 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 10:14:56 +0800 Subject: [PATCH 0564/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9346d8bc..14a9d914 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 326 | 150 | 168 | 8 | +| 327 | 151 | 168 | 8 | ### 题目 @@ -317,6 +317,7 @@ |100289 | 对称的二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dui-cheng-de-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof/) | Easy | |100291 | 调整数组顺序使奇数位于偶数前面 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/) | Easy | |100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | +|100293 | 顺时针打印矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shun-shi-zhen-da-yin-ju-zhen-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shun-shi-zhen-da-yin-ju-zhen-lcof/) | Easy | |100294 | 链表中倒数第k个节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/) | Easy | |100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | |100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | From fc5054869ae3d85541b52db05686624b1a8874e0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 10:15:28 +0800 Subject: [PATCH 0565/1556] src/bin/spiral-matrix.rs --- src/bin/spiral-matrix.rs | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/bin/spiral-matrix.rs diff --git a/src/bin/spiral-matrix.rs b/src/bin/spiral-matrix.rs new file mode 100644 index 00000000..48aa0643 --- /dev/null +++ b/src/bin/spiral-matrix.rs @@ -0,0 +1,71 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +enum Direction { + Right, + Down, + Left, + Up, +} + +impl Solution { + pub fn spiral_order(matrix: Vec>) -> Vec { + if matrix.is_empty() { + return vec![]; + } + + let (mut left, mut right, mut up, mut down) = (0, matrix[0].len(), 0, matrix.len()); + let mut data = Vec::with_capacity(right * down); + let (mut index1, mut index2) = (0, 0); + + let mut direction = Direction::Right; + + while left < right && up < down { + data.push(matrix[index1][index2]); + match direction { + Direction::Right => { + if index2 < right - 1 { + index2 += 1; + } else { + direction = Direction::Down; + index1 += 1; + up += 1; + } + } + + Direction::Down => { + if index1 < down - 1 { + index1 += 1; + } else { + direction = Direction::Left; + index2 -= 1; + right -= 1; + } + } + Direction::Left => { + if index2 > left { + index2 -= 1; + } else { + direction = Direction::Up; + index1 -= 1; + down -= 1; + } + } + Direction::Up => { + if index1 > up { + index1 -= 1; + } else { + direction = Direction::Right; + index2 += 1; + left += 1; + } + } + } + } + + data + } +} From 21e15e5023a7e1006b6c1de5b4994462b2bd3db4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 10:15:29 +0800 Subject: [PATCH 0566/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 14a9d914..4d3a8217 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 327 | 151 | 168 | 8 | +| 328 | 151 | 169 | 8 | ### 题目 @@ -50,6 +50,7 @@ |51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Hard | |52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Hard | |53 | 最大子数组和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) | Easy | +|54 | 螺旋矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix/) | Medium | |55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | Medium | |56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | Medium | |57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | Medium | From 04487871f415d6bba619664a1422432efdbeed1f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 10:41:10 +0800 Subject: [PATCH 0567/1556] src/bin/bao-han-minhan-shu-de-zhan-lcof.rs --- src/bin/bao-han-minhan-shu-de-zhan-lcof.rs | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/bin/bao-han-minhan-shu-de-zhan-lcof.rs diff --git a/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs b/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs new file mode 100644 index 00000000..6e8d7d33 --- /dev/null +++ b/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs @@ -0,0 +1,61 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +struct MinStack { + stack: Vec, + min_stack: Vec, // 辅助栈存放当前栈中的最小值 +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl MinStack { + /** initialize your data structure here. */ + fn new() -> Self { + Self { + stack: vec![], + min_stack: vec![], + } + } + + fn push(&mut self, x: i32) { + if self.min_stack.is_empty() { + self.min_stack.push(x); + } else { + if self.min_stack[self.min_stack.len() - 1] >= x { + self.min_stack.push(x); + } + } + + self.stack.push(x); + } + + fn pop(&mut self) { + if let Some(x) = self.stack.pop() { + if x == *self.min_stack.last().unwrap() { + self.min_stack.pop(); + } + } + } + + fn top(&self) -> i32 { + *self.stack.last().unwrap() + } + + fn min(&self) -> i32 { + *self.min_stack.last().unwrap() + } +} + +// Your MinStack object will be instantiated and called as such: +// let obj = MinStack::new(); +// obj.push(x); +// obj.pop(); +// let ret_3: i32 = obj.top(); +// let ret_4: i32 = obj.min(); From eff9b90aab1aa4fcb7274801da4c1d6218d9c9bf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 10:41:10 +0800 Subject: [PATCH 0568/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d3a8217..6d8a44fc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 328 | 151 | 169 | 8 | +| 329 | 152 | 169 | 8 | ### 题目 @@ -326,6 +326,7 @@ |100296 | 打印从1到最大的n位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) | Easy | |100298 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fan-zhuan-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | +|100302 | 包含min函数的栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | From f803241609602ea15f06934cc4392538a82f1a1e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 15:41:23 +0800 Subject: [PATCH 0569/1556] src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs --- src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs | 60 ++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs diff --git a/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs b/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs new file mode 100644 index 00000000..8fac2730 --- /dev/null +++ b/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs @@ -0,0 +1,60 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + println!( + "{}", + Solution::validate_stack_sequences(vec![1, 2, 3, 4, 5], vec![4, 5, 3, 2, 1]) + ); + + println!( + "{}", + Solution::validate_stack_sequences(vec![1, 2, 3, 4, 5], vec![4, 3, 5, 1, 2]) + ); +} + +struct Solution; + +impl Solution { + pub fn validate_stack_sequences1(pushed: Vec, popped: Vec) -> bool { + let (mut index1, mut index2) = (0, 0); + let mut stack = vec![]; + + while index1 < pushed.len() || index2 < pushed.len() { + if index1 < pushed.len() + && (stack.is_empty() || *stack.last().unwrap() != popped[index2]) + { + stack.push(pushed[index1]); + index1 += 1; + } else { + match stack.pop() { + Some(x) if x == popped[index2] => { + index2 += 1; + } + _ => return false, + } + } + } + + stack.is_empty() + } + + pub fn validate_stack_sequences(pushed: Vec, popped: Vec) -> bool { + let mut index = 0; + let mut stack = vec![]; + + for i in pushed { + stack.push(i); + + while let Some(&x) = stack.last() { + if x == popped[index] { + stack.pop(); + index += 1; + } else { + break; + } + } + } + + stack.is_empty() + } +} From 9363497b4565e93ea579f24c9063e469578a20dc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 15:41:24 +0800 Subject: [PATCH 0570/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d8a44fc..32417052 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 329 | 152 | 169 | 8 | +| 330 | 152 | 170 | 8 | ### 题目 @@ -327,6 +327,7 @@ |100298 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fan-zhuan-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100302 | 包含min函数的栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/) | Easy | +|100306 | 栈的压入、弹出序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) | Medium | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | From 256c041e840e24ad05cf458d4fe4f018c0acf0cb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 15:43:35 +0800 Subject: [PATCH 0571/1556] src/bin/validate-stack-sequences.rs --- src/bin/validate-stack-sequences.rs | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/bin/validate-stack-sequences.rs diff --git a/src/bin/validate-stack-sequences.rs b/src/bin/validate-stack-sequences.rs new file mode 100644 index 00000000..fcea6b5b --- /dev/null +++ b/src/bin/validate-stack-sequences.rs @@ -0,0 +1,50 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn validate_stack_sequences1(pushed: Vec, popped: Vec) -> bool { + let (mut index1, mut index2) = (0, 0); + let mut stack = vec![]; + + while index1 < pushed.len() || index2 < pushed.len() { + if index1 < pushed.len() + && (stack.is_empty() || *stack.last().unwrap() != popped[index2]) + { + stack.push(pushed[index1]); + index1 += 1; + } else { + match stack.pop() { + Some(x) if x == popped[index2] => { + index2 += 1; + } + _ => return false, + } + } + } + + stack.is_empty() + } + + pub fn validate_stack_sequences(pushed: Vec, popped: Vec) -> bool { + let mut index = 0; + let mut stack = vec![]; + + for i in pushed { + stack.push(i); + + while let Some(&x) = stack.last() { + if x == popped[index] { + stack.pop(); + index += 1; + } else { + break; + } + } + } + + stack.is_empty() + } +} From eb0806f9cf9ec5cb1de42f81a388e25ae9fcf704 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 15:43:35 +0800 Subject: [PATCH 0572/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 32417052..56ec2a59 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 330 | 152 | 170 | 8 | +| 331 | 152 | 171 | 8 | ### 题目 @@ -251,6 +251,7 @@ |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | |981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | |982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Medium | +|983 | 验证栈序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-stack-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/validate-stack-sequences/) | Medium | |1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | Medium | |1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | Easy | |1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | From e7c9b6e099477eba1ebafcee153101d41d5092a5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 15:52:44 +0800 Subject: [PATCH 0573/1556] src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs --- ...ng-shang-dao-xia-da-yin-er-cha-shu-lcof.rs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs diff --git a/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs b/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs new file mode 100644 index 00000000..28268fd6 --- /dev/null +++ b/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs @@ -0,0 +1,47 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn level_order(root: Option>>) -> Vec { + let mut v = vec![]; + let mut stack = vec![root]; + let mut index = 0; + + while index < stack.len() { + if let Some(ref x) = stack[index].clone() { + v.push(x.borrow().val); + + stack.push(x.borrow_mut().left.take()); + + stack.push(x.borrow_mut().right.take()); + } + + index += 1; + } + + v + } +} From c3dbe5a69ecbc68954cb385ec5533f321e151ae4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 15:52:45 +0800 Subject: [PATCH 0574/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 56ec2a59..4b7f0354 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 331 | 152 | 171 | 8 | +| 332 | 152 | 172 | 8 | ### 题目 @@ -329,6 +329,7 @@ |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100302 | 包含min函数的栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/) | Easy | |100306 | 栈的压入、弹出序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) | Medium | +|100311 | 从上到下打印二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) | Medium | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | From 17c9ab8e478867cccb3b7d61bdcf7359d01025ca Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 16:17:15 +0800 Subject: [PATCH 0575/1556] src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs --- ...shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs diff --git a/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs b/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs new file mode 100644 index 00000000..5d9d5824 --- /dev/null +++ b/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs @@ -0,0 +1,64 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn level_order(root: Option>>) -> Vec> { + if root.is_none() { + return vec![]; + } + + let mut data = vec![]; + let mut stack = vec![root]; + + while !stack.is_empty() { + let mut r = vec![]; + let mut new_stack = vec![]; + let mut index = 0; + + while index < stack.len() { + if let Some(x) = stack[index].clone() { + r.push(x.borrow().val); + + let left = x.borrow_mut().left.take(); + if left.is_some() { + new_stack.push(left); + } + + let right = x.borrow_mut().right.take(); + if right.is_some() { + new_stack.push(right); + } + } + index += 1; + } + + stack = new_stack; + data.push(r); + } + + data + } +} From 469bf4bbc5a5630d7664b4b86e78d752371d0ec9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 16:17:15 +0800 Subject: [PATCH 0576/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b7f0354..c48a090e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 332 | 152 | 172 | 8 | +| 333 | 153 | 172 | 8 | ### 题目 @@ -330,6 +330,7 @@ |100302 | 包含min函数的栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/) | Easy | |100306 | 栈的压入、弹出序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) | Medium | |100311 | 从上到下打印二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) | Medium | +|100312 | 从上到下打印二叉树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/) | Easy | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | From 3a192b599e7fa3d52d98fb18f9c032200cc0e50c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 16:47:46 +0800 Subject: [PATCH 0577/1556] src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs --- ...hang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs diff --git a/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs b/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs new file mode 100644 index 00000000..44a52bb8 --- /dev/null +++ b/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs @@ -0,0 +1,60 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn level_order(root: Option>>) -> Vec> { + if root.is_none() { + return vec![]; + } + + let mut stack = vec![root.unwrap()]; + let mut data = vec![]; + let mut level = 1; + + while !stack.is_empty() { + let mut new_stack = vec![]; + let mut d = vec![]; + + while let Some(x) = stack.pop() { + d.push(x.borrow().val); + if level % 2 == 1 { + x.borrow_mut().left.take().map(|x| new_stack.push(x)); + x.borrow_mut().right.take().map(|x| new_stack.push(x)); + } else { + x.borrow_mut().right.take().map(|x| new_stack.push(x)); + x.borrow_mut().left.take().map(|x| new_stack.push(x)); + } + } + + level += 1; + + data.push(d); + stack = new_stack; + } + + data + } +} From 06b98e0f48ab72dab32f6b35ec9da698c8f44450 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Aug 2022 16:47:47 +0800 Subject: [PATCH 0578/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c48a090e..6210ac3d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 333 | 153 | 172 | 8 | +| 334 | 153 | 173 | 8 | ### 题目 @@ -331,6 +331,7 @@ |100306 | 栈的压入、弹出序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) | Medium | |100311 | 从上到下打印二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) | Medium | |100312 | 从上到下打印二叉树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/) | Easy | +|100314 | 从上到下打印二叉树 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof/) | Medium | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | From c4c4c64ae96d6607358b0f5ba298e98b911ae78a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 6 Aug 2022 12:40:28 +0800 Subject: [PATCH 0579/1556] src/bin/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof.rs --- ...u-suo-shu-de-hou-xu-bian-li-xu-lie-lcof.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof.rs diff --git a/src/bin/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof.rs b/src/bin/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof.rs new file mode 100644 index 00000000..98a1a5fd --- /dev/null +++ b/src/bin/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert!(!Solution::verify_postorder(vec![1, 6, 3, 2, 5])); + assert!(Solution::verify_postorder(vec![1, 3, 2, 6, 5])); + assert!(Solution::verify_postorder(vec![4, 8, 6, 12, 16, 14, 10])); + assert!(Solution::verify_postorder(vec![5, 4, 3, 2, 1])); +} + +struct Solution; + +impl Solution { + pub fn verify_postorder(postorder: Vec) -> bool { + Self::recurse(&postorder[..]) + } + + pub fn recurse(postorder: &[i32]) -> bool { + if postorder.is_empty() { + return true; + } + + let mut p = 0; + while p < postorder.len() && postorder[p] < postorder[postorder.len() - 1] { + p += 1; + } + + let mut q = p; + while q < postorder.len() && postorder[q] > postorder[postorder.len() - 1] { + q += 1; + } + + postorder[0..p].len() + postorder[p..q].len() + 1 == postorder.len() + && Self::recurse(&postorder[0..p]) + && Self::recurse(&postorder[p..q]) + } +} From 472349fdb57732f94dd56ce14f4af7a02dc4701b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 6 Aug 2022 12:40:28 +0800 Subject: [PATCH 0580/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6210ac3d..63d36ba0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 334 | 153 | 173 | 8 | +| 335 | 153 | 174 | 8 | ### 题目 @@ -332,6 +332,7 @@ |100311 | 从上到下打印二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) | Medium | |100312 | 从上到下打印二叉树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/) | Easy | |100314 | 从上到下打印二叉树 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof/) | Medium | +|100315 | 二叉搜索树的后序遍历序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof/) | Medium | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | From d9bfdcf3a405184c161938929b33339c299cc76e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 6 Aug 2022 13:05:54 +0800 Subject: [PATCH 0581/1556] src/bin/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs --- ...zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/bin/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs diff --git a/src/bin/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs b/src/bin/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs new file mode 100644 index 00000000..c261e872 --- /dev/null +++ b/src/bin/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs @@ -0,0 +1,62 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +use std::vec; +impl Solution { + pub fn path_sum(root: Option>>, target: i32) -> Vec> { + if root.is_none() { + return vec![]; + } + + let root = root.unwrap(); + let val = root.borrow().val; + let left = root.borrow_mut().left.take(); + let right = root.borrow_mut().right.take(); + + if val == target && left.is_none() && right.is_none() { + return vec![vec![val]]; + } + + let v1 = Self::path_sum(left, target - val); + let v2 = Self::path_sum(right, target - val); + + let mut data = vec![]; + + for i in v1 { + let mut v = vec![val]; + v.extend(i); + data.push(v); + } + + for i in v2 { + let mut v = vec![val]; + v.extend(i); + data.push(v); + } + + data + } +} From 713da7cc57586d585a13bae6d5bfe2a97acbafcd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 6 Aug 2022 13:05:55 +0800 Subject: [PATCH 0582/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 63d36ba0..09eb0e05 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 335 | 153 | 174 | 8 | +| 336 | 153 | 175 | 8 | ### 题目 @@ -334,6 +334,7 @@ |100314 | 从上到下打印二叉树 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof/) | Medium | |100315 | 二叉搜索树的后序遍历序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof/) | Medium | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | +|100317 | 二叉树中和为某一值的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | From 2d07d939dfd9f167fa04774ae6eb4da69c006d85 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 7 Aug 2022 19:17:13 +0800 Subject: [PATCH 0583/1556] src/bin/zi-fu-chuan-de-pai-lie-lcof.rs --- src/bin/zi-fu-chuan-de-pai-lie-lcof.rs | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/bin/zi-fu-chuan-de-pai-lie-lcof.rs diff --git a/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs b/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs new file mode 100644 index 00000000..b3c75e54 --- /dev/null +++ b/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs @@ -0,0 +1,43 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() { + println!("{:?}", Solution::permutation("abc".to_string())); +} + +struct Solution; + +impl Solution { + pub fn permutation(s: String) -> Vec { + Self::f(s.as_bytes()) + .into_iter() + .map(|x| String::from_utf8(x).unwrap()) + .collect::>() + .into_iter() + .collect() + } + + fn f(x: &[u8]) -> Vec> { + if x.len() == 1 { + return vec![vec![x[0]]]; + } + let mut data = vec![]; + for i in 0..x.len() { + let n = x[i]; + let mut v = Vec::with_capacity(x.len()); + v.extend(&x[0..i]); + v.extend(&x[i + 1..]); + + let x1 = Self::f(&v[..]); + for j in x1.iter() { + let mut m = Vec::with_capacity(x.len()); + m.push(n); + m.extend(j.into_iter()); + data.push(m); + } + } + + data + } +} From 6d0d0bfca495d483d32ba3171be8f55be7e4b9bb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 7 Aug 2022 19:17:13 +0800 Subject: [PATCH 0584/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 09eb0e05..6c161417 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 336 | 153 | 175 | 8 | +| 337 | 153 | 176 | 8 | ### 题目 @@ -329,6 +329,7 @@ |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100302 | 包含min函数的栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/) | Easy | |100306 | 栈的压入、弹出序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) | Medium | +|100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | |100311 | 从上到下打印二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) | Medium | |100312 | 从上到下打印二叉树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/) | Easy | |100314 | 从上到下打印二叉树 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof/) | Medium | From f9a3d74a0385f142cfb2fb9b0d82ddd646222c8d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 9 Aug 2022 09:27:11 +0800 Subject: [PATCH 0585/1556] src/bin/zi-fu-chuan-de-pai-lie-lcof.rs --- src/bin/zi-fu-chuan-de-pai-lie-lcof.rs | 45 +++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs b/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs index b3c75e54..ed40f6df 100644 --- a/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs +++ b/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs @@ -9,7 +9,7 @@ fn main() { struct Solution; impl Solution { - pub fn permutation(s: String) -> Vec { + pub fn permutation1(s: String) -> Vec { Self::f(s.as_bytes()) .into_iter() .map(|x| String::from_utf8(x).unwrap()) @@ -40,4 +40,47 @@ impl Solution { data } + + pub fn permutation(s: String) -> Vec { + let mut s = s; + unsafe { + let bytes = s.as_bytes_mut(); + bytes.sort(); + } + + let mut data = vec![s]; + let mut index = 0; + + while index < data.len() { + match Self::next_permutation(data[index].clone()) { + Some(s) => data.push(s), + None => break, + } + index += 1; + } + + data + } + + pub fn next_permutation(mut string: String) -> Option { + unsafe { + let s = string.as_bytes_mut(); + for i in (0..s.len() - 1).rev() { + if s[i] < s[i + 1] { + let mut min = i + 1; + for j in (i + 1..s.len()).rev() { + if s[j] > s[i] && s[j] < s[min] { + min = j; + } + } + s.swap(i, min); + s[i + 1..].sort(); + + return Some(string); + } + } + + None + } + } } From c31a3b45313cad20c6328af83d61feafe32cb4be Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 9 Aug 2022 09:27:11 +0800 Subject: [PATCH 0586/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c161417..21c54c5b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 337 | 153 | 176 | 8 | +| 338 | 153 | 177 | 8 | ### 题目 @@ -330,6 +330,7 @@ |100302 | 包含min函数的栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/) | Easy | |100306 | 栈的压入、弹出序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) | Medium | |100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | +|100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | |100311 | 从上到下打印二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) | Medium | |100312 | 从上到下打印二叉树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/) | Easy | |100314 | 从上到下打印二叉树 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof/) | Medium | From 55cc6e385fcb00a2560fae671f5f9441bd33635d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 9 Aug 2022 13:18:48 +0800 Subject: [PATCH 0587/1556] src/bin/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof.rs --- ...n-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof.rs diff --git a/src/bin/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof.rs b/src/bin/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof.rs new file mode 100644 index 00000000..90daeddc --- /dev/null +++ b/src/bin/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn majority_element1(mut nums: Vec) -> i32 { + nums.sort(); + + nums[nums.len() / 2] + } + + /// https://leetcode.cn/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof/solution/mian-shi-ti-39-shu-zu-zhong-chu-xian-ci-shu-chao-3/ + pub fn majority_element(mut nums: Vec) -> i32 { + let mut x = None; + let mut score = 0; + + for i in nums { + if x.is_none() { + x = Some(i); + } + + match x { + Some(s) if s == i => score += 1, + _ => score -= 1, + } + + if score == 0 { + x = None; + } + } + + x.unwrap() + } +} From 813e3600106758487b99ee47933e252ce5dfc52d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 9 Aug 2022 13:18:49 +0800 Subject: [PATCH 0588/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 21c54c5b..e910b3e5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 338 | 153 | 177 | 8 | +| 339 | 154 | 177 | 8 | ### 题目 @@ -331,6 +331,7 @@ |100306 | 栈的压入、弹出序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) | Medium | |100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | |100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | +|100310 | 数组中出现次数超过一半的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof/) | Easy | |100311 | 从上到下打印二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) | Medium | |100312 | 从上到下打印二叉树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/) | Easy | |100314 | 从上到下打印二叉树 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof/) | Medium | From dcbf38e597934d3b2d0336292a253c3b16c8d6bb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 10 Aug 2022 11:16:23 +0800 Subject: [PATCH 0589/1556] src/bin/zui-xiao-de-kge-shu-lcof.rs --- src/bin/zui-xiao-de-kge-shu-lcof.rs | 67 +++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/bin/zui-xiao-de-kge-shu-lcof.rs diff --git a/src/bin/zui-xiao-de-kge-shu-lcof.rs b/src/bin/zui-xiao-de-kge-shu-lcof.rs new file mode 100644 index 00000000..e104455f --- /dev/null +++ b/src/bin/zui-xiao-de-kge-shu-lcof.rs @@ -0,0 +1,67 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::{iter::FromIterator, vec}; + +fn main() { + println!("{:?}", Solution::get_least_numbers(vec![3, 2, 1], 2)); + println!("{:?}", Solution::get_least_numbers(vec![0, 1, 2, 1], 1)); + println!("{:?}", Solution::get_least_numbers((0..100).collect(), 15)); + println!( + "{:?}", + Solution::get_least_numbers(vec![0, 0, 1, 2, 4, 2, 2, 3, 1, 4], 8) + ); +} + +/// 大顶堆 +struct Heap { + data: Vec, + len: usize, +} + +struct Solution; + +impl Solution { + pub fn get_least_numbers(mut arr: Vec, k: i32) -> Vec { + Self::quick_sort(&mut arr, k as usize); + (&arr[0..k as usize]).to_vec() + } + + pub fn quick_sort(arr: &mut [i32], k: usize) { + if arr.len() <= 1 || k == 0 { + return; + } + + let (mut base, mut begin, mut end) = (arr[0], 0, arr.len() - 1); + while begin < end { + while begin < end { + if arr[end] > base { + end -= 1; + } else { + arr.swap(begin, end); + begin += 1; + break; + } + } + + while begin < end { + if arr[begin] < base { + begin += 1; + } else { + arr.swap(begin, end); + end -= 1; + break; + } + } + } + + arr[begin] = base; + // [1,2,3,4,5] k=1 begin=2 + if begin == k || begin + 1 == k { + return; + } else if begin >= 1 + k { + Self::quick_sort(&mut arr[..begin], k); + } else { + Self::quick_sort(&mut arr[begin + 1..], k - begin - 1); + } + } +} From 6d5ff5686b654bf488fa6d61af556be7a5f21978 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 10 Aug 2022 11:16:24 +0800 Subject: [PATCH 0590/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e910b3e5..27ece271 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 339 | 154 | 177 | 8 | +| 340 | 155 | 177 | 8 | ### 题目 @@ -327,6 +327,7 @@ |100296 | 打印从1到最大的n位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) | Easy | |100298 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fan-zhuan-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/) | Easy | |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | +|100301 | 最小的k个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-xiao-de-kge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof/) | Easy | |100302 | 包含min函数的栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/) | Easy | |100306 | 栈的压入、弹出序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) | Medium | |100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | From 77097bb0fc795eafa09da0f772a03e95652c8c5e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 10 Aug 2022 18:42:06 +0800 Subject: [PATCH 0591/1556] src/bin/shu-ju-liu-zhong-de-zhong-wei-shu-lcof.rs --- .../shu-ju-liu-zhong-de-zhong-wei-shu-lcof.rs | 231 ++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 src/bin/shu-ju-liu-zhong-de-zhong-wei-shu-lcof.rs diff --git a/src/bin/shu-ju-liu-zhong-de-zhong-wei-shu-lcof.rs b/src/bin/shu-ju-liu-zhong-de-zhong-wei-shu-lcof.rs new file mode 100644 index 00000000..adc6d1f3 --- /dev/null +++ b/src/bin/shu-ju-liu-zhong-de-zhong-wei-shu-lcof.rs @@ -0,0 +1,231 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() { + let mut finder = MedianFinder::new(); + finder.add_num(1); + finder.add_num(2); + + println!("{}", finder.find_median()); + + finder.add_num(3); + + println!("{}", finder.find_median()); +} + +enum Type { + Big, + Small, +} + +struct Heap { + data: Vec, + r#type: Type, +} + +impl Heap { + fn get_top(&self) -> i32 { + self.data[0] + } + + fn insert(&mut self, value: i32) { + self.data.push(value); + self.heapify(); + } + + fn heapify(&mut self) { + let mut index = self.len() - 1; + while index != 0 { + match self.r#type { + Type::Big if self.data[index] > self.data[(index - 1) / 2] => { + self.data.swap(index, (index - 1) / 2); + } + Type::Small if self.data[index] < self.data[(index - 1) / 2] => { + self.data.swap(index, (index - 1) / 2); + } + _ => { + return; + } + } + + index = (index - 1) / 2; + } + } + + fn down_heap(&mut self) { + let mut index = 0; + while index < self.len() { + match self.r#type { + Type::Big => { + let son_index = if index * 2 + 2 < self.len() { + if self.data[index * 2 + 2] > self.data[index * 2 + 1] { + index * 2 + 2 + } else { + index * 2 + 1 + } + } else if index * 2 + 1 < self.len() { + index * 2 + 1 + } else { + return; + }; + + if self.data[son_index] > self.data[index] { + self.data.swap(son_index, index); + index = son_index; + } else { + return; + } + } + Type::Small => { + let son_index = if index * 2 + 2 < self.len() { + if self.data[index * 2 + 2] < self.data[index * 2 + 1] { + index * 2 + 2 + } else { + index * 2 + 1 + } + } else if index * 2 + 1 < self.len() { + index * 2 + 1 + } else { + return; + }; + + if self.data[son_index] < self.data[index] { + self.data.swap(son_index, index); + index = son_index; + } else { + return; + } + } + } + } + } + + fn pop(&mut self) -> i32 { + let last = self.len() - 1; + self.data.swap(0, last); + let pop = self.data.remove(last); + self.down_heap(); + pop + } + + fn len(&self) -> usize { + self.data.len() + } +} + +struct MedianFinder { + low: Heap, // 大顶推存值小的一半 + high: Heap, // 小顶堆村值大的一半 +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl MedianFinder { + /** initialize your data structure here. */ + fn new() -> Self { + Self { + low: Heap { + data: vec![], + r#type: Type::Big, + }, + high: Heap { + data: vec![], + r#type: Type::Small, + }, + } + } + + fn add_num(&mut self, num: i32) { + // 先把数据插入到 high,再从 high 中弹出一个元素插入到 low + if self.low.len() == self.high.len() { + self.low.insert(num); + let pop = self.low.pop(); + self.high.insert(pop); + } else { + self.high.insert(num); + let pop = self.high.pop(); + self.low.insert(pop); + } + } + + fn find_median(&self) -> f64 { + assert!(self.high.len() + self.low.len() > 0, "empty"); + + if self.high.len() != self.low.len() { + self.high.get_top() as f64 + } else { + (self.high.get_top() as f64 + self.low.get_top() as f64) / 2f64 + } + } +} + +// /** +// * Your MedianFinder object will be instantiated and called as such: +// * let obj = MedianFinder::new(); +// * obj.add_num(num); +// * let ret_2: f64 = obj.find_median(); +// */ +#[test] +fn test_min_heap() { + let mut min_heap = Heap { + data: vec![], + r#type: Type::Small, + }; + + min_heap.insert(10); + min_heap.insert(1); + min_heap.insert(3); + min_heap.insert(9); + min_heap.insert(8); + min_heap.insert(2); + min_heap.insert(7); + + assert_eq!(min_heap.pop(), 1); + assert_eq!(min_heap.pop(), 2); + assert_eq!(min_heap.pop(), 3); + assert_eq!(min_heap.pop(), 7); + assert_eq!(min_heap.pop(), 8); + assert_eq!(min_heap.pop(), 9); + assert_eq!(min_heap.pop(), 10); +} + +#[test] +fn test_max_heap() { + let mut max_heap = Heap { + data: vec![], + r#type: Type::Big, + }; + + max_heap.insert(10); + println!("{:?}", max_heap.data); + max_heap.insert(1); + println!("{:?}", max_heap.data); + max_heap.insert(3); + println!("{:?}", max_heap.data); + max_heap.insert(9); + println!("{:?}", max_heap.data); + max_heap.insert(8); + println!("{:?}", max_heap.data); + max_heap.insert(2); + println!("{:?}", max_heap.data); + max_heap.insert(7); + println!("{:?}", max_heap.data); + + assert_eq!(max_heap.pop(), 10); + println!("{:?}", max_heap.data); + assert_eq!(max_heap.pop(), 9); + println!("{:?}", max_heap.data); + assert_eq!(max_heap.pop(), 8); + println!("{:?}", max_heap.data); + assert_eq!(max_heap.pop(), 7); + println!("{:?}", max_heap.data); + assert_eq!(max_heap.pop(), 3); + println!("{:?}", max_heap.data); + assert_eq!(max_heap.pop(), 2); + println!("{:?}", max_heap.data); + assert_eq!(max_heap.pop(), 1); + println!("{:?}", max_heap.data); +} From 5dfba03a018f0b173d8fd1bf68b9d23c121cada5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 10 Aug 2022 18:42:07 +0800 Subject: [PATCH 0592/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 27ece271..f6e24c3f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 340 | 155 | 177 | 8 | +| 341 | 155 | 177 | 9 | ### 题目 @@ -329,6 +329,7 @@ |100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | |100301 | 最小的k个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-xiao-de-kge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof/) | Easy | |100302 | 包含min函数的栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/) | Easy | +|100303 | 数据流中的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-ju-liu-zhong-de-zhong-wei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof/) | Hard | |100306 | 栈的压入、弹出序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) | Medium | |100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | |100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | From 44e7b5ed461417aede536ee285a86e7135e07e64 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 11 Aug 2022 10:01:14 +0800 Subject: [PATCH 0593/1556] src/bin/lian-xu-zi-shu-zu-de-zui-da-he-lcof.rs --- .../lian-xu-zi-shu-zu-de-zui-da-he-lcof.rs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/bin/lian-xu-zi-shu-zu-de-zui-da-he-lcof.rs diff --git a/src/bin/lian-xu-zi-shu-zu-de-zui-da-he-lcof.rs b/src/bin/lian-xu-zi-shu-zu-de-zui-da-he-lcof.rs new file mode 100644 index 00000000..498ceb8b --- /dev/null +++ b/src/bin/lian-xu-zi-shu-zu-de-zui-da-he-lcof.rs @@ -0,0 +1,53 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() { + assert_eq!( + Solution::max_sub_array(vec![-2, 1, -3, 4, -1, 2, 1, -5, 4]), + 6 + ); +} + +struct Solution; + +impl Solution { + pub fn max_sub_array1(nums: Vec) -> i32 { + let mut dp = vec![0; nums.len()]; + dp[0] = nums[0]; + let mut result = dp[0]; + + for i in 1..nums.len() { + if dp[i - 1] > 0 { + dp[i] = dp[i - 1] + nums[i]; + } else { + dp[i] = nums[i]; + } + + if dp[i] > result { + result = dp[i]; + } + } + + result + } + + pub fn max_sub_array(nums: Vec) -> i32 { + let mut dp = nums[0]; + let mut result = dp; + + for &i in nums[1..].iter() { + if dp > 0 { + dp += i; + } else { + dp = i; + } + + if dp > result { + result = dp; + } + } + + result + } +} From 82dd66f20eecafbc931acc9e857352ef2f9b7be8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 11 Aug 2022 10:01:15 +0800 Subject: [PATCH 0594/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f6e24c3f..2650300c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 341 | 155 | 177 | 9 | +| 342 | 156 | 177 | 9 | ### 题目 @@ -330,6 +330,7 @@ |100301 | 最小的k个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-xiao-de-kge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof/) | Easy | |100302 | 包含min函数的栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/) | Easy | |100303 | 数据流中的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-ju-liu-zhong-de-zhong-wei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof/) | Hard | +|100304 | 连续子数组的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lian-xu-zi-shu-zu-de-zui-da-he-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/) | Easy | |100306 | 栈的压入、弹出序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) | Medium | |100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | |100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | From e8433c681522e2e889a6c283dd2d4938453031ac Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 12 Aug 2022 16:38:05 +0800 Subject: [PATCH 0595/1556] src/bin/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof.rs --- ...-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof.rs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/bin/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof.rs diff --git a/src/bin/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof.rs b/src/bin/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof.rs new file mode 100644 index 00000000..a513eafc --- /dev/null +++ b/src/bin/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + // println!("{}", Solution::find_nth_digit(3)); + println!("{}", Solution::find_nth_digit(11)); + println!("{}", Solution::find_nth_digit(20)); + println!("{}", Solution::find_nth_digit(21)); + println!("{}", Solution::find_nth_digit(3322432)); + println!("{}", Solution::find_nth_digit(324365434)); + println!("{}", Solution::find_nth_digit(95493394)); + println!("{}", Solution::find_nth_digit(1000000000)); +} + +struct Solution; + +impl Solution { + pub fn find_nth_digit(mut n: i32) -> i32 { + if n <= 9 { + return n; + } + + let mut n = n - 10; + let mut i = 2; + + // 2^31为10位的数字 + while i < 9 { + let s = (i as i32) * 9 * 10i32.pow(i - 1); + if n >= s { + n -= s; + } else { + break; + } + i += 1; + } + + let num = n / i as i32 + 10i32.pow(i - 1); + let digit = n % i as i32; + + num / (10i32.pow(i - digit as u32 - 1)) % 10 + } +} From b3937970fd6150cce0f9837647b1782fc6216344 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 12 Aug 2022 16:38:06 +0800 Subject: [PATCH 0596/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2650300c..7d9d8599 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 342 | 156 | 177 | 9 | +| 343 | 156 | 178 | 9 | ### 题目 @@ -337,6 +337,7 @@ |100310 | 数组中出现次数超过一半的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof/) | Easy | |100311 | 从上到下打印二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) | Medium | |100312 | 从上到下打印二叉树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/) | Easy | +|100313 | 数字序列中某一位的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof/) | Medium | |100314 | 从上到下打印二叉树 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof/) | Medium | |100315 | 二叉搜索树的后序遍历序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof/) | Medium | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | From 1e3845b49eb23ab5241b2e41d9fefdfc4c9937d6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 14 Aug 2022 10:52:06 +0800 Subject: [PATCH 0597/1556] src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs --- ...a-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs diff --git a/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs b/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs new file mode 100644 index 00000000..e861d748 --- /dev/null +++ b/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + println!("{}", Solution::min_number(vec![10, 2])); + println!("{}", Solution::min_number(vec![3, 30, 34, 5, 9])); +} + +struct Solution; + +impl Solution { + /// 如果 x + y > y + x, 则 x > y + /// 如果 x + y < y + x, 则 x < y + pub fn min_number(nums: Vec) -> String { + let mut nums: Vec = nums.into_iter().map(|x| x.to_string()).collect(); + nums.sort_by(|x, y| { + let mut s = String::with_capacity(x.len() + y.len()); + s.push_str(&x); + s.push_str(&y); + + let mut s1 = String::with_capacity(x.len() + y.len()); + s1.push_str(&y); + s1.push_str(&x); + + s.cmp(&s1) + }); + nums.join("") + } +} From 87e89340a6a9af8fdf6aada72884ffd4fad6215b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 14 Aug 2022 10:52:07 +0800 Subject: [PATCH 0598/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d9d8599..319fc29c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 343 | 156 | 178 | 9 | +| 344 | 156 | 179 | 9 | ### 题目 @@ -342,6 +342,7 @@ |100315 | 二叉搜索树的后序遍历序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof/) | Medium | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100317 | 二叉树中和为某一值的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/) | Medium | +|100323 | 把数组排成最小的数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | From 684fe25ccbe1fa33dd407968c81b59bde55eb6bf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 15 Aug 2022 09:12:07 +0800 Subject: [PATCH 0599/1556] src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs --- ...ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs b/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs index 3da1be8f..5caf98d8 100644 --- a/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs +++ b/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs @@ -5,7 +5,7 @@ fn main() {} struct Solution; impl Solution { - pub fn translate_num(num: i32) -> i32 { + pub fn translate_num1(num: i32) -> i32 { let s = num.to_string(); let s = s.as_bytes(); let mut count = 0; @@ -26,4 +26,21 @@ impl Solution { } Self::dp(&s[1..], count); } + + pub fn translate_num(num: i32) -> i32 { + if num == 0 { + return 0; + } + + let mut count = 1; + count += Self::translate_num(num / 10); + + let new_num = num % 100; + if new_num >= 10 && new_num <= 25 { + count += 1; + count += Self::translate_num(num / 100); + } + + count + } } From 8e3fca0fe69c42f7dd918d37dea78de981fc13fe Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 15 Aug 2022 09:12:08 +0800 Subject: [PATCH 0600/1556] src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs --- src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs diff --git a/src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs b/src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs new file mode 100644 index 00000000..5e58385b --- /dev/null +++ b/src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs @@ -0,0 +1,37 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_value(grid: Vec>) -> i32 { + let mut dp = vec![vec![0; grid[0].len()]; grid.len()]; + Self::dp(&grid, &mut dp, (0, 0)); + + dp[0][0] + } + + fn dp(grid: &[Vec], dp: &mut [Vec], index: (usize, usize)) { + if index.0 == grid.len() - 1 && index.1 == grid[0].len() - 1 { + dp[index.0][index.1] = grid[index.0][index.1]; + } + + if index.0 + 1 < grid.len() && dp[index.0 + 1][index.1] == 0 { + Self::dp(grid, dp, (index.0 + 1, index.1)); + } + + if index.1 + 1 < grid[0].len() && dp[index.0][index.1 + 1] == 0 { + Self::dp(grid, dp, (index.0, index.1 + 1)); + } + + if index.0 + 1 < grid.len() && index.1 + 1 < grid[0].len() { + dp[index.0][index.1] = + grid[index.0][index.1] + dp[index.0 + 1][index.1].max(dp[index.0][index.1 + 1]); + } else if index.0 + 1 < grid.len() { + dp[index.0][index.1] = grid[index.0][index.1] + dp[index.0 + 1][index.1]; + } else if index.1 + 1 < grid[0].len() { + dp[index.0][index.1] = grid[index.0][index.1] + dp[index.0][index.1 + 1]; + } + } +} From 369d95b7305927578fd90aa7784395954073ab3d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 15 Aug 2022 09:12:10 +0800 Subject: [PATCH 0601/1556] README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 319fc29c..b839dc8b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 344 | 156 | 179 | 9 | +| 346 | 156 | 181 | 9 | ### 题目 @@ -344,6 +344,8 @@ |100317 | 二叉树中和为某一值的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/) | Medium | |100323 | 把数组排成最小的数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | +|100327 | 礼物的最大价值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | |100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | From b6cae1845829c95681f3c0090a4560dc24a797b6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 15 Aug 2022 12:00:39 +0800 Subject: [PATCH 0602/1556] src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs --- ...n-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs diff --git a/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs b/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs new file mode 100644 index 00000000..c59f450f --- /dev/null +++ b/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs @@ -0,0 +1,38 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(3, Solution::length_of_longest_substring("abcabcbb".into())); + assert_eq!(1, Solution::length_of_longest_substring("bbbbb".into())); + assert_eq!(3, Solution::length_of_longest_substring("pwwkew".into())); + assert_eq!(2, Solution::length_of_longest_substring("au".into())); + assert_eq!(2, Solution::length_of_longest_substring("aab".into())); + assert_eq!(3, Solution::length_of_longest_substring("dvdf".into())); + assert_eq!(5, Solution::length_of_longest_substring("tmmzuxt".into())); +} + +struct Solution; + +impl Solution { + pub fn length_of_longest_substring(s: String) -> i32 { + let mut hash = std::collections::HashMap::new(); + let (mut start, mut length, mut result) = (0, 0, 0); + + for (index, value) in s.as_bytes().into_iter().enumerate() { + if let Some(i) = hash.get_mut(value) { + if start < *i { + start = *i; + } + + length = index - start; + *i = index; + } else { + hash.insert(value, index); + length += 1; + } + + result = result.max(length); + } + + result as i32 + } +} From 39ce70efb19685538f77aee0ed1e332df4cdaab4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 15 Aug 2022 12:00:40 +0800 Subject: [PATCH 0603/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b839dc8b..1212751f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 346 | 156 | 181 | 9 | +| 347 | 156 | 182 | 9 | ### 题目 @@ -346,6 +346,7 @@ |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100327 | 礼物的最大价值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/) | Medium | +|100332 | 最长不含重复字符的子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | |100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | From 8643d758b2e0fb93300bf5160e58621b36f9e5a9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 16 Aug 2022 17:36:52 +0800 Subject: [PATCH 0604/1556] src/bin/chou-shu-lcof.rs --- src/bin/chou-shu-lcof.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/chou-shu-lcof.rs diff --git a/src/bin/chou-shu-lcof.rs b/src/bin/chou-shu-lcof.rs new file mode 100644 index 00000000..c4d272a9 --- /dev/null +++ b/src/bin/chou-shu-lcof.rs @@ -0,0 +1,31 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn nth_ugly_number(n: i32) -> i32 { + let mut dp = vec![0; n as usize + 1]; + dp[1] = 1; + let (mut dpa, mut dpb, mut dpc) = (1, 1, 1); + for i in 2..=n as usize { + let next = (dp[dpa] * 2).min(dp[dpb] * 3).min(dp[dpc] * 5); + dp[i] = next; + + if next == dp[dpa] * 2 { + dpa += 1; + } + + if next == dp[dpb] * 3 { + dpb += 1; + } + + if next == dp[dpc] * 5 { + dpc += 1; + } + } + + dp[n as usize] + } +} From b7aa705b0295819ac6ba4a706dce9fb4237f2494 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 16 Aug 2022 17:36:52 +0800 Subject: [PATCH 0605/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1212751f..09423ca0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 347 | 156 | 182 | 9 | +| 348 | 156 | 183 | 9 | ### 题目 @@ -348,6 +348,7 @@ |100327 | 礼物的最大价值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/) | Medium | |100332 | 最长不含重复字符的子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | +|100334 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chou-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/chou-shu-lcof/) | Medium | |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | |100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | |100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | From f5e092da0db26b2b5dc5567f6db5eea45cd93534 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 17 Aug 2022 12:57:07 +0800 Subject: [PATCH 0606/1556] src/bin/shu-zu-zhong-de-ni-xu-dui-lcof.rs --- src/bin/shu-zu-zhong-de-ni-xu-dui-lcof.rs | 78 +++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/bin/shu-zu-zhong-de-ni-xu-dui-lcof.rs diff --git a/src/bin/shu-zu-zhong-de-ni-xu-dui-lcof.rs b/src/bin/shu-zu-zhong-de-ni-xu-dui-lcof.rs new file mode 100644 index 00000000..da7371b4 --- /dev/null +++ b/src/bin/shu-zu-zhong-de-ni-xu-dui-lcof.rs @@ -0,0 +1,78 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 暴力解法 + pub fn reverse_pairs1(nums: Vec) -> i32 { + let mut result = 0; + + for i in 0..nums.len() { + for j in i..nums.len() { + if nums[i] > nums[j] { + result += 1; + } + } + } + + result + } + + /// 使用merge sort排序 + pub fn reverse_pairs(nums: Vec) -> i32 { + let mut new = vec![0; nums.len()]; + Self::merge_sort(&nums, &mut new) + } + + fn merge_sort(nums: &[i32], new: &mut [i32]) -> i32 { + let mut num = 0; + if nums.len() <= 1 { + if nums.len() == 1 { + new[0] = nums[0]; + } + return num; + } + + let middle = nums.len() / 2; + + let mut left_vec = vec![0; middle]; + let left = Self::merge_sort(&nums[..middle], &mut left_vec); + + let mut right_vec = vec![0; nums.len() - middle]; + let right = Self::merge_sort(&nums[middle..], &mut right_vec); + + let (mut i, mut j, mut k) = (0, 0, 0); + + loop { + match (left_vec.get(i), right_vec.get(j)) { + (Some(x), Some(y)) => { + if *x > *y { + j += 1; + num += (left_vec.len() - i) as i32; + new[k] = *y; + } else { + i += 1; + new[k] = *x; + } + } + + (Some(x), None) => { + new[k] = *x; + i += 1; + } + + (None, Some(y)) => { + new[k] = *y; + j += 1; + } + + (None, None) => break, + } + + k += 1; + } + num + left + right + } +} From 54202594805edaa1a40fe3b07f68e8df651ecde4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 17 Aug 2022 12:57:08 +0800 Subject: [PATCH 0607/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 09423ca0..5e6bb68e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 348 | 156 | 183 | 9 | +| 349 | 156 | 183 | 10 | ### 题目 @@ -342,6 +342,7 @@ |100315 | 二叉搜索树的后序遍历序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof/) | Medium | |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100317 | 二叉树中和为某一值的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/) | Medium | +|100318 | 数组中的逆序对 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-de-ni-xu-dui-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/) | Hard | |100323 | 把数组排成最小的数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From 089537ea8454f9b539e40eff9c3c7d9a00e1914f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 17 Aug 2022 16:06:43 +0800 Subject: [PATCH 0608/1556] src/bin/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof.rs --- ...ai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof.rs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/bin/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof.rs diff --git a/src/bin/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof.rs b/src/bin/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof.rs new file mode 100644 index 00000000..2472692d --- /dev/null +++ b/src/bin/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof.rs @@ -0,0 +1,44 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + // 二分法 + // 找到第一个数和最后一个数的下标,相减得到数量 + pub fn search(nums: Vec, target: i32) -> i32 { + let (mut start, mut end) = (0, nums.len()); + let (mut left, mut right) = (0, 0); + + // 搜索右边界 + while start < end { + let middle = (end + start) / 2; + + if nums[middle] <= target { + start = middle + 1; + } else { + end = middle; + } + } + + right = start as i32; + + let (mut start, mut end) = (0, nums.len()); + + // 搜索左边界 + while start < end { + let middle = (end + start) / 2; + + if nums[middle] >= target { + end = middle; + } else { + start = middle + 1; + } + } + + left = start as i32; + + right - left + } +} From 5845504f8e0e956046e7045d7aa9cbb535fb3d34 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 17 Aug 2022 16:06:44 +0800 Subject: [PATCH 0609/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e6bb68e..ab553da7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 349 | 156 | 183 | 10 | +| 350 | 157 | 183 | 10 | ### 题目 @@ -347,6 +347,7 @@ |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100327 | 礼物的最大价值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/) | Medium | +|100329 | 在排序数组中查找数字 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/) | Easy | |100332 | 最长不含重复字符的子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | |100334 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chou-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/chou-shu-lcof/) | Medium | From 3110b3e3a50f02d47a90854cec02267d892f9826 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 17 Aug 2022 16:17:43 +0800 Subject: [PATCH 0610/1556] src/bin/que-shi-de-shu-zi-lcof.rs --- src/bin/que-shi-de-shu-zi-lcof.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/bin/que-shi-de-shu-zi-lcof.rs diff --git a/src/bin/que-shi-de-shu-zi-lcof.rs b/src/bin/que-shi-de-shu-zi-lcof.rs new file mode 100644 index 00000000..ea96da2d --- /dev/null +++ b/src/bin/que-shi-de-shu-zi-lcof.rs @@ -0,0 +1,22 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn missing_number(nums: Vec) -> i32 { + let (mut start, mut end) = (0, nums.len()); + + while start < end { + let middle = (start + end) / 2; + if nums[middle] <= middle as i32 { + start = middle + 1; + } else { + end = middle; + } + } + + start as i32 + } +} From f3176c2b1fa43bbc3dabd0e1562610a93b67d8a8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 17 Aug 2022 16:17:43 +0800 Subject: [PATCH 0611/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ab553da7..d3a4a64d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 350 | 157 | 183 | 10 | +| 351 | 158 | 183 | 10 | ### 题目 @@ -348,6 +348,7 @@ |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100327 | 礼物的最大价值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/) | Medium | |100329 | 在排序数组中查找数字 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/) | Easy | +|100331 | 0~n-1中缺失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/que-shi-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/) | Easy | |100332 | 最长不含重复字符的子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | |100334 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chou-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/chou-shu-lcof/) | Medium | From d49a20da6ccbe165f7b6c7368a6583cde90e432d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Aug 2022 09:47:33 +0800 Subject: [PATCH 0612/1556] src/bin/er-cha-shu-de-shen-du-lcof.rs --- src/bin/er-cha-shu-de-shen-du-lcof.rs | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/bin/er-cha-shu-de-shen-du-lcof.rs diff --git a/src/bin/er-cha-shu-de-shen-du-lcof.rs b/src/bin/er-cha-shu-de-shen-du-lcof.rs new file mode 100644 index 00000000..50094e55 --- /dev/null +++ b/src/bin/er-cha-shu-de-shen-du-lcof.rs @@ -0,0 +1,60 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::cell::RefCell; +use std::rc::Rc; + +use serde::__private::de; +impl Solution { + pub fn max_depth(root: Option>>) -> i32 { + if root.is_none() { + return 0; + } + + let mut depth = 0; + let mut v = vec![root]; + + while !v.is_empty() { + let mut new_v = vec![]; + + while let Some(Some(x)) = v.pop() { + let left = x.borrow_mut().left.take(); + if left.is_some() { + new_v.push(left); + } + + let right = x.borrow_mut().right.take(); + if right.is_some() { + new_v.push(right); + } + } + + depth += 1; + v = new_v; + } + + depth + } +} From 3c995ca429050cf6744abb61fbf51a5c20362c87 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Aug 2022 09:47:34 +0800 Subject: [PATCH 0613/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d3a4a64d..f6255de5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 351 | 158 | 183 | 10 | +| 352 | 159 | 183 | 10 | ### 题目 @@ -343,6 +343,7 @@ |100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | |100317 | 二叉树中和为某一值的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/) | Medium | |100318 | 数组中的逆序对 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-de-ni-xu-dui-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/) | Hard | +|100319 | 二叉树的深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-shen-du-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) | Easy | |100323 | 把数组排成最小的数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From 437dfad2bea53ea611a26ebbb7598bf172c85e0c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Aug 2022 10:27:36 +0800 Subject: [PATCH 0614/1556] src/bin/er-cha-shu-de-shen-du-lcof.rs --- src/bin/er-cha-shu-de-shen-du-lcof.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/bin/er-cha-shu-de-shen-du-lcof.rs b/src/bin/er-cha-shu-de-shen-du-lcof.rs index 50094e55..f11099f0 100644 --- a/src/bin/er-cha-shu-de-shen-du-lcof.rs +++ b/src/bin/er-cha-shu-de-shen-du-lcof.rs @@ -28,7 +28,7 @@ use std::rc::Rc; use serde::__private::de; impl Solution { - pub fn max_depth(root: Option>>) -> i32 { + pub fn max_depth1(root: Option>>) -> i32 { if root.is_none() { return 0; } @@ -57,4 +57,15 @@ impl Solution { depth } + + pub fn max_depth(root: Option>>) -> i32 { + if root.is_none() { + return 0; + } + + let left = root.clone().unwrap().borrow_mut().left.take(); + let right = root.clone().unwrap().borrow_mut().right.take(); + + 1 + Self::max_depth(left).max(Self::max_depth(right)) + } } From 634594e7c6063721ffe38b18603faa4cdcad3f19 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Aug 2022 10:27:36 +0800 Subject: [PATCH 0615/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f6255de5..78981887 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 352 | 159 | 183 | 10 | +| 353 | 160 | 183 | 10 | ### 题目 @@ -344,6 +344,7 @@ |100317 | 二叉树中和为某一值的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/) | Medium | |100318 | 数组中的逆序对 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-de-ni-xu-dui-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/) | Hard | |100319 | 二叉树的深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-shen-du-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) | Easy | +|100319 | 二叉树的深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-shen-du-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) | Easy | |100323 | 把数组排成最小的数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From 6b4ba22f0b0cb99840ee8ede8971ed5e7c0c0b8b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Aug 2022 15:13:16 +0800 Subject: [PATCH 0616/1556] src/bin/ping-heng-er-cha-shu-lcof.rs --- src/bin/ping-heng-er-cha-shu-lcof.rs | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/bin/ping-heng-er-cha-shu-lcof.rs diff --git a/src/bin/ping-heng-er-cha-shu-lcof.rs b/src/bin/ping-heng-er-cha-shu-lcof.rs new file mode 100644 index 00000000..a1a0259b --- /dev/null +++ b/src/bin/ping-heng-er-cha-shu-lcof.rs @@ -0,0 +1,57 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn is_balanced(root: Option>>) -> bool { + let (result, _) = Self::scan(root); + result + } + + pub fn scan(root: Option>>) -> (bool, i32) { + if root.is_none() { + return (true, 0); + } + let root = root.clone().unwrap(); + let left = root.borrow_mut().left.take(); + let right = root.borrow_mut().right.take(); + + let (r1, h1) = Self::scan(left); + if !r1 { + return (false, 0); + } + + let (r2, h2) = Self::scan(right); + if !r2 { + return (false, 0); + } + + if (h1 - h2).abs() > 1 { + return (false, 0); + } + + (true, 1 + h1.max(h2)) + } +} From 5dac971580a054619d5f5f0d9459c9f5148b3c38 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Aug 2022 15:13:16 +0800 Subject: [PATCH 0617/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 78981887..79a74af6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 353 | 160 | 183 | 10 | +| 354 | 161 | 183 | 10 | ### 题目 @@ -354,6 +354,7 @@ |100332 | 最长不含重复字符的子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | |100334 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chou-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/chou-shu-lcof/) | Medium | +|100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | |100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | |100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | From 01b01bcf1ba1fa20b8c5495e7031a706ef610cc3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Aug 2022 16:12:09 +0800 Subject: [PATCH 0618/1556] src/bin/ping-heng-er-cha-shu-lcof.rs --- src/bin/ping-heng-er-cha-shu-lcof.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/bin/ping-heng-er-cha-shu-lcof.rs b/src/bin/ping-heng-er-cha-shu-lcof.rs index a1a0259b..3f8def9d 100644 --- a/src/bin/ping-heng-er-cha-shu-lcof.rs +++ b/src/bin/ping-heng-er-cha-shu-lcof.rs @@ -26,32 +26,31 @@ use std::cell::RefCell; use std::rc::Rc; impl Solution { pub fn is_balanced(root: Option>>) -> bool { - let (result, _) = Self::scan(root); - result + Self::scan(root) != -1 } - pub fn scan(root: Option>>) -> (bool, i32) { + pub fn scan(root: Option>>) -> i32 { if root.is_none() { - return (true, 0); + return 0; } let root = root.clone().unwrap(); let left = root.borrow_mut().left.take(); let right = root.borrow_mut().right.take(); - let (r1, h1) = Self::scan(left); - if !r1 { - return (false, 0); + let h1 = Self::scan(left); + if h1 == -1 { + return -1; } - let (r2, h2) = Self::scan(right); - if !r2 { - return (false, 0); + let h2 = Self::scan(right); + if h2 == -1 { + return -1; } if (h1 - h2).abs() > 1 { - return (false, 0); + return -1; } - (true, 1 + h1.max(h2)) + 1 + h1.max(h2) } } From 0a10a60abed09528fe134b3a0adcb950a8790bdd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Aug 2022 16:12:09 +0800 Subject: [PATCH 0619/1556] src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof.rs --- ...zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof.rs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof.rs diff --git a/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof.rs b/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof.rs new file mode 100644 index 00000000..e92c18d3 --- /dev/null +++ b/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +impl Solution { + /// https://leetcode.cn/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/solution/jian-zhi-offer-56-i-shu-zu-zhong-shu-zi-tykom/ + pub fn single_numbers(nums: Vec) -> Vec { + let mut x = 0; + + for &i in nums.iter() { + x ^= i; + } + + let mut m = 1; + while x & m != m { + m <<= 1; + } + + let mut v = vec![0; 2]; + + for &i in nums.iter() { + if i & m == m { + v[0] ^= i; + } else { + v[1] ^= i; + } + } + + v + } +} From 2197dcb0d0294a3c58742672257707a1d9e84fdc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Aug 2022 16:12:10 +0800 Subject: [PATCH 0620/1556] README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 79a74af6..9762b32e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 354 | 161 | 183 | 10 | +| 356 | 162 | 184 | 10 | ### 题目 @@ -345,6 +345,7 @@ |100318 | 数组中的逆序对 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-de-ni-xu-dui-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/) | Hard | |100319 | 二叉树的深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-shen-du-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) | Easy | |100319 | 二叉树的深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-shen-du-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) | Easy | +|100320 | 数组中数字出现的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/) | Medium | |100323 | 把数组排成最小的数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | @@ -355,6 +356,7 @@ |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | |100334 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chou-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/chou-shu-lcof/) | Medium | |100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | +|100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | |100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | |100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | From d9d363e3142e18e8006744eb6fd60456340436e9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Aug 2022 17:12:10 +0800 Subject: [PATCH 0621/1556] src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof.rs --- ...zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof.rs diff --git a/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof.rs b/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof.rs new file mode 100644 index 00000000..8e0f4fb9 --- /dev/null +++ b/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn single_number(nums: Vec) -> i32 { + let mut v = [0; 32]; + + for mut i in nums { + let mut index = 0; + while i > 0 { + if i & 1 == 1 { + v[index] += 1; + } + index += 1; + i >>= 1; + } + } + + let mut result = 0; + + for (index, &value) in v.iter().enumerate() { + if value % 3 != 0 { + result |= (1 << index); + } + } + + result + } +} From e23e14ce20adc8b65d3fd912b5bea37caaf60bf9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Aug 2022 17:12:11 +0800 Subject: [PATCH 0622/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9762b32e..b11556be 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 356 | 162 | 184 | 10 | +| 357 | 162 | 185 | 10 | ### 题目 @@ -346,6 +346,7 @@ |100319 | 二叉树的深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-shen-du-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) | Easy | |100319 | 二叉树的深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-shen-du-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) | Easy | |100320 | 数组中数字出现的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/) | Medium | +|100321 | 数组中数字出现的次数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/) | Medium | |100323 | 把数组排成最小的数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From 9ee43199ae2ce1136d3cf6e5cf1837a0b21273b1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 19 Aug 2022 11:18:38 +0800 Subject: [PATCH 0623/1556] src/bin/he-wei-sde-liang-ge-shu-zi-lcof.rs --- src/bin/he-wei-sde-liang-ge-shu-zi-lcof.rs | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/he-wei-sde-liang-ge-shu-zi-lcof.rs diff --git a/src/bin/he-wei-sde-liang-ge-shu-zi-lcof.rs b/src/bin/he-wei-sde-liang-ge-shu-zi-lcof.rs new file mode 100644 index 00000000..92155187 --- /dev/null +++ b/src/bin/he-wei-sde-liang-ge-shu-zi-lcof.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn two_sum(nums: Vec, target: i32) -> Vec { + let (mut i, mut j) = (0, nums.len() - 1); + + while i < j { + if target - nums[i] > nums[j] { + j -= 1; + } else if target - nums[i] < nums[j] { + i += 1; + } else { + break; + } + } + + vec![nums[i], nums[j]] + } +} From e93d0052961bb4a59f32f24ee9075a348d5363cf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 19 Aug 2022 11:18:39 +0800 Subject: [PATCH 0624/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b11556be..22dc4ed5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 357 | 162 | 185 | 10 | +| 358 | 163 | 185 | 10 | ### 题目 @@ -347,6 +347,7 @@ |100319 | 二叉树的深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-shen-du-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) | Easy | |100320 | 数组中数字出现的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/) | Medium | |100321 | 数组中数字出现的次数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/) | Medium | +|100322 | 和为s的两个数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/he-wei-sde-liang-ge-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof/) | Easy | |100323 | 把数组排成最小的数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | From 6f96cf635a9ce9d6a2f04397f92ea85f6b9c1178 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 19 Aug 2022 15:42:29 +0800 Subject: [PATCH 0625/1556] src/bin/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof.rs --- ...e-wei-sde-lian-xu-zheng-shu-xu-lie-lcof.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/bin/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof.rs diff --git a/src/bin/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof.rs b/src/bin/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof.rs new file mode 100644 index 00000000..d5cf2c78 --- /dev/null +++ b/src/bin/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof.rs @@ -0,0 +1,34 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 从i=1,j=2开始,代表连续数组的边界值,sum为3,此时sum是最小的 + /// 如果sum大于target,则说明i需要增加,i增加则sum减少i + /// 如果sum小于target,则说明j需要增加,j增加则sum增加j + /// 当i>=j时,终止 + pub fn find_continuous_sequence(target: i32) -> Vec> { + let (mut i, mut j) = (1, 2); + let mut sum = i + j; + let mut v = vec![]; + while i < j { + if sum == target { + v.push((i..=j).collect()); + sum -= i; + i += 1; + j += 1; + sum += j; + } else if sum > target { + sum -= i; + i += 1; + } else { + j += 1; + sum += j; + } + } + + v + } +} From d3e466fc2c63b0c104c77265031e313aa12054df Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 19 Aug 2022 15:42:29 +0800 Subject: [PATCH 0626/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 22dc4ed5..8570c05f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 358 | 163 | 185 | 10 | +| 359 | 164 | 185 | 10 | ### 题目 @@ -349,6 +349,7 @@ |100321 | 数组中数字出现的次数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/) | Medium | |100322 | 和为s的两个数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/he-wei-sde-liang-ge-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof/) | Easy | |100323 | 把数组排成最小的数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | Medium | +|100324 | 和为s的连续正数序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/) | Easy | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100327 | 礼物的最大价值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/) | Medium | From 638ddbf20ec2437c5bc7442c1eea92cdfa344c0c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 21 Aug 2022 14:52:27 +0800 Subject: [PATCH 0627/1556] src/bin/zuo-xuan-zhuan-zi-fu-chuan-lcof.rs --- src/bin/zuo-xuan-zhuan-zi-fu-chuan-lcof.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/bin/zuo-xuan-zhuan-zi-fu-chuan-lcof.rs diff --git a/src/bin/zuo-xuan-zhuan-zi-fu-chuan-lcof.rs b/src/bin/zuo-xuan-zhuan-zi-fu-chuan-lcof.rs new file mode 100644 index 00000000..c9cec9c6 --- /dev/null +++ b/src/bin/zuo-xuan-zhuan-zi-fu-chuan-lcof.rs @@ -0,0 +1,19 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::{io::Read, vec}; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn reverse_left_words(s: String, n: i32) -> String { + let mut r = Vec::with_capacity(s.len()); + let bytes = s.as_bytes(); + for i in (n as usize..(n as usize + s.len())) { + r.push(bytes[i % s.len()]); + } + + String::from_utf8(r).unwrap() + } +} From 48cffe3b72202be0526ef24b4365415f30a98afc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 21 Aug 2022 14:52:28 +0800 Subject: [PATCH 0628/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8570c05f..db5e9c16 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 359 | 164 | 185 | 10 | +| 360 | 165 | 185 | 10 | ### 题目 @@ -354,6 +354,7 @@ |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100327 | 礼物的最大价值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/) | Medium | |100329 | 在排序数组中查找数字 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/) | Easy | +|100330 | 左旋转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zuo-xuan-zhuan-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/) | Easy | |100331 | 0~n-1中缺失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/que-shi-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/) | Easy | |100332 | 最长不含重复字符的子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | From b1a45386579b32c1b56a0ee4549b7f3b38d80232 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 23 Aug 2022 11:52:53 +0800 Subject: [PATCH 0629/1556] src/bin/nge-tou-zi-de-dian-shu-lcof.rs --- src/bin/nge-tou-zi-de-dian-shu-lcof.rs | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/nge-tou-zi-de-dian-shu-lcof.rs diff --git a/src/bin/nge-tou-zi-de-dian-shu-lcof.rs b/src/bin/nge-tou-zi-de-dian-shu-lcof.rs new file mode 100644 index 00000000..0b652a4a --- /dev/null +++ b/src/bin/nge-tou-zi-de-dian-shu-lcof.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +impl Solution { + /// 和的范围为n - 6n + pub fn dices_probability(n: i32) -> Vec { + if n == 1 { + return vec![1.0 / 6.0; 6]; + } + + let mut r = vec![0f64; (5 * n + 1) as usize]; + + let r1 = Self::dices_probability(n - 1); + + for i in 1..=6 { + // index代表n-1个骰子的和,index=0的和为n-1 + for (index, &value) in r1.iter().enumerate() { + r[(index + (n - 1) as usize) + i - n as usize] += value * 1.0 / 6.0; + } + } + + r + } +} From e338acedd870942702963b09e67033d18d6559e8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 23 Aug 2022 11:52:54 +0800 Subject: [PATCH 0630/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index db5e9c16..5fea5a22 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 360 | 165 | 185 | 10 | +| 361 | 165 | 186 | 10 | ### 题目 @@ -359,6 +359,7 @@ |100332 | 最长不含重复字符的子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | |100334 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chou-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/chou-shu-lcof/) | Medium | +|100339 | n个骰子的点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nge-tou-zi-de-dian-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/nge-tou-zi-de-dian-shu-lcof/) | Medium | |100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | |100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | From ba4320a6a092097dcc52e126d038d54925e3851f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 23 Aug 2022 16:53:19 +0800 Subject: [PATCH 0631/1556] src/bin/bu-ke-pai-zhong-de-shun-zi-lcof.rs --- src/bin/bu-ke-pai-zhong-de-shun-zi-lcof.rs | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/bin/bu-ke-pai-zhong-de-shun-zi-lcof.rs diff --git a/src/bin/bu-ke-pai-zhong-de-shun-zi-lcof.rs b/src/bin/bu-ke-pai-zhong-de-shun-zi-lcof.rs new file mode 100644 index 00000000..7791b860 --- /dev/null +++ b/src/bin/bu-ke-pai-zhong-de-shun-zi-lcof.rs @@ -0,0 +1,69 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn is_straight1(nums: Vec) -> bool { + let mut nums = nums; + nums.sort(); + + let mut zero_num = 0; + for i in 0..nums.len() { + if nums[i] == 0 { + zero_num += 1; + } else { + if i > 0 && nums[i - 1] != 0 { + if nums[i] - nums[i - 1] > 0 { + zero_num -= (nums[i] - nums[i - 1] - 1); + } else { + return false; + } + + if zero_num < 0 { + return false; + } + } + } + } + + true + } + + pub fn is_straight(nums: Vec) -> bool { + let mut min = std::i32::MAX; + let mut zero = 0; // 0 的数量 + let set = nums + .into_iter() + .map(|x| { + if x == 0 { + zero += 1; + } else if x < min { + min = x; + } + + x + }) + .filter(|x| *x != 0) + .collect::>(); + + if zero == 5 { + return true; + } + + for i in 0..5 { + if set.contains(&(i + min)) { + continue; + } else { + if zero > 0 { + zero -= 1; + } else { + return false; + } + } + } + + true + } +} From d8425010e880e2f87511510fc8d7d4620f53887f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 23 Aug 2022 16:53:19 +0800 Subject: [PATCH 0632/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5fea5a22..02e82420 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 361 | 165 | 186 | 10 | +| 362 | 166 | 186 | 10 | ### 题目 @@ -360,6 +360,7 @@ |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | |100334 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chou-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/chou-shu-lcof/) | Medium | |100339 | n个骰子的点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nge-tou-zi-de-dian-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/nge-tou-zi-de-dian-shu-lcof/) | Medium | +|100341 | 扑克牌中的顺子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bu-ke-pai-zhong-de-shun-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof/) | Easy | |100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | |100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | From 76ac465b6da09145e877f505152046a68ff40b62 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 24 Aug 2022 13:43:13 +0800 Subject: [PATCH 0633/1556] update dependicies --- Cargo.lock | 319 +++++++++++++---------------------------------------- Cargo.toml | 6 +- 2 files changed, 81 insertions(+), 244 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4378e4ea..694d0479 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,7 +19,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -88,12 +88,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytes" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" - [[package]] name = "bytes" version = "1.1.0" @@ -109,12 +103,6 @@ dependencies = [ "jobserver", ] -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -130,7 +118,7 @@ dependencies = [ "libc", "num-integer", "num-traits", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -201,7 +189,7 @@ version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "once_cell", ] @@ -226,7 +214,7 @@ version = "0.8.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -275,22 +263,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - [[package]] name = "futures-channel" version = "0.3.21" @@ -334,7 +306,7 @@ dependencies = [ "futures-io", "futures-task", "memchr", - "pin-project-lite 0.2.9", + "pin-project-lite", "pin-utils", "slab", ] @@ -354,16 +326,16 @@ version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "wasi", ] [[package]] name = "git2" -version = "0.13.25" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29229cc1b24c0e6062f6e742aa3e256492a5323365e5ed3413599f8a5eff7d6" +checksum = "d0155506aab710a86160ddb504a480d2964d7ab5b9e62419be69e0032bc5931c" dependencies = [ "bitflags", "libc", @@ -400,11 +372,11 @@ dependencies = [ [[package]] name = "h2" -version = "0.2.7" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" dependencies = [ - "bytes 0.5.6", + "bytes", "fnv", "futures-core", "futures-sink", @@ -415,7 +387,6 @@ dependencies = [ "tokio", "tokio-util", "tracing", - "tracing-futures", ] [[package]] @@ -439,19 +410,20 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" dependencies = [ - "bytes 1.1.0", + "bytes", "fnv", - "itoa 1.0.2", + "itoa", ] [[package]] name = "http-body" -version = "0.3.1" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ - "bytes 0.5.6", + "bytes", "http", + "pin-project-lite", ] [[package]] @@ -462,9 +434,9 @@ checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" [[package]] name = "httpdate" -version = "0.3.2" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "humansize" @@ -474,11 +446,11 @@ checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026" [[package]] name = "hyper" -version = "0.13.10" +version = "0.14.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a6f157065790a3ed2f88679250419b5cdd96e714a0d65f7797fd337186e96bb" +checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" dependencies = [ - "bytes 0.5.6", + "bytes", "futures-channel", "futures-core", "futures-util", @@ -487,8 +459,8 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 0.4.8", - "pin-project", + "itoa", + "pin-project-lite", "socket2", "tokio", "tower-service", @@ -498,15 +470,15 @@ dependencies = [ [[package]] name = "hyper-tls" -version = "0.4.3" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ - "bytes 0.5.6", + "bytes", "hyper", "native-tls", "tokio", - "tokio-tls", + "tokio-native-tls", ] [[package]] @@ -554,16 +526,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", + "cfg-if", ] [[package]] @@ -572,12 +535,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" -[[package]] -name = "itoa" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" - [[package]] name = "itoa" version = "1.0.2" @@ -602,16 +559,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -641,9 +588,9 @@ checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "libgit2-sys" -version = "0.12.26+1.3.0" +version = "0.13.4+1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e1c899248e606fbfe68dcb31d8b0176ebab833b103824af31bddf4b7457494" +checksum = "d0fa6563431ede25f5cc7f6d803c6afbc1c5d3ad3d4925d12c882bf2b526f5d1" dependencies = [ "cc", "libc", @@ -685,7 +632,7 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -712,45 +659,16 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" -[[package]] -name = "mime_guess" -version = "2.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" -dependencies = [ - "mime", - "unicase", -] - [[package]] name = "mio" -version = "0.6.23" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" +checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", "libc", "log", - "miow", - "net2", - "slab", - "winapi 0.2.8", -] - -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", + "wasi", + "windows-sys", ] [[package]] @@ -771,17 +689,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "net2" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", -] - [[package]] name = "num-integer" version = "0.1.45" @@ -830,7 +737,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" dependencies = [ "bitflags", - "cfg-if 1.0.0", + "cfg-if", "foreign-types", "libc", "once_cell", @@ -971,32 +878,6 @@ dependencies = [ "uncased", ] -[[package]] -name = "pin-project" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78203e83c48cffbe01e4a2d35d566ca4de445d79a85372fc64e378bfc812a260" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "710faf75e1b33345361201d36d04e98ac1ed8909151a017ed384700836104c74" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pin-project-lite" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" - [[package]] name = "pin-project-lite" version = "0.2.9" @@ -1101,20 +982,21 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] name = "reqwest" -version = "0.10.10" +version = "0.11.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0718f81a8e14c4dbb3b34cf23dc6aaf9ab8a0dfec160c534b3dbca1aaa21f47c" +checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" dependencies = [ "base64", - "bytes 0.5.6", + "bytes", "encoding_rs", "futures-core", "futures-util", + "h2", "http", "http-body", "hyper", @@ -1124,15 +1006,15 @@ dependencies = [ "lazy_static", "log", "mime", - "mime_guess", "native-tls", "percent-encoding", - "pin-project-lite 0.2.9", + "pin-project-lite", "serde", "serde_json", "serde_urlencoded", "tokio", - "tokio-tls", + "tokio-native-tls", + "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", @@ -1214,7 +1096,7 @@ version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" dependencies = [ - "itoa 1.0.2", + "itoa", "ryu", "serde", ] @@ -1226,7 +1108,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa 1.0.2", + "itoa", "ryu", "serde", ] @@ -1266,13 +1148,12 @@ dependencies = [ [[package]] name = "socket2" -version = "0.3.19" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" dependencies = [ - "cfg-if 1.0.0", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1298,12 +1179,12 @@ version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "fastrand", "libc", "redox_syscall", "remove_dir_all", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1369,27 +1250,27 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "0.2.25" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" +checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" dependencies = [ - "bytes 0.5.6", - "fnv", - "futures-core", - "iovec", - "lazy_static", + "autocfg", + "bytes", + "libc", "memchr", "mio", "num_cpus", - "pin-project-lite 0.1.12", - "slab", + "once_cell", + "pin-project-lite", + "socket2", + "winapi", ] [[package]] -name = "tokio-tls" -version = "0.3.1" +name = "tokio-native-tls" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a70f4fcd7b3b24fb194f837560168208f669ca8cb70d0c4b862944452396343" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" dependencies = [ "native-tls", "tokio", @@ -1397,16 +1278,16 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.3.1" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" dependencies = [ - "bytes 0.5.6", + "bytes", "futures-core", "futures-sink", - "log", - "pin-project-lite 0.1.12", + "pin-project-lite", "tokio", + "tracing", ] [[package]] @@ -1421,9 +1302,8 @@ version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" dependencies = [ - "cfg-if 1.0.0", - "log", - "pin-project-lite 0.2.9", + "cfg-if", + "pin-project-lite", "tracing-core", ] @@ -1436,16 +1316,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - [[package]] name = "try-lock" version = "0.2.3" @@ -1523,15 +1393,6 @@ dependencies = [ "unic-common", ] -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - [[package]] name = "unicode-bidi" version = "0.3.8" @@ -1584,7 +1445,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" dependencies = [ "same-file", - "winapi 0.3.9", + "winapi", "winapi-util", ] @@ -1610,9 +1471,7 @@ version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" dependencies = [ - "cfg-if 1.0.0", - "serde", - "serde_json", + "cfg-if", "wasm-bindgen-macro", ] @@ -1637,7 +1496,7 @@ version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "wasm-bindgen", "web-sys", @@ -1682,12 +1541,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.9" @@ -1698,12 +1551,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1716,7 +1563,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1770,19 +1617,9 @@ checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "winreg" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" -dependencies = [ - "winapi 0.3.9", -] - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ - "winapi 0.2.8", - "winapi-build", + "winapi", ] diff --git a/Cargo.toml b/Cargo.toml index 3acd6cb8..cb33a606 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,8 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -git2 = "0.13.15" -reqwest = { version = "0.10", features = ["blocking", "json"] } +git2 = "0.14.4" +reqwest = { version = "0.11.11", features = ["blocking", "json"] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } clap = "3.0.0-beta.2" @@ -19,5 +19,5 @@ rand = "0.8.4" [[bin]] -name ="leetcode" +name = "leetcode" path = "src/main.rs" From 9cba08e28f1dd0d02ea55ad3b48e71bafcb89e17 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 24 Aug 2022 14:25:57 +0800 Subject: [PATCH 0634/1556] src/bin/gou-jian-cheng-ji-shu-zu-lcof.rs --- src/bin/gou-jian-cheng-ji-shu-zu-lcof.rs | 57 ++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/bin/gou-jian-cheng-ji-shu-zu-lcof.rs diff --git a/src/bin/gou-jian-cheng-ji-shu-zu-lcof.rs b/src/bin/gou-jian-cheng-ji-shu-zu-lcof.rs new file mode 100644 index 00000000..07a35894 --- /dev/null +++ b/src/bin/gou-jian-cheng-ji-shu-zu-lcof.rs @@ -0,0 +1,57 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn construct_arr1(a: Vec) -> Vec { + if a.is_empty() { + return vec![]; + } + + let mut v1 = vec![0; a.len()]; + let mut v2 = vec![0; a.len()]; + + for i in 0..a.len() { + if i == 0 { + v1[i] = a[i]; + v2[a.len() - 1] = a[a.len() - 1]; + } else { + v1[i] = a[i] * v1[i - 1]; + v2[a.len() - 1 - i] = a[a.len() - 1 - i] * v2[a.len() - i]; + } + } + + let mut r = Vec::with_capacity(a.len()); + + for i in 0..a.len() { + if i == 0 { + r.push(v2[i + 1]); + } else if i == a.len() - 1 { + r.push(v1[a.len() - 2]); + } else { + r.push(v1[i - 1] * v2[1 + i]); + } + } + + r + } + + pub fn construct_arr(a: Vec) -> Vec { + let mut r = vec![1; a.len()]; + + for i in 1..a.len() { + r[i] = a[i - 1] * r[i - 1]; + } + let mut temp = 1; + for i in (0..a.len()).rev() { + r[i] *= temp; + temp *= a[i]; + } + + r + } +} From e98dca18b6ff4fb7dea8fd7f80de8db9d0e16db9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 24 Aug 2022 14:25:58 +0800 Subject: [PATCH 0635/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 02e82420..5955f1e6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 362 | 166 | 186 | 10 | +| 363 | 166 | 187 | 10 | ### 题目 @@ -359,6 +359,7 @@ |100332 | 最长不含重复字符的子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | |100334 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chou-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/chou-shu-lcof/) | Medium | +|100338 | 构建乘积数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gou-jian-cheng-ji-shu-zu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof/) | Medium | |100339 | n个骰子的点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nge-tou-zi-de-dian-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/nge-tou-zi-de-dian-shu-lcof/) | Medium | |100341 | 扑克牌中的顺子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bu-ke-pai-zhong-de-shun-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof/) | Easy | |100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | From d4702e8993d2dcda25da512ce305f14a3ca6823c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 24 Aug 2022 16:09:42 +0800 Subject: [PATCH 0636/1556] src/bin/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof.rs --- ...u-chuan-zhuan-huan-cheng-zheng-shu-lcof.rs | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/bin/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof.rs diff --git a/src/bin/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof.rs b/src/bin/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof.rs new file mode 100644 index 00000000..afd02b06 --- /dev/null +++ b/src/bin/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof.rs @@ -0,0 +1,63 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn str_to_int(str: String) -> i32 { + let mut r = 0i32; + let mut start = false; // 是否开始遍历 + let mut sign = 1; // 符号位 + + for &i in str.as_bytes() { + match i { + b'-' | b'+' => { + if start { + break; + } else { + sign = if i == b'-' { -1 } else { 1 }; + start = true; + } + } + b'0'..=b'9' => { + if !start { + start = true; + } + + let (r1, is_overflow) = r.overflowing_mul(10); + + if is_overflow { + if sign == 1 { + r = std::i32::MAX; + } else { + r = std::i32::MIN; + } + break; + } + + let (r1, is_overflow) = r.overflowing_add((i - b'0') as i32 * sign); + + if is_overflow { + if sign == 1 { + r = std::i32::MAX; + } else { + r = std::i32::MIN; + } + break; + } + + r = r1; + } + b' ' => { + if start { + break; + } + } + _ => break, + } + } + + r + } +} From 7af0c9a143b85bff080a0994c696860237120c1e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 24 Aug 2022 16:09:43 +0800 Subject: [PATCH 0637/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5955f1e6..573cc9da 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 363 | 166 | 187 | 10 | +| 364 | 166 | 188 | 10 | ### 题目 @@ -361,6 +361,7 @@ |100334 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chou-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/chou-shu-lcof/) | Medium | |100338 | 构建乘积数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gou-jian-cheng-ji-shu-zu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof/) | Medium | |100339 | n个骰子的点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nge-tou-zi-de-dian-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/nge-tou-zi-de-dian-shu-lcof/) | Medium | +|100340 | 把字符串转换成整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof/) | Medium | |100341 | 扑克牌中的顺子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bu-ke-pai-zhong-de-shun-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof/) | Easy | |100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | |100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | From 05d363cc99eede699094d9f4d670b5e70094cbe2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 25 Aug 2022 13:59:15 +0800 Subject: [PATCH 0638/1556] src/bin/dui-lie-de-zui-da-zhi-lcof.rs --- src/bin/dui-lie-de-zui-da-zhi-lcof.rs | 63 +++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/bin/dui-lie-de-zui-da-zhi-lcof.rs diff --git a/src/bin/dui-lie-de-zui-da-zhi-lcof.rs b/src/bin/dui-lie-de-zui-da-zhi-lcof.rs new file mode 100644 index 00000000..d0f7e526 --- /dev/null +++ b/src/bin/dui-lie-de-zui-da-zhi-lcof.rs @@ -0,0 +1,63 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +struct MaxQueue { + queue: Vec, + deque: Vec, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl MaxQueue { + fn new() -> Self { + MaxQueue { + queue: vec![], + deque: vec![], + } + } + + fn max_value(&self) -> i32 { + self.deque.first().map(|x| *x).unwrap_or(-1) + } + + fn push_back(&mut self, value: i32) { + while !self.deque.is_empty() { + if self.deque[self.deque.len() - 1] >= value { + break; + } + + self.deque.pop(); + } + + self.deque.push(value); + self.queue.push(value); + } + + fn pop_front(&mut self) -> i32 { + if self.deque.is_empty() { + return -1; + } + + let v = self.queue[0]; + self.queue = self.queue[1..].to_vec(); + + if v == self.deque[0] { + self.deque = self.deque[1..].to_vec(); + } + + v + } +} + +// /** +// * Your MaxQueue object will be instantiated and called as such: +// * let obj = MaxQueue::new(); +// * let ret_1: i32 = obj.max_value(); +// * obj.push_back(value); +// * let ret_3: i32 = obj.pop_front(); +// */ From 836cec16c98a4352b7a71181da65ea1657e02076 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 25 Aug 2022 13:59:16 +0800 Subject: [PATCH 0639/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 573cc9da..ac0c9cfa 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 364 | 166 | 188 | 10 | +| 365 | 166 | 189 | 10 | ### 题目 @@ -359,6 +359,7 @@ |100332 | 最长不含重复字符的子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | |100334 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chou-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/chou-shu-lcof/) | Medium | +|100337 | 队列的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dui-lie-de-zui-da-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof/) | Medium | |100338 | 构建乘积数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gou-jian-cheng-ji-shu-zu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof/) | Medium | |100339 | n个骰子的点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nge-tou-zi-de-dian-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/nge-tou-zi-de-dian-shu-lcof/) | Medium | |100340 | 把字符串转换成整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof/) | Medium | From 6867b25553228c017c6c6f34c90f54f8717ace94 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 26 Aug 2022 10:28:06 +0800 Subject: [PATCH 0640/1556] src/bin/fan-zhuan-dan-ci-shun-xu-lcof.rs --- src/bin/fan-zhuan-dan-ci-shun-xu-lcof.rs | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/bin/fan-zhuan-dan-ci-shun-xu-lcof.rs diff --git a/src/bin/fan-zhuan-dan-ci-shun-xu-lcof.rs b/src/bin/fan-zhuan-dan-ci-shun-xu-lcof.rs new file mode 100644 index 00000000..53d366ce --- /dev/null +++ b/src/bin/fan-zhuan-dan-ci-shun-xu-lcof.rs @@ -0,0 +1,50 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn reverse_words(s: String) -> String { + if s.is_empty() { + return Default::default(); + } + + // 先去掉首位的空格 + let mut s = s.trim().as_bytes(); + + let mut i = s.len() - 1; + let mut new = vec![]; + + while !s.is_empty() { + match s.last() { + Some(&x) if x == b' ' => s = &s[..s.len() - 1], + _ => { + let mut i = s.len() - 1; + while let Some(&x) = s.get(i) { + if x != b' ' { + if i == 0 { + break; + } + i -= 1; + } else { + break; + } + } + + if i != 0 { + i += 1; + } + + new.extend_from_slice(&s[i..]); + new.push(b' '); + s = &s[..i]; + } + } + } + + new.pop(); + + String::from_utf8(new).unwrap() + } +} From fb73937937b5baa0b5ec9782553ef3ba898bfc79 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 26 Aug 2022 10:28:07 +0800 Subject: [PATCH 0641/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ac0c9cfa..76976da4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 365 | 166 | 189 | 10 | +| 366 | 167 | 189 | 10 | ### 题目 @@ -353,6 +353,7 @@ |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | |100327 | 礼物的最大价值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/) | Medium | +|100328 | 翻转单词顺序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fan-zhuan-dan-ci-shun-xu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof/) | Easy | |100329 | 在排序数组中查找数字 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/) | Easy | |100330 | 左旋转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zuo-xuan-zhuan-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/) | Easy | |100331 | 0~n-1中缺失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/que-shi-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/) | Easy | From 3d79410c2554966fc79fd6d738e22fc713487ceb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 26 Aug 2022 11:44:50 +0800 Subject: [PATCH 0642/1556] src/bin/er-wei-shu-zu-zhong-de-cha-zhao-lcof.rs --- .../er-wei-shu-zu-zhong-de-cha-zhao-lcof.rs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bin/er-wei-shu-zu-zhong-de-cha-zhao-lcof.rs diff --git a/src/bin/er-wei-shu-zu-zhong-de-cha-zhao-lcof.rs b/src/bin/er-wei-shu-zu-zhong-de-cha-zhao-lcof.rs new file mode 100644 index 00000000..755f28a3 --- /dev/null +++ b/src/bin/er-wei-shu-zu-zhong-de-cha-zhao-lcof.rs @@ -0,0 +1,37 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_number_in2_d_array(matrix: Vec>, target: i32) -> bool { + if matrix.is_empty() || matrix[0].is_empty() { + return false; + } + + let (mut i, mut j) = (matrix.len() - 1, 0); + + loop { + match target.cmp(&matrix[i][j]) { + std::cmp::Ordering::Equal => return true, + std::cmp::Ordering::Greater => { + if j == matrix[0].len() - 1 { + return false; + } + + j += 1; + } + std::cmp::Ordering::Less => { + if i == 0 { + return false; + } + + i -= 1; + } + } + } + + false + } +} From 6ecbbb3bc2862204c67b3f1b350211e98efe7e4b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 26 Aug 2022 11:44:51 +0800 Subject: [PATCH 0643/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 76976da4..f7e80e7a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 366 | 167 | 189 | 10 | +| 367 | 167 | 190 | 10 | ### 题目 @@ -304,6 +304,7 @@ |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | +|100276 | 二维数组中的查找 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-wei-shu-zu-zhong-de-cha-zhao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/) | Medium | |100277 | 青蛙跳台阶问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) | Easy | |100278 | 旋转数组的最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/) | Easy | |100279 | 矩阵中的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ju-zhen-zhong-de-lu-jing-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ju-zhen-zhong-de-lu-jing-lcof/) | Medium | From f525e855c072d7d70a4815b1e0a3cdfb407d1fb7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 26 Aug 2022 11:47:11 +0800 Subject: [PATCH 0644/1556] src/bin/search-a-2d-matrix-ii.rs --- src/bin/search-a-2d-matrix-ii.rs | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bin/search-a-2d-matrix-ii.rs diff --git a/src/bin/search-a-2d-matrix-ii.rs b/src/bin/search-a-2d-matrix-ii.rs new file mode 100644 index 00000000..ee05c291 --- /dev/null +++ b/src/bin/search-a-2d-matrix-ii.rs @@ -0,0 +1,37 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn search_matrix(matrix: Vec>, target: i32) -> bool { + if matrix.is_empty() || matrix[0].is_empty() { + return false; + } + + let (mut i, mut j) = (matrix.len() - 1, 0); + + loop { + match target.cmp(&matrix[i][j]) { + std::cmp::Ordering::Equal => return true, + std::cmp::Ordering::Greater => { + if j == matrix[0].len() - 1 { + return false; + } + + j += 1; + } + std::cmp::Ordering::Less => { + if i == 0 { + return false; + } + + i -= 1; + } + } + } + + false + } +} From 014498839a423583b2c18781c54df85f9d00df4a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 26 Aug 2022 11:47:11 +0800 Subject: [PATCH 0645/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f7e80e7a..03b55d5b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 367 | 167 | 190 | 10 | +| 368 | 167 | 191 | 10 | ### 题目 @@ -151,6 +151,7 @@ |234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) | Easy | |235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | Easy | |238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Medium | +|240 | 搜索二维矩阵 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix-ii/) | Medium | |242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | Easy | |257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | Easy | |258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits/) | Easy | From 011d03b4ca38e99cf545774bafc9ca484b911a7f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 27 Aug 2022 11:54:41 +0800 Subject: [PATCH 0646/1556] src/bin/biao-shi-shu-zhi-de-zi-fu-chuan-lcof.rs --- .../biao-shi-shu-zhi-de-zi-fu-chuan-lcof.rs | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 src/bin/biao-shi-shu-zhi-de-zi-fu-chuan-lcof.rs diff --git a/src/bin/biao-shi-shu-zhi-de-zi-fu-chuan-lcof.rs b/src/bin/biao-shi-shu-zhi-de-zi-fu-chuan-lcof.rs new file mode 100644 index 00000000..2f3d5ba5 --- /dev/null +++ b/src/bin/biao-shi-shu-zhi-de-zi-fu-chuan-lcof.rs @@ -0,0 +1,121 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +enum Status { + Start, + PreBlank, // 前空格 + Sign, // 符号位 + Integer, // 数字 + PointWithInteger, // 前面带数字的小数点 + PointWithoutInteger, // 前面不带数字的小数点 + IntegerAfterPoint, // 小数点后面的数字 + E, // E or e + IntegerAfterE, // E后面的数字 + SignAfterE, // E 后面的符号 + LastInteger, // 最后的数字 + PostBlank, // 后空格 + Invalid, // 无效的 +} + +impl Status { + fn new() -> Status { + Status::Start + } + + fn transform(&mut self, x: u8) { + use Status::*; + + match self { + Start => match x { + b' ' => *self = PreBlank, + b'+' | b'-' => *self = Sign, + b'0'..=b'9' => *self = Integer, + b'.' => *self = PointWithoutInteger, + _ => *self = Invalid, + }, + PreBlank => match x { + b' ' => *self = PreBlank, + b'+' | b'-' => *self = Sign, + b'0'..=b'9' => *self = Integer, + b'.' => *self = PointWithoutInteger, + _ => *self = Invalid, + }, + Sign => match x { + b'0'..=b'9' => *self = Integer, + b'.' => *self = PointWithoutInteger, + _ => *self = Invalid, + }, + Integer => match x { + b' ' => *self = PostBlank, + b'0'..=b'9' => *self = Integer, + b'.' => *self = PointWithInteger, + b'E' | b'e' => *self = E, + _ => *self = Invalid, + }, + PointWithInteger => match x { + b' ' => *self = PostBlank, + b'0'..=b'9' => *self = IntegerAfterPoint, + b'E' | b'e' => *self = E, + _ => *self = Invalid, + }, + PointWithoutInteger => match x { + b'0'..=b'9' => *self = IntegerAfterPoint, + _ => *self = Invalid, + }, + IntegerAfterPoint => match x { + b' ' => *self = PostBlank, + b'0'..=b'9' => *self = IntegerAfterPoint, + b'E' | b'e' => *self = E, + _ => *self = Invalid, + }, + E => match x { + b'0'..=b'9' => *self = IntegerAfterE, + b'+' | b'-' => *self = SignAfterE, + _ => *self = Invalid, + }, + IntegerAfterE => match x { + b' ' => *self = PostBlank, + b'0'..=b'9' => *self = IntegerAfterE, + b'+' | b'-' => *self = SignAfterE, + _ => *self = Invalid, + }, + SignAfterE => match x { + b'0'..=b'9' => *self = LastInteger, + _ => *self = Invalid, + }, + LastInteger => match x { + b' ' => *self = PostBlank, + b'0'..=b'9' => *self = LastInteger, + _ => *self = Invalid, + }, + PostBlank => match x { + b' ' => *self = PostBlank, + _ => *self = Invalid, + }, + Invalid => {} + } + } + + fn is_valid(&self) -> bool { + use Status::*; + match self { + Integer | PointWithInteger | IntegerAfterPoint | LastInteger | PostBlank + | IntegerAfterE => true, + _ => false, + } + } +} + +struct Solution; + +impl Solution { + pub fn is_number(s: String) -> bool { + let mut status = Status::new(); + for &i in s.as_bytes() { + status.transform(i); + } + + status.is_valid() + } +} From df4fd43737ffcb67ad8ea9b0c2fb2194af4d7fab Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 27 Aug 2022 11:54:41 +0800 Subject: [PATCH 0647/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 03b55d5b..76cbceb1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 368 | 167 | 191 | 10 | +| 369 | 167 | 192 | 10 | ### 题目 @@ -319,6 +319,7 @@ |100287 | 树的子结构 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-de-zi-jie-gou-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof/) | Medium | |100288 | 二叉树的镜像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-jing-xiang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof/) | Easy | |100289 | 对称的二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dui-cheng-de-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof/) | Easy | +|100290 | 表示数值的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/biao-shi-shu-zhi-de-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/biao-shi-shu-zhi-de-zi-fu-chuan-lcof/) | Medium | |100291 | 调整数组顺序使奇数位于偶数前面 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/) | Easy | |100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | |100293 | 顺时针打印矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shun-shi-zhen-da-yin-ju-zhen-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shun-shi-zhen-da-yin-ju-zhen-lcof/) | Easy | From 0eb3f24591cf9746ab9d84d849dd0a214c7f8661 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 29 Aug 2022 10:26:10 +0800 Subject: [PATCH 0648/1556] src/bin/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof.rs --- ...heng-shu-zhong-1chu-xian-de-ci-shu-lcof.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/bin/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof.rs diff --git a/src/bin/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof.rs b/src/bin/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof.rs new file mode 100644 index 00000000..a2825b47 --- /dev/null +++ b/src/bin/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// https://leetcode.cn/problems/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof/solution/mian-shi-ti-43-1n-zheng-shu-zhong-1-chu-xian-de-2/ + /// 找规律 + pub fn count_digit_one(n: i32) -> i32 { + let (mut n, mut r) = (n, 0); + let mut digit = 1; // 位数 + let mut low = 0; + while n > 0 { + let mut cur = n % 10; + let mut high = n / 10; + match cur { + 0 => r += (high * digit), + 1 => r += (high * digit + low + 1), + 2..=9 => r += ((high + 1) * digit), + _ => unreachable!(), + } + low += (cur * digit); + digit *= 10; + n = (n - cur) / 10; + } + + r + } +} From 8321eebf7a254a3985326421eca71fe25417021b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 29 Aug 2022 10:26:10 +0800 Subject: [PATCH 0649/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 76cbceb1..ca813a06 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 369 | 167 | 192 | 10 | +| 370 | 167 | 192 | 11 | ### 题目 @@ -337,6 +337,7 @@ |100306 | 栈的压入、弹出序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) | Medium | |100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | |100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | +|100309 | 1~n 整数中 1 出现的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof/) | Hard | |100310 | 数组中出现次数超过一半的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof/) | Easy | |100311 | 从上到下打印二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) | Medium | |100312 | 从上到下打印二叉树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/) | Easy | From 5afc97178b6b255f00df362361ea4f871fa0cbae Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 29 Aug 2022 21:52:59 +0800 Subject: [PATCH 0650/1556] src/bin/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs --- ...n-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/bin/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs diff --git a/src/bin/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs b/src/bin/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs new file mode 100644 index 00000000..4e6359db --- /dev/null +++ b/src/bin/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs @@ -0,0 +1,18 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 常规解法,使用vec作为列表 + pub fn last_remaining(n: i32, m: i32) -> i32 { + let mut v = 0; + + for i in 2..n + 1 { + v = (v + m) % i; + } + + v + } +} From 999c25fb504283b8f9b463ee1c7d075b0b5efb0d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 29 Aug 2022 21:53:00 +0800 Subject: [PATCH 0651/1556] README.md --- README.md | 3 ++- ...n-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ca813a06..72107206 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 370 | 167 | 192 | 11 | +| 371 | 168 | 192 | 11 | ### 题目 @@ -371,6 +371,7 @@ |100341 | 扑克牌中的顺子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bu-ke-pai-zhong-de-shun-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof/) | Easy | |100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | |100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | +|100343 | 圆圈中最后剩下的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/) | Easy | |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | |100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | |100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | diff --git a/src/bin/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs b/src/bin/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs index 4e6359db..695835ff 100644 --- a/src/bin/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs +++ b/src/bin/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs @@ -5,7 +5,10 @@ fn main() {} struct Solution; impl Solution { - /// 常规解法,使用vec作为列表 + /// 倒推法 + /// n等于1时,一定返回下标为0的 + /// 最后一个元素的下标一定会一直往前移动m位,即f(n-1)的下标为f(n) - m,因此f(n) = f(n-1) + m + /// 又因为会溢出,所以需要对n取模,所以f(n) = (f(n-1) + m) % n pub fn last_remaining(n: i32, m: i32) -> i32 { let mut v = 0; @@ -15,4 +18,17 @@ impl Solution { v } + + pub fn last_remaining_1(n: i32, m: i32) -> i32 { + let mut v = (0..n).collect::>(); + + let mut index = 0; // 开始的索引,开始从0计数 + while v.len() > 1 { + index = (index + m as usize - 1) % v.len(); + + v.remove(index); + } + + v[0] + } } From 2f0589ef28f74c0b9a3560ef88563460753f462f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 31 Aug 2022 10:54:12 +0800 Subject: [PATCH 0652/1556] src/bin/maximum-xor-for-each-query.rs --- src/bin/maximum-xor-for-each-query.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/maximum-xor-for-each-query.rs diff --git a/src/bin/maximum-xor-for-each-query.rs b/src/bin/maximum-xor-for-each-query.rs new file mode 100644 index 00000000..36585eee --- /dev/null +++ b/src/bin/maximum-xor-for-each-query.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn get_maximum_xor(nums: Vec, maximum_bit: i32) -> Vec { + let mut r = vec![0; nums.len()]; + let max = (1 << maximum_bit) - 1; + let len = r.len(); + let mut current = 0; + for (i, v) in nums.into_iter().enumerate() { + current ^= v; + r[len - 1 - i] = (!current) & max; + } + + r + } +} From 17473e4aa6f1ff47dfaab76024735547edfcafbd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 31 Aug 2022 10:54:13 +0800 Subject: [PATCH 0653/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 72107206..f79cd789 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 371 | 168 | 192 | 11 | +| 372 | 168 | 193 | 11 | ### 题目 @@ -298,6 +298,7 @@ |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | |1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | +|1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | From 9c42efb4e96d59e9be161ab630a3c3ca812af25d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 1 Sep 2022 10:32:28 +0800 Subject: [PATCH 0654/1556] feat(sort): add quick_sort --- Cargo.lock | 4 ++++ Cargo.toml | 2 ++ sort/Cargo.toml | 8 ++++++++ sort/src/lib.rs | 19 +++++++++++++++++++ sort/src/quick.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 sort/Cargo.toml create mode 100644 sort/src/lib.rs create mode 100644 sort/src/quick.rs diff --git a/Cargo.lock b/Cargo.lock index 694d0479..eca4603f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1156,6 +1156,10 @@ dependencies = [ "winapi", ] +[[package]] +name = "sort" +version = "0.1.0" + [[package]] name = "strsim" version = "0.10.0" diff --git a/Cargo.toml b/Cargo.toml index cb33a606..74020d0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,8 @@ authors = ["bestgopher <84328409@qq.com>"] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[workspace] +members = ["./sort"] [dependencies] git2 = "0.14.4" diff --git a/sort/Cargo.toml b/sort/Cargo.toml new file mode 100644 index 00000000..71a29e68 --- /dev/null +++ b/sort/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "sort" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/sort/src/lib.rs b/sort/src/lib.rs new file mode 100644 index 00000000..c466b70f --- /dev/null +++ b/sort/src/lib.rs @@ -0,0 +1,19 @@ +pub mod quick; + +pub use quick::quick_sort; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_sort() { + let s = "The Waker type allows for a loose coupling between the reactor-part and the executor-part of a runtime"; + let mut m: Vec = s.split(" ").map(|x| x.to_string()).collect(); + let mut m1 = m.clone(); + quick_sort(&mut m1); + m.sort(); + + assert_eq!(m, m1); + } +} diff --git a/sort/src/quick.rs b/sort/src/quick.rs new file mode 100644 index 00000000..55d53c0a --- /dev/null +++ b/sort/src/quick.rs @@ -0,0 +1,46 @@ +/// 原地排序的快速排序实现 +/// 步骤: +/// 1.指定一个基准值p(p为s[begin]), begin为0,end为len(s)-1 +/// 2.首先从后往前遍历,如果遍历的元素大于基准值,则继续往前遍历, end = end-1 +/// 3.如果从后往前遍历时的值小于基准值,begin的值赋值为s[end], begin = begin + 1 +/// 4.然后从前往后遍历,遍历值小于或者等于基准值时,继续向后遍历,begin = begin + 1 +/// 5.当遍历值大于或者等于基准值时,s[end] = s[begin] +/// 6.再次重复2-5步,直到begin == end为止 +/// 7.最后s[begin] = p +/// 8.递归快速排序以begin为分界线的两部分序列 +pub fn quick_sort(target: &mut [T]) { + if target.len() < 2 { + return; + } + + let (p, mut begin, mut end) = (target[0].clone(), 0, target.len() - 1); + + while begin < end { + while begin < end { + match p.cmp(&target[end]) { + std::cmp::Ordering::Greater => { + target[begin] = target[end].clone(); + begin += 1; + break; + } + _ => end -= 1, + } + } + + while begin < end { + match p.cmp(&target[begin]) { + std::cmp::Ordering::Less => { + target[end] = target[begin].clone(); + end -= 1; + break; + } + _ => begin += 1, + } + } + } + + target[begin] = p; + + quick_sort(&mut target[..begin]); + quick_sort(&mut target[begin + 1..]); +} From 8623c83bd3baf224e9ca88f0a52dc4adcd0a32bc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 3 Sep 2022 11:25:13 +0800 Subject: [PATCH 0655/1556] src/bin/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof.rs --- ...u-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/bin/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof.rs diff --git a/src/bin/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof.rs b/src/bin/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof.rs new file mode 100644 index 00000000..d3ce935b --- /dev/null +++ b/src/bin/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof.rs @@ -0,0 +1,17 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn add(a: i32, b: i32) -> i32 { + let (mut a, mut b) = (a, b); + while b != 0 { + let c = a ^ b; + b = (a & b) << 1; + a = c; + } + a + } +} From 909aaf103b38b8320332107210b3786b1110f9ce Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 3 Sep 2022 11:25:13 +0800 Subject: [PATCH 0656/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f79cd789..72f2ff51 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 372 | 168 | 193 | 11 | +| 373 | 169 | 193 | 11 | ### 题目 @@ -365,6 +365,7 @@ |100332 | 最长不含重复字符的子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) | Medium | |100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | |100334 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chou-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/chou-shu-lcof/) | Medium | +|100335 | 不用加减乘除做加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/) | Easy | |100337 | 队列的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dui-lie-de-zui-da-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof/) | Medium | |100338 | 构建乘积数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gou-jian-cheng-ji-shu-zu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof/) | Medium | |100339 | n个骰子的点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nge-tou-zi-de-dian-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/nge-tou-zi-de-dian-shu-lcof/) | Medium | From 3341b060e2eaa23d86bfd2bd2bf064a1f89142e4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 6 Sep 2022 13:41:36 +0800 Subject: [PATCH 0657/1556] src/bin/reverse-vowels-of-a-string.rs --- src/bin/reverse-vowels-of-a-string.rs | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/bin/reverse-vowels-of-a-string.rs diff --git a/src/bin/reverse-vowels-of-a-string.rs b/src/bin/reverse-vowels-of-a-string.rs new file mode 100644 index 00000000..0cefe163 --- /dev/null +++ b/src/bin/reverse-vowels-of-a-string.rs @@ -0,0 +1,39 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn reverse_vowels(s: String) -> String { + let mut s = s; + let mut bytes = unsafe { s.as_bytes_mut() }; + + let (mut start, mut end) = (0, bytes.len() - 1); + + while start < end { + match bytes[start] { + b'A' | b'E' | b'I' | b'O' | b'U' | b'a' | b'e' | b'i' | b'o' | b'u' => {} + _ => { + start += 1; + continue; + } + } + + match bytes[end] { + b'A' | b'E' | b'I' | b'O' | b'U' | b'a' | b'e' | b'i' | b'o' | b'u' => {} + _ => { + end -= 1; + continue; + } + } + + bytes.swap(start, end); + + start += 1; + end -= 1; + } + + s + } +} From d8e90349b38a3dc9857f5ed4c1e11c3ab73f9a6d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 6 Sep 2022 13:41:39 +0800 Subject: [PATCH 0658/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 72f2ff51..14da69cf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 373 | 169 | 193 | 11 | +| 374 | 170 | 193 | 11 | ### 题目 @@ -170,6 +170,7 @@ |322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | |326 | 3 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | |344 | 反转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string/) | Easy | +|345 | 反转字符串中的元音字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-vowels-of-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-vowels-of-a-string/) | Easy | |349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | |350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | |357 | 统计各位数字都不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | From 0ade262f41a3762b7b850788d5f5e3c381e069ec Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 11 Sep 2022 16:51:43 +0800 Subject: [PATCH 0659/1556] src/bin/matrix-diagonal-sum.rs --- src/bin/matrix-diagonal-sum.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/bin/matrix-diagonal-sum.rs diff --git a/src/bin/matrix-diagonal-sum.rs b/src/bin/matrix-diagonal-sum.rs new file mode 100644 index 00000000..61036e3f --- /dev/null +++ b/src/bin/matrix-diagonal-sum.rs @@ -0,0 +1,22 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn diagonal_sum(mat: Vec>) -> i32 { + let (mut i, mut j, mut sum) = (0, mat.len() - 1, 0); + + while i < j { + sum += mat[i][i]; + sum += mat[i][j]; + sum += mat[j][i]; + sum += mat[j][j]; + i += 1; + j -= 1; + } + sum += (mat[i][i] * (mat.len() as i32 & 1)); + sum + } +} From e34089a0e503821021c79a0e38be00cf616f81a8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 11 Sep 2022 16:51:43 +0800 Subject: [PATCH 0660/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 14da69cf..5932f6d5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 374 | 170 | 193 | 11 | +| 375 | 171 | 193 | 11 | ### 题目 @@ -295,6 +295,7 @@ |1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | Easy | |1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | |1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | +|1677 | 矩阵对角线元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/matrix-diagonal-sum.rs) | [leetcode](https://leetcode-cn.com/problems/matrix-diagonal-sum/) | Easy | |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | From 1d76e3d401008ba28a5cc5d9ba079f6aa8d4f07a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 16 Sep 2022 18:36:55 +0800 Subject: [PATCH 0661/1556] src/bin/target-sum.rs --- src/bin/target-sum.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/target-sum.rs diff --git a/src/bin/target-sum.rs b/src/bin/target-sum.rs new file mode 100644 index 00000000..3df63c13 --- /dev/null +++ b/src/bin/target-sum.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_target_sum_ways(nums: Vec, target: i32) -> i32 { + // Self::calc(&nums, target) + Self::calc(&nums, target) + } + + pub fn calc(nums: &[i32], target: i32) -> i32 { + if nums.is_empty() { + if target == 0 { + return 1; + } else { + return 0; + } + } + + if nums[0] == 0 { + Self::calc(&nums[1..], target - nums[0]) * 2 + } else { + Self::calc(&nums[1..], target - nums[0]) + Self::calc(&nums[1..], target + nums[0]) + } + } From 0f588d3b4794633a8c30e7e7959d45876f93af21 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 16 Sep 2022 18:36:55 +0800 Subject: [PATCH 0662/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5932f6d5..3c8dbfd3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 375 | 171 | 193 | 11 | +| 376 | 171 | 194 | 11 | ### 题目 @@ -207,6 +207,7 @@ |476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | +|494 | 目标和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/target-sum/) | Medium | |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | |504 | 七进制数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/base-7.rs) | [leetcode](https://leetcode-cn.com/problems/base-7/) | Easy | |507 | 完美数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-number.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-number/) | Easy | From 6e6230645891487de866623b3eea39e4373eb175 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 20 Sep 2022 22:55:20 +0800 Subject: [PATCH 0663/1556] src/bin/string-rotation-lcci.rs --- src/bin/string-rotation-lcci.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/string-rotation-lcci.rs diff --git a/src/bin/string-rotation-lcci.rs b/src/bin/string-rotation-lcci.rs new file mode 100644 index 00000000..745fb833 --- /dev/null +++ b/src/bin/string-rotation-lcci.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::ops::Add; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn is_fliped_string(s1: String, s2: String) -> bool { + use std::ops::Add; + + if s1.len() != s2.len() { + return false; + } + + let mut new_s1 = s1.clone(); + new_s1.add(s1.as_str()).contains(&s2) + } +} From b5fa0aa963d1d193bd0d6234601ab043808c0a19 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 20 Sep 2022 22:55:20 +0800 Subject: [PATCH 0664/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c8dbfd3..52edf37c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 376 | 171 | 194 | 11 | +| 377 | 172 | 194 | 11 | ### 题目 @@ -306,6 +306,7 @@ |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | +|100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | From 6b46ab3507d7515a51ac838add3d80e7e733c812 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 24 Sep 2022 22:55:15 +0800 Subject: [PATCH 0665/1556] src/bin/three-consecutive-odds.rs --- src/bin/three-consecutive-odds.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/three-consecutive-odds.rs diff --git a/src/bin/three-consecutive-odds.rs b/src/bin/three-consecutive-odds.rs new file mode 100644 index 00000000..70204fb9 --- /dev/null +++ b/src/bin/three-consecutive-odds.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn three_consecutive_odds(arr: Vec) -> bool { + let mut count = 0; + + for i in arr { + if i % 2 == 0 { + count = 0; + } else { + count += 1; + } + + if count >= 3 { + return true; + } + } + + false + } +} From 95efcc7359f838dbe397965956584cc1ae37d5ac Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 24 Sep 2022 22:55:16 +0800 Subject: [PATCH 0666/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 52edf37c..45e2d3b1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 377 | 172 | 194 | 11 | +| 378 | 173 | 194 | 11 | ### 题目 @@ -269,6 +269,7 @@ |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | |1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | +|1293 | 存在连续三个奇数的数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/three-consecutive-odds.rs) | [leetcode](https://leetcode-cn.com/problems/three-consecutive-odds/) | Easy | |1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | |1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | From 203941777b21939460998e8bfe345d77965329fe Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 29 Sep 2022 21:18:09 +0800 Subject: [PATCH 0667/1556] src/bin/minimum-index-sum-of-two-lists.rs --- src/bin/minimum-index-sum-of-two-lists.rs | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/minimum-index-sum-of-two-lists.rs diff --git a/src/bin/minimum-index-sum-of-two-lists.rs b/src/bin/minimum-index-sum-of-two-lists.rs new file mode 100644 index 00000000..2a982e33 --- /dev/null +++ b/src/bin/minimum-index-sum-of-two-lists.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_restaurant(list1: Vec, list2: Vec) -> Vec { + let m = list1 + .into_iter() + .enumerate() + .map(|x| (x.1, x.0)) + .collect::>(); + + let mut data = vec![]; + let mut index = usize::MAX; + + for (i, v) in list2.into_iter().enumerate() { + if i > index { + break; + } + + if let Some(&x) = m.get(&v) { + if i + x <= index { + if i + x < index { + data.clear(); + } + data.push(v); + index = i + x; + } + } + } + + data + } +} From c4d23d9f1172348273e94898c166e1457a698d0c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 29 Sep 2022 21:18:10 +0800 Subject: [PATCH 0668/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 45e2d3b1..82069dba 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 378 | 173 | 194 | 11 | +| 379 | 174 | 194 | 11 | ### 题目 @@ -222,6 +222,7 @@ |560 | 和为 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | |565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | |594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | +|599 | 两个列表的最小索引总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-index-sum-of-two-lists.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-index-sum-of-two-lists/) | Easy | |605 | 种花问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/can-place-flowers.rs) | [leetcode](https://leetcode-cn.com/problems/can-place-flowers/) | Easy | |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | |623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | From 0af9ef8c385d7172ca81d6e5bbf602a2d74cc556 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 26 Jan 2023 11:44:47 +0800 Subject: [PATCH 0669/1556] src/bin/longest-palindromic-substring.rs --- src/bin/longest-palindromic-substring.rs | 51 ++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/bin/longest-palindromic-substring.rs diff --git a/src/bin/longest-palindromic-substring.rs b/src/bin/longest-palindromic-substring.rs new file mode 100644 index 00000000..88afbd58 --- /dev/null +++ b/src/bin/longest-palindromic-substring.rs @@ -0,0 +1,51 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::f32::consts::E; + +fn main() { + assert_eq!( + Solution::longest_palindrome("aaaa".into()), + "aaaa".to_string() + ); +} + +struct Solution; + +impl Solution { + pub fn longest_palindrome(s: String) -> String { + let length = s.len(); + if length == 1 { + return s; + } + + let bytes = s.as_bytes(); + + let mut v: Vec> = (0..length) + .map(|x| (0..length).map(|y| x == y).collect::>()) + .collect(); + + let (mut start, mut end) = (0, 0); + + for i in 1..length { + for start1 in 0..length { + let end1 = start1 + i; + if end1 >= length { + break; + } + + if i == 1 { + v[start1][end1] = bytes[start1] == bytes[end1]; + } else { + v[start1][end1] = bytes[start1] == bytes[end1] && v[start1 + 1][end1 - 1]; + } + + if end1 - start1 >= end - start { + start = start1; + end = end1; + } + } + } + + s[start..=end].to_owned() + } +} From eae91fe5ba14782e158578efc727ffc423939aa0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 26 Jan 2023 11:44:47 +0800 Subject: [PATCH 0670/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 82069dba..1a43981e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 379 | 174 | 194 | 11 | +| 380 | 174 | 195 | 11 | ### 题目 @@ -12,6 +12,7 @@ |2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | Medium | |3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | Medium | |4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Hard | +|5 | 最长回文子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindromic-substring.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindromic-substring/) | Medium | |6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | Medium | |7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | Medium | |8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | Medium | From 24a5796886b1c3f8b8f17ae778640395d556d82e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 26 Jan 2023 15:08:44 +0800 Subject: [PATCH 0671/1556] src/bin/generate-parentheses.rs --- src/bin/generate-parentheses.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/generate-parentheses.rs diff --git a/src/bin/generate-parentheses.rs b/src/bin/generate-parentheses.rs new file mode 100644 index 00000000..4a3e9aec --- /dev/null +++ b/src/bin/generate-parentheses.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn generate_parenthesis(n: i32) -> Vec { + if n == 1 { + return vec!["()".into()]; + } + let mut v = std::collections::HashSet::new(); + for i in Self::generate_parenthesis(n - 1) { + for j in 0..i.len() { + let mut s = String::new(); + s.push_str(&i[..j]); + s.push_str("()"); + s.push_str(&i[j..]); + v.insert(s); + } + } + + v.into_iter().collect() + } +} From 15fc6ca6f3d6d98c6ed4c4e2932d6e994148c2be Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 26 Jan 2023 15:08:45 +0800 Subject: [PATCH 0672/1556] src/bin/target-sum.rs --- src/bin/target-sum.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/target-sum.rs b/src/bin/target-sum.rs index 3df63c13..ef2995ac 100644 --- a/src/bin/target-sum.rs +++ b/src/bin/target-sum.rs @@ -27,3 +27,4 @@ impl Solution { Self::calc(&nums[1..], target - nums[0]) + Self::calc(&nums[1..], target + nums[0]) } } +} From af49a0c96688917309c46c65c72ec456e82860c8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 26 Jan 2023 15:08:46 +0800 Subject: [PATCH 0673/1556] README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a43981e..347508b8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 380 | 174 | 195 | 11 | +| 382 | 174 | 197 | 11 | ### 题目 @@ -28,6 +28,7 @@ |19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Medium | |20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | Easy | |21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | Easy | +|22 | 括号生成 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/generate-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/generate-parentheses/) | Medium | |23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Hard | |24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | Medium | |25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Hard | @@ -209,6 +210,7 @@ |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | |494 | 目标和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/target-sum/) | Medium | +|494 | 目标和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/target-sum/) | Medium | |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | |504 | 七进制数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/base-7.rs) | [leetcode](https://leetcode-cn.com/problems/base-7/) | Easy | |507 | 完美数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-number.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-number/) | Easy | From 36ac43ba0183f5859bfcc0b5007977badd1b7ce8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 28 Jan 2023 13:49:23 +0800 Subject: [PATCH 0674/1556] src/bin/trapping-rain-water.rs --- src/bin/trapping-rain-water.rs | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/bin/trapping-rain-water.rs diff --git a/src/bin/trapping-rain-water.rs b/src/bin/trapping-rain-water.rs new file mode 100644 index 00000000..bdaf843f --- /dev/null +++ b/src/bin/trapping-rain-water.rs @@ -0,0 +1,43 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::trap(vec![0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]), 6); +} + +struct Solution; + +impl Solution { + pub fn trap(height: Vec) -> i32 { + let mut max_left = vec![0; height.len()]; // 左边的最大值 + + for (i, &v) in height.iter().enumerate() { + if i == 0 { + max_left[i] = v; + } else { + max_left[i] = v.max(max_left[i - 1]); + } + } + + let mut max_right = vec![0; height.len()]; + + for (i, &v) in height.iter().rev().enumerate() { + let index = max_right.len() - i - 1; + if i == 0 { + max_right[index] = v; + } else { + max_right[index] = v.max(max_right[index + 1]); + } + } + + let mut ans = 0; + + for (i, &v) in height.iter().enumerate() { + let min = max_left[i].min(max_right[i]); + if v < min { + ans += min - v; + } + } + + ans + } +} From 5519cd73277a502eb50c440a3977ff9180982920 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 28 Jan 2023 13:49:24 +0800 Subject: [PATCH 0675/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 347508b8..644ea6e5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 382 | 174 | 197 | 11 | +| 383 | 174 | 197 | 12 | ### 题目 @@ -43,6 +43,7 @@ |38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Medium | |39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | |41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Hard | +|42 | 接雨水 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/trapping-rain-water.rs) | [leetcode](https://leetcode-cn.com/problems/trapping-rain-water/) | Hard | |43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Medium | |45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Medium | |46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Medium | From fe71ea1a74b625a1427ef1c00e971993a52a9f5d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 28 Jan 2023 14:55:54 +0800 Subject: [PATCH 0676/1556] src/bin/trapping-rain-water.rs --- src/bin/trapping-rain-water.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/bin/trapping-rain-water.rs b/src/bin/trapping-rain-water.rs index bdaf843f..f1fdf672 100644 --- a/src/bin/trapping-rain-water.rs +++ b/src/bin/trapping-rain-water.rs @@ -2,6 +2,10 @@ fn main() { assert_eq!(Solution::trap(vec![0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]), 6); + assert_eq!( + Solution::trap_stack(vec![0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]), + 6 + ); } struct Solution; @@ -40,4 +44,26 @@ impl Solution { ans } + + pub fn trap_stack(height: Vec) -> i32 { + let mut ans = 0; + let mut stack = vec![]; + + for i in 0..height.len() { + while !stack.is_empty() && height[stack[stack.len() - 1]] < height[i] { + let top = stack.pop().unwrap(); + if stack.is_empty() { + break; + } + + let &l = stack.last().unwrap(); + let h = height[i].min(height[l]) - height[top]; + ans += (i as i32 - l as i32 - 1) * h; + } + + stack.push(i); + } + + ans + } } From 9feb251dfc9d9281cf0a94d350060a6592de1996 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 28 Jan 2023 14:55:54 +0800 Subject: [PATCH 0677/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 644ea6e5..12ebb853 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 383 | 174 | 197 | 12 | +| 384 | 174 | 197 | 13 | ### 题目 @@ -44,6 +44,7 @@ |39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | |41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Hard | |42 | 接雨水 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/trapping-rain-water.rs) | [leetcode](https://leetcode-cn.com/problems/trapping-rain-water/) | Hard | +|42 | 接雨水 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/trapping-rain-water.rs) | [leetcode](https://leetcode-cn.com/problems/trapping-rain-water/) | Hard | |43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Medium | |45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Medium | |46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Medium | From fa3bc6eb7af8b84dfaf6f18948d084863a332699 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 29 Jan 2023 10:42:55 +0800 Subject: [PATCH 0678/1556] src/bin/edit-distance.rs --- src/bin/edit-distance.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/bin/edit-distance.rs diff --git a/src/bin/edit-distance.rs b/src/bin/edit-distance.rs new file mode 100644 index 00000000..1e3bfc35 --- /dev/null +++ b/src/bin/edit-distance.rs @@ -0,0 +1,39 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::min_distance("horse".into(), "ros".into()), 3); +} + +struct Solution; + +impl Solution { + pub fn min_distance(word1: String, word2: String) -> i32 { + let m = word1.len(); + let n = word2.len(); + + let (b1, b2) = (word1.as_bytes(), word2.as_bytes()); + + let mut d = vec![vec![0; n + 1]; m + 1]; + + for i in 1..=n { + d[0][i] = d[0][i - 1] + 1; + } + + for i in 1..=m { + d[i][0] = d[i - 1][0] + 1; + } + + for i in 1..=m { + for j in 1..=n { + let mut l = d[i - 1][j - 1]; + if b1[i - 1] == b2[j - 1] { + l -= 1; + } + + d[i][j] = d[i][j - 1].min(l).min(d[i - 1][j]) + 1; + } + } + + d[m][n] + } +} From adb339d28cc88494bddface696d6926b8085c15b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 29 Jan 2023 10:42:56 +0800 Subject: [PATCH 0679/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 12ebb853..cc32ef5d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 384 | 174 | 197 | 13 | +| 385 | 174 | 197 | 14 | ### 题目 @@ -67,6 +67,7 @@ |69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | Easy | |70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | Easy | |71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | Medium | +|72 | 编辑距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/edit-distance.rs) | [leetcode](https://leetcode-cn.com/problems/edit-distance/) | Hard | |73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | Medium | |74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | Medium | |75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | Medium | From 19207662421d11e8a3e1b2bb66b661b5d8abec81 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 29 Jan 2023 15:14:48 +0800 Subject: [PATCH 0680/1556] src/bin/largest-rectangle-in-histogram.rs --- src/bin/largest-rectangle-in-histogram.rs | 95 +++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/bin/largest-rectangle-in-histogram.rs diff --git a/src/bin/largest-rectangle-in-histogram.rs b/src/bin/largest-rectangle-in-histogram.rs new file mode 100644 index 00000000..a40f7ea0 --- /dev/null +++ b/src/bin/largest-rectangle-in-histogram.rs @@ -0,0 +1,95 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!( + Solution::force_largest_rectangle_area(vec![2, 1, 5, 6, 2, 3]), + 10 + ); + assert_eq!(Solution::force_largest_rectangle_area(vec![2, 4]), 4); + assert_eq!(Solution::force_largest_rectangle_area(vec![1, 1]), 2); + assert_eq!(Solution::force_largest_rectangle_area(vec![2, 1, 2]), 3); + assert_eq!(Solution::force_largest_rectangle_area(vec![5, 4, 1, 2]), 8); + + assert_eq!(Solution::largest_rectangle_area(vec![2, 1, 5, 6, 2, 3]), 10); + assert_eq!(Solution::largest_rectangle_area(vec![2, 4]), 4); + assert_eq!(Solution::largest_rectangle_area(vec![1, 1]), 2); + assert_eq!(Solution::largest_rectangle_area(vec![2, 1, 2]), 3); + assert_eq!(Solution::largest_rectangle_area(vec![5, 4, 1, 2]), 8); + assert_eq!(Solution::largest_rectangle_area(vec![4, 2, 0, 3, 2, 5]), 6); + assert_eq!( + Solution::largest_rectangle_area(vec![3, 6, 5, 7, 4, 8, 1, 0]), + 20 + ); +} + +struct Solution; + +impl Solution { + /// 暴力解法 + pub fn force_largest_rectangle_area(heights: Vec) -> i32 { + let mut ans = 0; + + for i in 0..heights.len() { + let mut left = i; + + for j in (0..i).rev() { + if heights[j] >= heights[i] { + left = j; + } else { + break; + } + } + + let mut right = i; + + for j in i..heights.len() { + if heights[j] >= heights[i] { + right = j; + } else { + break; + } + } + + ans = ans.max((right - left + 1) as i32 * heights[i]) + } + + ans + } + + pub fn largest_rectangle_area(heights: Vec) -> i32 { + let len = heights.len(); + if len == 1 { + return heights[0]; + } + + let mut stack: Vec = vec![]; + let mut ans = 0; + + // 循环便利整个heights + for i in 0..len { + while !stack.is_empty() && heights[stack[stack.len() - 1]] > heights[i] { + let h = stack.pop().unwrap(); + if !stack.is_empty() { + ans = ans.max(heights[h] * (i - *stack.last().unwrap_or(&0) - 1) as i32); + } else { + ans = ans.max(heights[h] * (i - *stack.last().unwrap_or(&0)) as i32); + } + } + + stack.push(i); + } + + let last = *stack.last().unwrap_or(&0); + + while !stack.is_empty() { + let h = stack.pop().unwrap(); + if stack.is_empty() { + ans = ans.max(heights[h] * len as i32); + } else { + ans = ans.max(heights[h] * (last - *stack.last().unwrap_or(&0)) as i32); + } + } + + ans + } +} From 8219f505a64c6bb68d2b0ee09a9edf60b7af11e2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 29 Jan 2023 15:14:49 +0800 Subject: [PATCH 0681/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cc32ef5d..47b2a859 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 385 | 174 | 197 | 14 | +| 386 | 174 | 197 | 15 | ### 题目 @@ -78,6 +78,7 @@ |81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | Medium | |82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | Medium | |83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | Easy | +|84 | 柱状图中最大的矩形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-rectangle-in-histogram.rs) | [leetcode](https://leetcode-cn.com/problems/largest-rectangle-in-histogram/) | Hard | |88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | Easy | |89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Medium | |91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Medium | From 2a66a6182dc1030ec0ab97926772aeee086c0acf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 29 Jan 2023 16:07:23 +0800 Subject: [PATCH 0682/1556] src/bin/maximal-rectangle.rs --- src/bin/maximal-rectangle.rs | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/bin/maximal-rectangle.rs diff --git a/src/bin/maximal-rectangle.rs b/src/bin/maximal-rectangle.rs new file mode 100644 index 00000000..d49997bb --- /dev/null +++ b/src/bin/maximal-rectangle.rs @@ -0,0 +1,51 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximal_rectangle(matrix: Vec>) -> i32 { + // 构造柱状图 + let mut v = vec![vec![]; matrix.len()]; + + for i in 0..matrix.len() { + v[i].push(0); + for j in 0..matrix[0].len() { + if matrix[i][j] == '0' { + v[i].push(0); + } else { + let value = if i == 0 { 1 } else { v[i - 1][j + 1] + 1 }; + v[i].push(value); + } + } + + v[i].push(0); + } + + let mut ans = 0; + + for v1 in v { + let len = v1.len(); + let mut stack = vec![]; + + for v2 in 0..len { + while !stack.is_empty() && v1[stack[stack.len() - 1]] >= v1[v2] { + let top = stack.pop().unwrap(); + ans = ans.max(v1[top] * (v2 - *stack.last().unwrap_or(&0) - 1) as i32); + } + + stack.push(v2); + } + + let last = *stack.last().unwrap_or(&0); + + while !stack.is_empty() { + let top = stack.pop().unwrap(); + ans = ans.max(v1[top] * (last - *stack.last().unwrap_or(&0)) as i32); + } + } + + ans + } +} From 15e30ea1e48f8dd3c801dce66de28a50a2d8ff36 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 29 Jan 2023 16:07:24 +0800 Subject: [PATCH 0683/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 47b2a859..8bfcda76 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 386 | 174 | 197 | 15 | +| 387 | 174 | 197 | 16 | ### 题目 @@ -79,6 +79,7 @@ |82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | Medium | |83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | Easy | |84 | 柱状图中最大的矩形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-rectangle-in-histogram.rs) | [leetcode](https://leetcode-cn.com/problems/largest-rectangle-in-histogram/) | Hard | +|85 | 最大矩形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-rectangle.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-rectangle/) | Hard | |88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | Easy | |89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Medium | |91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Medium | From b2d5bd983ff25e0b71235e734dca765f27452910 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 30 Jan 2023 10:17:49 +0800 Subject: [PATCH 0684/1556] src/bin/scramble-string.rs --- src/bin/scramble-string.rs | 163 +++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 src/bin/scramble-string.rs diff --git a/src/bin/scramble-string.rs b/src/bin/scramble-string.rs new file mode 100644 index 00000000..a96b5a08 --- /dev/null +++ b/src/bin/scramble-string.rs @@ -0,0 +1,163 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::str::FromStr; + +fn main() { + assert!(!Solution::is_scramble("abcde".into(), "caebd".into())); + assert!(Solution::is_scramble("great".into(), "rgeat".into())); + assert!(Solution::is_scramble("abca".into(), "caba".into())); + assert!(Solution::is_scramble("a".into(), "a".into())); + assert!(!Solution::is_scramble("ab".into(), "xa".into())); + assert!(Solution::is_scramble("aaab".into(), "baaa".into())); + assert!(!Solution::is_scramble( + "ccabcbabcbabbbbcbb".into(), + "bbbbabccccbbbabcba".into() + )); + assert!(Solution::is_scramble( + "abcdbdacbdac".into(), + "bdacabcdbdac".into() + )); +} + +struct Solution; + +impl Solution { + /// 暴力递归 + pub fn force_is_scramble(s1: String, s2: String) -> bool { + if s1.len() <= 1 && s2.len() <= 1 { + return s1 == s2; + } + + let (b1, b2) = (s1.as_str(), s2.as_str()); + for i in 1..s1.len() { + if Solution::force_is_scramble( + String::from_str(&b1[0..i]).unwrap(), + String::from_str(&b2[0..i]).unwrap(), + ) && Solution::force_is_scramble( + String::from_str(&b1[i..b1.len()]).unwrap(), + String::from_str(&b2[i..b2.len()]).unwrap(), + ) { + return true; + } + + if Solution::force_is_scramble( + String::from_str(&b1[i..b1.len()]).unwrap(), + String::from_str(&b2[0..b1.len() - i]).unwrap(), + ) && Solution::force_is_scramble( + String::from_str(&b1[0..i]).unwrap(), + String::from_str(&b2[b2.len() - i..b2.len()]).unwrap(), + ) { + return true; + } + } + + false + } + + /// 递归记忆化搜索 + pub fn recu_is_scramble(s1: String, s2: String) -> bool { + // v[b1的开始索引][b2的开始索引][长度] + let mut v = vec![vec![vec![Option::::None; s1.len() + 1]; s1.len()]; s1.len()]; + + let (b1, b2) = (s1.as_bytes(), s2.as_bytes()); + + Self::check((0, b1.len()), (0, b1.len()), b1, b2, &mut v) + } + + pub fn check( + b1_index: (usize, usize), + b2_index: (usize, usize), + b1: &[u8], + b2: &[u8], + v: &mut Vec>>>, + ) -> bool { + assert_eq!(b1_index.1 - b1_index.0, b2_index.1 - b2_index.0); + + if b1_index.1 - b1_index.0 == 1 { + let r = b1[b1_index.0] == b2[b2_index.0]; + v[b1_index.0][b2_index.0][1] = Some(r); + } + + if let Some(x) = v[b1_index.0][b2_index.0][b1_index.1 - b1_index.0] { + return x; + } + for i in 1..b1_index.1 - b1_index.0 { + if Self::check( + (b1_index.0, b1_index.0 + i), + (b2_index.0, b2_index.0 + i), + b1, + b2, + v, + ) && Self::check( + (b1_index.0 + i, b1_index.1), + (b2_index.0 + i, b2_index.1), + b1, + b2, + v, + ) { + v[b1_index.0][b2_index.0][b1_index.1 - b1_index.0] = Some(true); + return true; + } + + if Self::check( + (b1_index.0, b1_index.0 + i), + (b2_index.1 - i, b2_index.1), + b1, + b2, + v, + ) && Self::check( + (b1_index.0 + i, b1_index.1), + (b2_index.0, b2_index.1 - i), + b1, + b2, + v, + ) { + v[b1_index.0][b2_index.0][b1_index.1 - b1_index.0] = Some(true); + return true; + } + } + + v[b1_index.0][b2_index.0][b1_index.1 - b1_index.0] = Some(false); + false + } + + /// dp + pub fn is_scramble(s1: String, s2: String) -> bool { + let n = s1.len(); + let (b1, b2) = (s1.as_bytes(), s2.as_bytes()); + + let mut v = vec![vec![vec![false; s1.len() + 1]; s1.len()]; s1.len()]; + + for i in 0..n { + for j in 0..n { + v[i][j][1] = b1[i] == b2[j]; + } + } + + for len in 2..=n { + for i in 0..n { + if i + len > n { + break; + } + + for j in 0..n { + if j + len > n { + break; + } + + // 从1个字符开始枚举 + for k in 1..len { + if (v[i][j][k] && v[i + k][j + k][len - k]) + || (v[i][j + len - k][k] && v[i + k][j][len - k]) + { + v[i][j][len] = true; + break; + } + } + } + } + } + + v[0][0][n] + } +} From a617dfdd2b04222003f495c0338b166b43ec640b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 30 Jan 2023 10:17:49 +0800 Subject: [PATCH 0685/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8bfcda76..c96fbccd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 387 | 174 | 197 | 16 | +| 388 | 174 | 197 | 17 | ### 题目 @@ -80,6 +80,7 @@ |83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | Easy | |84 | 柱状图中最大的矩形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-rectangle-in-histogram.rs) | [leetcode](https://leetcode-cn.com/problems/largest-rectangle-in-histogram/) | Hard | |85 | 最大矩形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-rectangle.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-rectangle/) | Hard | +|87 | 扰乱字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/scramble-string.rs) | [leetcode](https://leetcode-cn.com/problems/scramble-string/) | Hard | |88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | Easy | |89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Medium | |91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Medium | From 36c852bc9dc3198e0804c3a680e0a38eebe4ea10 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 30 Jan 2023 15:20:37 +0800 Subject: [PATCH 0686/1556] src/bin/longest-valid-parentheses.rs --- src/bin/longest-valid-parentheses.rs | 117 +++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/bin/longest-valid-parentheses.rs diff --git a/src/bin/longest-valid-parentheses.rs b/src/bin/longest-valid-parentheses.rs new file mode 100644 index 00000000..8635dfb1 --- /dev/null +++ b/src/bin/longest-valid-parentheses.rs @@ -0,0 +1,117 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + for i in vec![ + ("(()", 2), + (")()())", 4), + ("", 0), + ("(()))())(", 4), + ("))))((()((", 2), + ("()()))))()()(", 4), + ] { + assert_eq!( + Solution::force_longest_valid_parentheses(i.0.into()), + i.1, + "{}", + i.0 + ); + assert_eq!( + Solution::longest_valid_parentheses(i.0.into()), + i.1, + "{}", + i.0 + ); + assert_eq!( + Solution::stack_longest_valid_parentheses(i.0.into()), + i.1, + "{}", + i.0 + ); + } +} + +struct Solution; + +impl Solution { + /// 暴力解法 + /// 从大到小开始求解 + pub fn force_longest_valid_parentheses(s: String) -> i32 { + let mut len = s.len() / 2 * 2; // 因为括号都是成对出现的,所以从最长的长度开始 + let b = s.as_bytes(); + + while len > 0 { + for i in 0..b.len() { + if i + len > b.len() { + break; + } + if b[i] == b')' { + continue; + } + + if b[i + len - 1] != b')' { + continue; + } + + let mut left_num = 0; // 左括号的数量 + let mut invalid = false; + for j in i..i + len { + match b[j] { + b'(' => left_num += 1, + b')' => { + // 出现右括号但是左括号的数量为0时,说明不满足条件 + if left_num == 0 { + invalid = true; + break; + } + + left_num -= 1; + } + _ => unreachable!(), + } + } + + if !invalid && left_num == 0 { + return len as i32; + } + } + len -= 2; + } + + 0 + } + + /// 使用dp + pub fn longest_valid_parentheses(s: String) -> i32 { + // dp[i] = 2+dp[i-1] + dp[i-dp[i-1]-2] + // 2+dp[i-1]是内部的 + // dp[i-dp[i-1]-2]是与之相连的外部的 + let mut dp = vec![0; s.len()]; + let mut b = s.as_bytes(); + let mut ans = 0; + for i in 0..b.len() { + match b[i] { + b')' => { + if i < 1 { + continue; + } + + let inner = dp[i - 1]; + if i > inner { + if b[i - inner - 1] == b'(' { + dp[i] += inner + 2; + + if i > inner + 2 { + dp[i] += dp[i - inner - 2]; + } + } + } + + ans = ans.max(dp[i] as i32); + } + _ => continue, + } + } + + ans + } +} From 009ee96ee6f8baa1d6775ce00678a4495e20e5e4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 30 Jan 2023 15:20:38 +0800 Subject: [PATCH 0687/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c96fbccd..27c4f6dd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 388 | 174 | 197 | 17 | +| 389 | 174 | 197 | 18 | ### 题目 @@ -36,6 +36,7 @@ |27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | Easy | |28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | Easy | |31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Medium | +|32 | 最长有效括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/longest-valid-parentheses/) | Hard | |33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Medium | |34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Medium | |35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | Easy | From b58e502c90d630638d12792e7e44846c993b2890 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 31 Jan 2023 10:21:42 +0800 Subject: [PATCH 0688/1556] src/bin/binary-tree-maximum-path-sum.rs --- src/bin/binary-tree-maximum-path-sum.rs | 97 +++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/bin/binary-tree-maximum-path-sum.rs diff --git a/src/bin/binary-tree-maximum-path-sum.rs b/src/bin/binary-tree-maximum-path-sum.rs new file mode 100644 index 00000000..43eed113 --- /dev/null +++ b/src/bin/binary-tree-maximum-path-sum.rs @@ -0,0 +1,97 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + /// 递归 + pub fn max_path_sum(root: Option>>) -> i32 { + if root.is_none() { + return 0; + } + let mut max = None; + Self::max(root, &mut max); + + max.unwrap_or_default() + } + + fn max(root: Option>>, global_max: &mut Option) -> i32 { + if root.is_none() { + return 0; + } + let root = root.unwrap(); + let current = root.borrow().val; + + let left = root.borrow_mut().left.take(); + let right = root.borrow_mut().right.take(); + + let left_max = Solution::max(left, global_max); + let right_max = Solution::max(right, global_max); + + global_max.insert_if(current + left_max.max(0) + right_max.max(0), |x, y| *x > *y); + + current + left_max.max(right_max).max(0) // 当前节点的最大和 = 当前节点+子节点的最大值(且此值必须为正数) + } +} + +trait InsertIf { + fn insert_if(&mut self, value: T, f: F) + where + F: Fn(&T, &T) -> bool; +} + +impl InsertIf for Option { + fn insert_if(&mut self, value: T, f: F) + where + F: Fn(&T, &T) -> bool, + { + match self { + Some(x) => { + if f(&value, x) { + *self = Some(value); + }; + } + None => *self = Some(value), + } + } +} + +#[cfg(test)] +mod test { + use crate::InsertIf; + + #[test] + fn insert_if() { + let mut n = None; + + n.insert_if(10, |x, y| *x > *y); + assert_eq!(n, Some(10)); + + n.insert_if(11, |x, y| *x > *y); + assert_eq!(n, Some(11)); + + n.insert_if(9, |x, y| *x > *y); + assert_eq!(n, Some(11)); + } +} From 9cbb92a4a01ec606baa1ec3e73102f9ad918fe3f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 31 Jan 2023 10:21:43 +0800 Subject: [PATCH 0689/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 27c4f6dd..2bb9fa45 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 389 | 174 | 197 | 18 | +| 390 | 174 | 197 | 19 | ### 题目 @@ -108,6 +108,7 @@ |120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | Medium | |121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/) | Easy | |122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | Medium | +|124 | 二叉树中的最大路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-maximum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-maximum-path-sum/) | Hard | |125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | Easy | |129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Medium | |136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | Easy | From 84c207339a289aa05c498e5dc383f9c3d944b1bd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 31 Jan 2023 12:07:59 +0800 Subject: [PATCH 0690/1556] src/bin/longest-consecutive-sequence.rs --- src/bin/longest-consecutive-sequence.rs | 97 +++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/bin/longest-consecutive-sequence.rs diff --git a/src/bin/longest-consecutive-sequence.rs b/src/bin/longest-consecutive-sequence.rs new file mode 100644 index 00000000..24858a43 --- /dev/null +++ b/src/bin/longest-consecutive-sequence.rs @@ -0,0 +1,97 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + // assert_eq!(Solution::longest_consecutive(vec![100, 4, 200, 1, 3, 2]), 4); + assert_eq!( + Solution::hashset_longest_consecutive(vec![0, 3, 7, 2, 5, 8, 4, 6, 0, 1]), + 9 + ); +} + +struct Solution; + +impl Solution { + /// 使用哈希集合 + /// 遍历到一个数的时候,挨个+1看集合中是否存在,存在则说明是连续的。 + /// 优化:如果集合中是 [2,3,1,4,5] 的话,我们遍历2的时候,检查3,4,5是否存在,但是遍历到1的时候,要检查2,3,4,5是否存在,因此我们不需要在2的时候进行检查。因此遍历到i时,如果i-1存在,则i的时候不需要检查。 + pub fn hashset_longest_consecutive(nums: Vec) -> i32 { + let mut set = nums + .iter() + .map(|x| *x) + .collect::>(); + + let mut ans = 0; + + for mut i in nums { + if set.contains(&(i - 1)) { + continue; + } + + let mut r = 0; + while set.contains(&i) { + r += 1; + i += 1; + } + + ans = ans.max(r); + } + + ans + } + + /// 使用hash表,保存值对应的最远有边界,比如 [2,3,1,4,5], 2的最远右边界就是5,1的最远右边界也是5. + /// 初始化的时候,每个数的最远右边界为自己。 + /// 遍历的时候,如果遍历到i,如果i-1存在,则说明i是一个连续序列的起点,获取到对应的右边界 right1 + /// 如果right1+1存在, 获取到right1+1的右边界的值right2,如果 right2 + 1 存在,则获取right2+1的右边界right3,如果right3+1存在... + /// 此时i的右边界则为最后一个值 + pub fn hashmap_longest_consecutive(nums: Vec) -> i32 { + let mut map = nums + .iter() + .map(|x| (*x, *x)) + .collect::>(); + + let mut ans = 0; + + for i in nums { + if map.contains_key(&(i - 1)) { + continue; + } + + let mut right = *map.get(&i).unwrap(); + + while map.contains_key(&(right + 1)) { + right = *map.get(&(right + 1)).unwrap(); + } + + ans = ans.max(right - i + 1); + map.insert(i, right); + } + + ans + } + + /// hash表存数字i所在的连续最大长度值 + /// 对于数字i不存在,则i的值为 i-1 与 i+1的最大值 +1 + /// 然后更新i-1、i+1、i + fn dp_longest_consecutive(nums: Vec) -> i32 { + let mut map = std::collections::HashMap::::new(); + let mut ans = 0; + + for i in nums { + if map.contains_key(&i) { + continue; + } + + let left = map.get(&(i - 1)).and_then(|x| Some(*x)).unwrap_or_default(); + let right = map.get(&(i + 1)).and_then(|x| Some(*x)).unwrap_or_default(); + + let current = 1 + left + right; + ans = ans.max(current); + map.insert(i, current); + map.get_mut(&(i + right)).map(|x| *x = current); + map.get_mut(&(i - left)).map(|x| *x = current); + } + + ans + } +} From f9fd7bfc1d922a8701bd997012179880248e8df8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 31 Jan 2023 12:08:00 +0800 Subject: [PATCH 0691/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2bb9fa45..7b56ab13 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 390 | 174 | 197 | 19 | +| 391 | 174 | 198 | 19 | ### 题目 @@ -110,6 +110,7 @@ |122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | Medium | |124 | 二叉树中的最大路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-maximum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-maximum-path-sum/) | Hard | |125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | Easy | +|128 | 最长连续序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-consecutive-sequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-consecutive-sequence/) | Medium | |129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Medium | |136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | Easy | |137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Medium | From 3f6979c44e57dafec2ad8f912a91e1b7081560c1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 31 Jan 2023 15:25:19 +0800 Subject: [PATCH 0692/1556] src/bin/word-break.rs --- src/bin/word-break.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/word-break.rs diff --git a/src/bin/word-break.rs b/src/bin/word-break.rs new file mode 100644 index 00000000..3ba2e2bc --- /dev/null +++ b/src/bin/word-break.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// dp[i]表示s[0..i]是否满足 + /// dp[j] 是否满足取决于dp[0] —> dp[j-n] 和 s[j-n..j]是否满足 + pub fn word_break(s: String, word_dict: Vec) -> bool { + let mut n = s.len(); + + let hash = word_dict + .iter() + .map(|x| &x[..]) + .collect::>(); + let mut dp = vec![false; n]; + dp[0] = hash.contains(&s[0..1]); + + for i in 1..n { + if (dp[i - 1] && hash.contains(&s[i..i + 1])) || hash.contains(&s[0..i + 1]) { + dp[i] = true; + continue; + } + + for j in 0..i { + dp[i] = dp[j] && hash.contains(&s[j + 1..i + 1]); + if dp[i] { + break; + } + } + } + + dp[dp.len() - 1] + } +} From 44c116b4efa6a69507bd08982798ba226e1fbfc6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 31 Jan 2023 15:25:20 +0800 Subject: [PATCH 0693/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b56ab13..fcaf7324 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 391 | 174 | 198 | 19 | +| 392 | 174 | 199 | 19 | ### 题目 @@ -114,6 +114,7 @@ |129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Medium | |136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | Easy | |137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Medium | +|139 | 单词拆分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-break.rs) | [leetcode](https://leetcode-cn.com/problems/word-break/) | Medium | |144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | Easy | |145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | Easy | |150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Medium | From db8f0bf9577f5d6d7fde2663acc181095b33a779 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Feb 2023 10:46:52 +0800 Subject: [PATCH 0694/1556] src/bin/divide-two-integers.rs --- src/bin/divide-two-integers.rs | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/bin/divide-two-integers.rs diff --git a/src/bin/divide-two-integers.rs b/src/bin/divide-two-integers.rs new file mode 100644 index 00000000..c3599aa5 --- /dev/null +++ b/src/bin/divide-two-integers.rs @@ -0,0 +1,50 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::divide(10, 3), 3); + assert_eq!(Solution::divide(7, -3), -2); +} + +struct Solution; + +impl Solution { + // 设 x 为被除数,y为除数, z 为结果 + // 如果 x > y + y, 则 z+=z,y += y + // 如果 x < y + y, 则 x -= y, 返回步骤二继续计算剩余的数 + pub fn divide(dividend: i32, divisor: i32) -> i32 { + let ans = Self::d(dividend as i64, divisor as i64); + if ans > i32::MAX as i64 { + i32::MAX + } else if ans < i32::MIN as i64 { + i32::MIN + } else { + ans as i32 + } + } + + pub fn d(dividend: i64, divisor: i64) -> i64 { + // 符号位, true表示为正数 + let is_na = dividend.signum() == divisor.signum(); + + let (mut dividend, divisor) = (dividend.abs(), divisor.abs()); + + if dividend < divisor { + return 0; + } + + let mut start = divisor; + let mut ans = 1; + while dividend > start + start { + ans += ans; + start += start; + } + + ans += Self::d(dividend - start, divisor); + + if !is_na { + ans = 0 - ans; + } + + ans + } +} From cbb98eaa08e43ffd16131aa90618d564cd32b18e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Feb 2023 10:46:53 +0800 Subject: [PATCH 0695/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fcaf7324..471db131 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 392 | 174 | 199 | 19 | +| 393 | 174 | 200 | 19 | ### 题目 @@ -35,6 +35,7 @@ |26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | Easy | |27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | Easy | |28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | Easy | +|29 | 两数相除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/divide-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/divide-two-integers/) | Medium | |31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Medium | |32 | 最长有效括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/longest-valid-parentheses/) | Hard | |33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Medium | From b7178bf2d09ca16e27c7be356091bd959f9e8eb3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Feb 2023 11:57:03 +0800 Subject: [PATCH 0696/1556] src/bin/substring-with-concatenation-of-all-words.rs --- ...bstring-with-concatenation-of-all-words.rs | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/bin/substring-with-concatenation-of-all-words.rs diff --git a/src/bin/substring-with-concatenation-of-all-words.rs b/src/bin/substring-with-concatenation-of-all-words.rs new file mode 100644 index 00000000..22e63504 --- /dev/null +++ b/src/bin/substring-with-concatenation-of-all-words.rs @@ -0,0 +1,77 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() { + assert_eq!( + Solution::find_substring("aaaaaa".into(), vec!["a".into(), "a".into()]), + vec![0, 1, 2, 3, 4] + ); + + assert_eq!( + Solution::find_substring( + "barfoothefoobarman".into(), + vec!["foo".into(), "bar".into()] + ), + vec![0, 9] + ); + + assert_eq!( + Solution::find_substring( + "wordgoodgoodgoodbestword".into(), + vec!["word".into(), "good".into(), "best".into(), "word".into()] + ), + vec![] + ); + + assert_eq!( + Solution::find_substring( + "barfoofoobarthefoobarman".into(), + vec!["bar".into(), "foo".into(), "the".into()] + ), + vec![6, 9, 12] + ); +} + +struct Solution; + +impl Solution { + pub fn find_substring(s: String, words: Vec) -> Vec { + let word_len = words[0].len(); + let sub_string_len = words.len() * word_len; + let mut ans = vec![]; + + if s.len() < sub_string_len { + return ans; + } + + let mut map = std::collections::HashMap::new(); + + for i in words.iter() { + map.entry(&i[..]).and_modify(|x| *x += 1).or_insert(1i32); + } + + 'Loop: for i in 0..=s.len() - sub_string_len { + let mut m = map.clone(); + + for j in (i..i + sub_string_len).step_by(word_len) { + match m.get_mut(&s[j..j + word_len]) { + Some(x) => { + if *x > 1 { + *x -= 1 + } else if *x == 1 { + m.remove(&s[j..j + word_len]); + } + } + None => continue 'Loop, + } + } + + if m.is_empty() { + ans.push(i as i32); + } + } + + ans + } +} From 83a6bd112eaba2b2bbed1fc039c9e98dec31bfa1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Feb 2023 11:57:04 +0800 Subject: [PATCH 0697/1556] README.md --- README.md | 3 ++- src/bin/substring-with-concatenation-of-all-words.rs | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 471db131..5ed9de40 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 393 | 174 | 200 | 19 | +| 394 | 174 | 200 | 20 | ### 题目 @@ -36,6 +36,7 @@ |27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | Easy | |28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | Easy | |29 | 两数相除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/divide-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/divide-two-integers/) | Medium | +|30 | 串联所有单词的子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/substring-with-concatenation-of-all-words.rs) | [leetcode](https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words/) | Hard | |31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Medium | |32 | 最长有效括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/longest-valid-parentheses/) | Hard | |33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Medium | diff --git a/src/bin/substring-with-concatenation-of-all-words.rs b/src/bin/substring-with-concatenation-of-all-words.rs index 22e63504..28d0eae3 100644 --- a/src/bin/substring-with-concatenation-of-all-words.rs +++ b/src/bin/substring-with-concatenation-of-all-words.rs @@ -36,6 +36,9 @@ fn main() { struct Solution; impl Solution { + /// 先对words的单词计数,使用hashmap,m + /// 遍历s的下标为i,获取words单词长度的子字符串,如果在m存在,如果数量大于1则数量-1,如果数量为1则从m中删除此字符串,如果不存在则说明i为起始的子字符串不满足条件 + /// 注意:每次遍历时都要生成一个新的m pub fn find_substring(s: String, words: Vec) -> Vec { let word_len = words[0].len(); let sub_string_len = words.len() * word_len; From bcdf18d5a3aae0f59cc9e0b3522ab06232bfe18c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Feb 2023 15:02:31 +0800 Subject: [PATCH 0698/1556] src/bin/sudoku-solver.rs --- src/bin/sudoku-solver.rs | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/bin/sudoku-solver.rs diff --git a/src/bin/sudoku-solver.rs b/src/bin/sudoku-solver.rs new file mode 100644 index 00000000..494073e8 --- /dev/null +++ b/src/bin/sudoku-solver.rs @@ -0,0 +1,84 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + let mut v = vec![ + vec!['5', '3', '.', '.', '7', '.', '.', '.', '.'], + vec!['6', '.', '.', '1', '9', '5', '.', '.', '.'], + vec!['.', '9', '8', '.', '.', '.', '.', '6', '.'], + vec!['8', '.', '.', '.', '6', '.', '.', '.', '3'], + vec!['4', '.', '.', '8', '.', '3', '.', '.', '1'], + vec!['7', '.', '.', '.', '2', '.', '.', '.', '6'], + vec!['.', '6', '.', '.', '.', '.', '2', '8', '.'], + vec!['.', '.', '.', '4', '1', '9', '.', '.', '5'], + vec!['.', '.', '.', '.', '8', '.', '.', '7', '9'], + ]; + + Solution::solve_sudoku(&mut v); + + for i in v { + println!("{i:?}"); + } +} + +struct Solution; + +impl Solution { + /// 暴力解法,挨个枚举就完事 + pub fn solve_sudoku(board: &mut Vec>) { + Self::rec(board, (0, 0)); + } + + pub fn rec(board: &mut Vec>, start: (usize, usize)) -> bool { + if start.0 == 8 && start.1 == 8 && board[start.0][start.1] != '.' { + return true; + } + + let mut index = (start.0, start.1); + while index.0 < 9 && index.1 < 9 { + if board[index.0][index.1] == '.' { + break; + } + index.1 += 1; + if index.1 == 9 { + index.0 += 1; + index.1 = 0; + } + } + + if index.0 == 9 || index.1 == 9 { + return true; + } + + 'Loop: for value in '1'..='9' { + // 检查行和列 + for x in 0..9 { + if board[index.0][x] == value { + continue 'Loop; + } + + if board[x][index.1] == value { + continue 'Loop; + } + } + + // 检查四周 + for i in index.0 / 3 * 3..index.0 / 3 * 3 + 3 { + for j in index.1 / 3 * 3..index.1 / 3 * 3 + 3 { + if board[i][j] == value { + continue 'Loop; + } + } + } + + board[index.0][index.1] = value; + + if !Solution::rec(board, index) { + board[index.0][index.1] = '.'; + } else { + return true; + } + } + + false + } +} From e63f105722560921399855e78a2170d02fed5889 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Feb 2023 15:02:32 +0800 Subject: [PATCH 0699/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ed9de40..b52a1ced 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 394 | 174 | 200 | 20 | +| 395 | 174 | 200 | 21 | ### 题目 @@ -43,6 +43,7 @@ |34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Medium | |35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | Easy | |36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Medium | +|37 | 解数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sudoku-solver.rs) | [leetcode](https://leetcode-cn.com/problems/sudoku-solver/) | Hard | |38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Medium | |39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | |41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Hard | From 7f3975239f4736859ff523b3d93c838501e53dce Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Feb 2023 15:21:34 +0800 Subject: [PATCH 0700/1556] src/bin/sudoku-solver.rs --- src/bin/sudoku-solver.rs | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/bin/sudoku-solver.rs b/src/bin/sudoku-solver.rs index 494073e8..ab068d30 100644 --- a/src/bin/sudoku-solver.rs +++ b/src/bin/sudoku-solver.rs @@ -29,51 +29,50 @@ impl Solution { } pub fn rec(board: &mut Vec>, start: (usize, usize)) -> bool { + if start.0 > 8 || start.1 > 8 { + return false; + } + if start.0 == 8 && start.1 == 8 && board[start.0][start.1] != '.' { return true; } - let mut index = (start.0, start.1); - while index.0 < 9 && index.1 < 9 { - if board[index.0][index.1] == '.' { - break; - } - index.1 += 1; - if index.1 == 9 { - index.0 += 1; - index.1 = 0; - } - } + // 下一个坐标 + let mut index = if start.1 == 8 { + (start.0 + 1, 0) + } else { + (start.0, start.1 + 1) + }; - if index.0 == 9 || index.1 == 9 { - return true; + if board[start.0][start.1] != '.' { + return Self::rec(board, index); } 'Loop: for value in '1'..='9' { // 检查行和列 for x in 0..9 { - if board[index.0][x] == value { + if board[start.0][x] == value { continue 'Loop; } - if board[x][index.1] == value { + if board[x][start.1] == value { continue 'Loop; } } // 检查四周 - for i in index.0 / 3 * 3..index.0 / 3 * 3 + 3 { - for j in index.1 / 3 * 3..index.1 / 3 * 3 + 3 { + for i in start.0 / 3 * 3..start.0 / 3 * 3 + 3 { + for j in start.1 / 3 * 3..start.1 / 3 * 3 + 3 { if board[i][j] == value { continue 'Loop; } } } - board[index.0][index.1] = value; + board[start.0][start.1] = value; if !Solution::rec(board, index) { - board[index.0][index.1] = '.'; + board[start.0][start.1] = '.'; } else { return true; } From 84936ba17bc1dc963717d24479b1c779a7b3c70a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Feb 2023 15:21:34 +0800 Subject: [PATCH 0701/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b52a1ced..7b9391ac 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 395 | 174 | 200 | 21 | +| 396 | 174 | 200 | 22 | ### 题目 @@ -44,6 +44,7 @@ |35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | Easy | |36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Medium | |37 | 解数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sudoku-solver.rs) | [leetcode](https://leetcode-cn.com/problems/sudoku-solver/) | Hard | +|37 | 解数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sudoku-solver.rs) | [leetcode](https://leetcode-cn.com/problems/sudoku-solver/) | Hard | |38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Medium | |39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | |41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Hard | From 1e501fea97d70ef726f7319e8319c8c260f3aac1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 2 Feb 2023 12:33:21 +0800 Subject: [PATCH 0702/1556] src/bin/lru-cache.rs --- src/bin/lru-cache.rs | 204 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 src/bin/lru-cache.rs diff --git a/src/bin/lru-cache.rs b/src/bin/lru-cache.rs new file mode 100644 index 00000000..6a61b2a0 --- /dev/null +++ b/src/bin/lru-cache.rs @@ -0,0 +1,204 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::{ + cell::RefCell, + rc::{Rc, Weak}, +}; + +fn main() { + // ["LRUCache","put","put","put","put","get","get","get","get","put","get","get","get","get","get"] + // [[3], [1,1],[2,2],[3,3],[4,4],[4], [3], [2], [1], [5,5], [1], [2], [3], [4], [5]] + // [null, null, null, null, null, 4, 3, 2, -1, null, -1, 2, 3, -1, 5] + + let mut lru = LRUCache::new(3); + lru.put(1, 1); + lru.put(2, 2); + lru.put(3, 3); + lru.put(4, 4); + + assert_eq!(lru.get(4), 4); + assert_eq!(lru.get(3), 3); + assert_eq!(lru.get(2), 2); + assert_eq!(lru.get(1), -1); + + lru.put(5, 5); + + assert_eq!(lru.get(1), -1); + assert_eq!(lru.get(2), 2); + assert_eq!(lru.get(3), 3); + assert_eq!(lru.get(4), -1); + assert_eq!(lru.get(5), 5); +} + +struct Solution; + +#[derive(Clone)] +struct KeyValuePair { + key: i32, + value: i32, +} + +struct LRUCache { + map: std::collections::HashMap>>, + list: List, + capacity: usize, +} + +struct Node { + value: KeyValuePair, + next: Option>>, + prev: Option>>, +} + +struct List { + length: usize, + head: Option>>, + tail: Option>>, +} + +impl List { + fn new() -> Self { + Self { + length: 0, + head: None, + tail: None, + } + } + + // 从链表中移除当前节点 + // 当前节点的prev节点的next节点指向当前节点的next节点 + // 当前节点的next节点的prev节点指向当前节点的prev节点 + fn remove(&mut self, node: Rc>) { + if self.length == 0 { + return; + } + + self.length -= 1; + + let prev = node.borrow_mut().prev.take(); + let next = node.borrow_mut().next.take(); + + // 说明移除的是头节点, head要指向next节点 + if prev.is_none() { + self.head = next.clone(); + } + + // 说明移除的尾节点,tail要指向prev节点 + if next.is_none() { + self.tail = prev.clone(); + } + + prev.clone().map(|x| x.borrow_mut().next = next.clone()); + next.clone().map(|x| x.borrow_mut().prev = prev.clone()); + } + + /// 向列表头部插入数据 + /// head指向新的数据 + /// 新数据的next指向原列表头部 + fn push_front(&mut self, value: KeyValuePair) -> Rc> { + self.length += 1; + + let node = Rc::new(RefCell::new(Node { + value, + next: None, + prev: None, + })); + + // 获取当前头头节点 + let head = self.head.take(); + + // 新的头节点的下一个元素指向旧的头节点 + node.borrow_mut().next = head.clone(); + + // 旧的头节点的prev指向新的头节点 + head.clone() + .map(|x| x.borrow_mut().prev = Some(node.clone())); + + // 如果长度为1,尾节点和头节点指向头一个节点 + if self.length == 1 { + self.tail = Some(node.clone()); + } + + self.head = Some(node.clone()); + + node + } + + /// 移除尾部元素 + /// 获取到tail的值, + /// 将tail.prev设置为tail + /// tail.prev.next设置为None + /// 返回最后节点的key + fn pop(&mut self) -> Option { + match self.tail.take() { + None => None, + Some(node) => { + self.length -= 1; + let prev = node.borrow().prev.clone(); + prev.clone().map(|x| x.borrow_mut().next = None); + self.tail = prev.clone(); // 将tail节点设置为 prev + node.borrow_mut().prev = None; + + if self.length == 0 { + self.head = None; + } + + Some(node.borrow().value.key) + } + } + } +} + +impl Drop for List { + fn drop(&mut self) { + // 回收所有节点 + while let Some(_) = self.pop() {} + } +} + +impl LRUCache { + fn new(capacity: i32) -> Self { + Self { + capacity: capacity as usize, + map: Default::default(), + list: List::new(), + } + } + + fn get(&mut self, key: i32) -> i32 { + match self._get(key) { + None => -1, + Some(x) => x.borrow().value.value, + } + } + + fn _get(&mut self, key: i32) -> Option>> { + match self.map.get_mut(&key) { + None => None, + Some(x) => { + self.list.remove(x.clone()); // 先移除当前节点 + let new = self.list.push_front(x.borrow().value.clone()); // 新插入节点 + *x = new.clone(); + Some(new) + } + } + } + + fn put(&mut self, key: i32, value: i32) { + match self._get(key) { + None => { + if self.map.len() == self.capacity { + if let Some(x) = self.list.pop() { + self.map.remove(&x); + } + } + + let x = self.list.push_front(KeyValuePair { key, value }); + self.map.insert(key, x); + } + Some(x) => { + x.borrow_mut().value.value = value; + } + } + } +} From 4c165d853090accca59386c51dd037cbd7c5f583 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 2 Feb 2023 12:33:22 +0800 Subject: [PATCH 0703/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b9391ac..6e86c419 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 396 | 174 | 200 | 22 | +| 397 | 174 | 201 | 22 | ### 题目 @@ -121,6 +121,7 @@ |139 | 单词拆分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-break.rs) | [leetcode](https://leetcode-cn.com/problems/word-break/) | Medium | |144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | Easy | |145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | Easy | +|146 | LRU 缓存 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lru-cache.rs) | [leetcode](https://leetcode-cn.com/problems/lru-cache/) | Medium | |150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Medium | |151 | 颠倒字符串中的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | Medium | |152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Medium | From 8842f0b179c7f993698d3c5b6fc62b2cbcca6875 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 3 Feb 2023 12:04:46 +0800 Subject: [PATCH 0704/1556] src/bin/minimum-sideway-jumps.rs --- src/bin/minimum-sideway-jumps.rs | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/bin/minimum-sideway-jumps.rs diff --git a/src/bin/minimum-sideway-jumps.rs b/src/bin/minimum-sideway-jumps.rs new file mode 100644 index 00000000..048376ba --- /dev/null +++ b/src/bin/minimum-sideway-jumps.rs @@ -0,0 +1,44 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::min_side_jumps(vec![0, 2, 1, 0, 3, 0]), 2); + assert_eq!(Solution::min_side_jumps(vec![0, 1, 1, 3, 3, 0]), 0); + assert_eq!(Solution::min_side_jumps(vec![0, 1, 2, 3, 0]), 2); +} + +struct Solution; + +impl Solution { + /// dp + pub fn min_side_jumps(obstacles: Vec) -> i32 { + let mut dp = [1, 0, 1i64]; + // 起点都没障碍物,所以起点为0 + + for i in 1..obstacles.len() { + let a = obstacles[i]; + // 说明当前位置三个跑道都没有障碍物,因此 + let mut new_dp = [0, 0, 0]; + if a == 0 { + new_dp[0] = dp[0].min(1 + dp[1].min(dp[2])); + new_dp[1] = dp[1].min(1 + dp[0].min(dp[2])); + new_dp[2] = dp[2].min(1 + dp[0].min(dp[1])); + } else if a == 1 { + new_dp[0] = i32::MAX as i64; + new_dp[1] = dp[1].min(1 + dp[2]); + new_dp[2] = dp[2].min(1 + dp[1]); + } else if a == 2 { + new_dp[0] = dp[0].min(1 + dp[2]); + new_dp[1] = i32::MAX as i64; + new_dp[2] = dp[2].min(1 + dp[0]); + } else { + new_dp[0] = dp[0].min(1 + dp[1]); + new_dp[1] = dp[1].min(1 + dp[0]); + new_dp[2] = i32::MAX as i64; + } + + dp = new_dp; + } + + *dp[..].into_iter().min().unwrap() as i32 + } +} From 7574029f3b4c4f4288a30545692fa8ed86aacd7e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 3 Feb 2023 12:04:47 +0800 Subject: [PATCH 0705/1556] README.md --- README.md | 3 ++- src/bin/minimum-sideway-jumps.rs | 40 ++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6e86c419..7b270996 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 397 | 174 | 201 | 22 | +| 398 | 174 | 202 | 22 | ### 题目 @@ -322,6 +322,7 @@ |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | |1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | |1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | +|1952 | 最少侧跳次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sideway-jumps.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sideway-jumps/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | diff --git a/src/bin/minimum-sideway-jumps.rs b/src/bin/minimum-sideway-jumps.rs index 048376ba..95323d0d 100644 --- a/src/bin/minimum-sideway-jumps.rs +++ b/src/bin/minimum-sideway-jumps.rs @@ -9,8 +9,8 @@ fn main() { struct Solution; impl Solution { - /// dp - pub fn min_side_jumps(obstacles: Vec) -> i32 { + /// dp 这个看不懂 + pub fn min_side_jumps1(obstacles: Vec) -> i32 { let mut dp = [1, 0, 1i64]; // 起点都没障碍物,所以起点为0 @@ -41,4 +41,40 @@ impl Solution { *dp[..].into_iter().min().unwrap() as i32 } + + /// dp[i][j], 0 < i < 3, j < obstacles.len() 表示第i条跑道在第j点时的最少跳跃次数 + /// 所以dp[i][j] 可能有:1.如果有障碍物的话,就不符合要求 + /// 2.没有障碍物,就是dp[i-1][j]或者是dp[i][n]+1的最小值(因为跳跃到[i,j]位置不值可以从[i-1,j]跳跃而来,而且还可以从j处的其他跑道而来。所以统一下跳跃的次数就行了。) + pub fn min_side_jumps(obstacles: Vec) -> i32 { + // 起点都没障碍物,所以起点为0 + let mut dp = [1, 0, 1i64]; + + for i in 1..obstacles.len() { + let a = obstacles[i]; // 障碍物 + let mut new_dp = [0, 0, 0]; + let mut min = i32::MAX as i64; + + for i in 0..3 { + if a - 1 == i { + new_dp[i as usize] = i32::MAX as i64; + } else { + new_dp[i as usize] = dp[i as usize]; + } + + min = min.min(new_dp[i as usize]); + } + + // 因为任何点都可以从当前位置的其他点+1跳来,需要判断下是不是其他点+1跳过来的更短少 + + for i in 0..3 { + if a - 1 != i { + new_dp[i as usize] = new_dp[i as usize].min(min + 1); + } + } + + dp = new_dp; + } + + *dp[..].into_iter().min().unwrap() as i32 + } } From 92c4ea22f62372e0cd5d2bb53a376c6df4578f11 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 3 Feb 2023 17:24:18 +0800 Subject: [PATCH 0706/1556] src/bin/distinct-subsequences-ii.rs --- src/bin/distinct-subsequences-ii.rs | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/distinct-subsequences-ii.rs diff --git a/src/bin/distinct-subsequences-ii.rs b/src/bin/distinct-subsequences-ii.rs new file mode 100644 index 00000000..7f588987 --- /dev/null +++ b/src/bin/distinct-subsequences-ii.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::distinct_subseq_ii("abc".into()), 7); + assert_eq!(Solution::distinct_subseq_ii("aaa".into()), 3); +} + +struct Solution; + +impl Solution { + /// 暴力解法 + /// 从长度为1开始, + /// 从下标为0开始 + /// + /// dp + /// v[i]表示s[0..i]的子串个数 + /// 则v[i] = v[i-1] + 新增个数a - 重复个数b + /// 因为s[0..i]相较于s[0..i-1]新增了一个字符,所以 a = v[i-1]+1 + /// 新增的子串都是以s[i]结尾的,所以重复的肯定是上次遇到相同字符结尾的字符串子串的个数,因此记录下每个字符上次出现的个数,即为重复的个数 + pub fn distinct_subseq_ii(s: String) -> i32 { + // let mut v = vec![0; s.len()]; // 这种只需要前一个数据,不需要回溯的,用一个变量表示就行了 + let mut repeate = [0; 26]; + let bytes = s.as_bytes(); + + let mut v = 1; + repeate[(bytes[0] - b'a') as usize] = v; + + for i in 1..bytes.len() { + v = (v * 2 + 1) - repeate[(bytes[i] - b'a') as usize]; + repeate[(bytes[i] - b'a') as usize] = v; + } + + v + } +} From 748291f558307a0f6d9072e03b2850e81b9d6a99 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 3 Feb 2023 17:24:19 +0800 Subject: [PATCH 0707/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b270996..5f0f474b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 398 | 174 | 202 | 22 | +| 399 | 174 | 202 | 23 | ### 题目 @@ -270,6 +270,7 @@ |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | |947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | +|977 | 不同的子序列 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distinct-subsequences-ii.rs) | [leetcode](https://leetcode-cn.com/problems/distinct-subsequences-ii/) | Hard | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | |981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | |982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Medium | From ba9670946e4d382e42b7d59b827f4780e55fd26b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 4 Feb 2023 11:33:44 +0800 Subject: [PATCH 0708/1556] src/bin/length-of-longest-fibonacci-subsequence.rs --- ...length-of-longest-fibonacci-subsequence.rs | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/bin/length-of-longest-fibonacci-subsequence.rs diff --git a/src/bin/length-of-longest-fibonacci-subsequence.rs b/src/bin/length-of-longest-fibonacci-subsequence.rs new file mode 100644 index 00000000..06a75742 --- /dev/null +++ b/src/bin/length-of-longest-fibonacci-subsequence.rs @@ -0,0 +1,76 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!( + Solution::len_longest_fib_subseq(vec![1, 2, 3, 4, 5, 6, 7, 8]), + 5 + ); + assert_eq!( + Solution::len_longest_fib_subseq(vec![1, 3, 7, 11, 12, 14, 18]), + 3 + ); +} + +struct Solution; + +impl Solution { + /// 暴力搜索, 双指针 + /// p1 = arr[0], p2 = arr[1], 如果 p1+p2在arr存在,则 p1, p2 = p2, p1+p2,结果+1;如果不存在,则推出循环 + pub fn force_len_longest_fib_subseq(arr: Vec) -> i32 { + let mut set = arr + .iter() + .map(|x| *x) + .collect::>(); + let mut ans = 0; + + for i in 0..arr.len() - 2 { + let mut _ans = -1; + for j in i + 1..arr.len() - 1 { + let mut current1 = arr[i]; + let mut current2 = arr[j]; + + while set.contains(&(current1 + current2)) { + _ans = (_ans + 1).max(3); + let _current1 = current2; + current2 = current1 + current2; + current1 = _current1; + } + + ans = ans.max(_ans); + _ans = -1; + } + } + + ans + } + + /// dp + /// dp[i][j]表示以arr[i]和arr[j]开始的最大值 + /// 则 dp[i][j] = 1 + dp[j][arr[i] +arr[j]] if arr[i] + arr[j] 存在的话 + pub fn len_longest_fib_subseq(arr: Vec) -> i32 { + let mut map = arr + .iter() + .enumerate() + .map(|(x, y)| (*y, x)) + .collect::>(); + let mut ans = 0; + + let mut dp = vec![vec![-1; arr.len()]; arr.len()]; + + for i in (0..arr.len() - 2).rev() { + for j in (i + 1..arr.len() - 1) { + let mut inner = 0; + let mut sum = arr[i] + arr[j]; + match map.get(&sum) { + Some(&x) => inner = (dp[j][x] + 1).max(3), + None => inner = 0, + } + + dp[i][j] = inner; + ans = ans.max(inner); + } + } + + ans + } +} From d4a4a7eeaff43ffe616f9968ebc30d5b3b62e3b5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 4 Feb 2023 11:33:44 +0800 Subject: [PATCH 0709/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f0f474b..bf78cf31 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 399 | 174 | 202 | 23 | +| 400 | 174 | 203 | 23 | ### 题目 @@ -263,6 +263,7 @@ |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | +|905 | 最长的斐波那契子序列的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-longest-fibonacci-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence/) | Medium | |917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | |921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | |924 | 公平的糖果交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | From cb97ad820be2ed84d97748dd1c58cc7b1af17924 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 5 Feb 2023 22:44:39 +0800 Subject: [PATCH 0710/1556] src/bin/sort-list.rs --- src/bin/sort-list.rs | 84 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/bin/sort-list.rs diff --git a/src/bin/sort-list.rs b/src/bin/sort-list.rs new file mode 100644 index 00000000..117583eb --- /dev/null +++ b/src/bin/sort-list.rs @@ -0,0 +1,84 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} + +impl Solution { + /// 归并排序 + pub fn sort_list(mut head: Option>) -> Option> { + let mut length = 0; + let mut ptr = head.as_ref(); + + if ptr.is_some() { + ptr = ptr.unwrap().next.as_ref(); + length += 1; + } + + Solution::sort(head, length) + } + + pub fn sort(mut head: Option>, length: usize) -> Option> { + if head.is_none() { + return None; + } + + if head.as_ref().unwrap().next.is_none() { + return head; + } + + let mut middle = head.as_mut(); + + for _ in 0..length / 2 { + middle = middle.unwrap().next.as_mut(); + } + + let mut r1 = Solution::sort_list(middle.unwrap().next.take()); + let mut r2 = Solution::sort_list(head); + + let mut result = Some(Box::new(ListNode::new(-1i32))); + let mut current = result.as_mut(); + loop { + match (r1, r2) { + (Some(mut x1), Some(mut x2)) => { + if x1.val < x2.val { + r2 = Some(x2); + r1 = x1.next.take(); + current.as_mut().unwrap().next = Some(x1); + } else { + r1 = Some(x1); + r2 = x2.next.take(); + current.as_mut().unwrap().next = Some(x2); + } + + current = current.unwrap().next.as_mut(); + } + (Some(x1), None) => { + current.unwrap().next = Some(x1); + break; + } + (None, Some(x2)) => { + current.unwrap().next = Some(x2); + break; + } + _ => break, + } + } + + result.map(|mut x| x.next.take()).unwrap() + } +} From b2f8f3b31285c5d1b04aa86f5d1483762edfad15 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 5 Feb 2023 22:44:39 +0800 Subject: [PATCH 0711/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bf78cf31..dfc4d21a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 400 | 174 | 203 | 23 | +| 401 | 174 | 204 | 23 | ### 题目 @@ -122,6 +122,7 @@ |144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | Easy | |145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | Easy | |146 | LRU 缓存 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lru-cache.rs) | [leetcode](https://leetcode-cn.com/problems/lru-cache/) | Medium | +|148 | 排序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-list.rs) | [leetcode](https://leetcode-cn.com/problems/sort-list/) | Medium | |150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Medium | |151 | 颠倒字符串中的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | Medium | |152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Medium | From e8a813580378a2b91c436993ee87cde6e4fe1478 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 Feb 2023 10:35:46 +0800 Subject: [PATCH 0712/1556] src/bin/course-schedule.rs --- src/bin/course-schedule.rs | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/bin/course-schedule.rs diff --git a/src/bin/course-schedule.rs b/src/bin/course-schedule.rs new file mode 100644 index 00000000..0f01930d --- /dev/null +++ b/src/bin/course-schedule.rs @@ -0,0 +1,66 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +struct Node { + /// 入度个数 + indegrees: i32, + /// 出度列表 + adjacency: Vec, +} + +impl Solution { + /// 有向图 + /// 看是否有环 + /// m[a] = b, a为课程编号,b为依赖a的课程 + pub fn can_finish(num_courses: i32, prerequisites: Vec>) -> bool { + if prerequisites.is_empty() { + return true; + } + + let mut h = std::collections::HashMap::new(); + + for i in prerequisites.iter() { + h.entry(i[1]) + .or_insert(Node { + indegrees: 0, + adjacency: vec![], + }) + .adjacency + .push(i[0]); + + h.entry(i[0]) + .or_insert(Node { + indegrees: 0, + adjacency: vec![], + }) + .indegrees += 1; + } + + let mut stack = vec![]; + for (&i, node) in h.iter() { + if node.indegrees == 0 { + stack.push(i); + } + } + + let mut count = 0; + + while let Some(x) = stack.pop() { + count += 1; + + let node = h.remove(&x).unwrap(); + + for i in node.adjacency { + h.entry(i).and_modify(|x| x.indegrees -= 1); + if h.get(&i).unwrap().indegrees == 0 { + stack.push(i); + } + } + } + + h.is_empty() || count >= num_courses + } +} From d06e260ee1be621f150d609c4641fc3252245469 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 Feb 2023 10:35:47 +0800 Subject: [PATCH 0713/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dfc4d21a..27fe0fc0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 401 | 174 | 204 | 23 | +| 402 | 174 | 205 | 23 | ### 题目 @@ -150,6 +150,7 @@ |204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | Medium | |205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | Easy | |206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | Easy | +|207 | 课程表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/course-schedule.rs) | [leetcode](https://leetcode-cn.com/problems/course-schedule/) | Medium | |208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | Medium | |211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | Medium | |213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | Medium | From 3db2959cd0bc68ee96ab4aa8dcd7853c36483b47 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 7 Feb 2023 15:34:55 +0800 Subject: [PATCH 0714/1556] src/bin/lowest-common-ancestor-of-a-binary-tree.rs --- ...lowest-common-ancestor-of-a-binary-tree.rs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/bin/lowest-common-ancestor-of-a-binary-tree.rs diff --git a/src/bin/lowest-common-ancestor-of-a-binary-tree.rs b/src/bin/lowest-common-ancestor-of-a-binary-tree.rs new file mode 100644 index 00000000..6fff9510 --- /dev/null +++ b/src/bin/lowest-common-ancestor-of-a-binary-tree.rs @@ -0,0 +1,59 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + /// 递归搜寻,当root为空或者root为p或者q就返回root + /// 然后搜寻子树,如果返回的都不为空,说明root是父节点 + pub fn lowest_common_ancestor( + mut root: Option>>, + mut p: Option>>, + mut q: Option>>, + ) -> Option>> { + if root.is_none() || root == p || root == q { + return root; + } + + let left = Self::lowest_common_ancestor( + root.clone().and_then(|x| x.borrow_mut().left.take()), + p.clone(), + q.clone(), + ); + + let right = Self::lowest_common_ancestor( + root.clone().and_then(|x| x.borrow_mut().right.take()), + p.clone(), + q.clone(), + ); + + if left.is_none() { + right + } else if right.is_none() { + left + } else { + root + } + } +} From 7ff8af7b39349ebb16132257945be107f0a7ec81 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 7 Feb 2023 15:34:57 +0800 Subject: [PATCH 0715/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 27fe0fc0..cf1aba16 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 402 | 174 | 205 | 23 | +| 403 | 174 | 206 | 23 | ### 题目 @@ -169,6 +169,7 @@ |232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks/) | Easy | |234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) | Easy | |235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | Easy | +|236 | 二叉树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/) | Medium | |238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Medium | |240 | 搜索二维矩阵 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix-ii/) | Medium | |242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | Easy | From ef1bd0e9737c6972e0cf53f15715e085269cff4a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 7 Feb 2023 21:58:29 +0800 Subject: [PATCH 0716/1556] src/bin/find-the-duplicate-number.rs --- src/bin/find-the-duplicate-number.rs | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/find-the-duplicate-number.rs diff --git a/src/bin/find-the-duplicate-number.rs b/src/bin/find-the-duplicate-number.rs new file mode 100644 index 00000000..7e9cf4c3 --- /dev/null +++ b/src/bin/find-the-duplicate-number.rs @@ -0,0 +1,31 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::find_duplicate(vec![1, 3, 4, 2, 2]), 2); + assert_eq!(Solution::find_duplicate(vec![2, 2, 2]), 2); +} + +struct Solution; + +impl Solution { + /// 环形列表, 找到第一个入环的值 + pub fn find_duplicate(nums: Vec) -> i32 { + let (mut slow, mut fast) = (0, 0); + + while fast < nums.len() { + slow = nums[slow] as usize; + fast = nums[nums[fast] as usize] as usize; + if nums[slow] == nums[fast] { + break; + } + } + + let mut slow = 0; + while nums[slow] != nums[fast] { + slow = nums[slow] as usize; + fast = nums[fast] as usize; + } + + nums[slow] + } +} From d07c9b4db85c79c6c448a562481476b880e982fd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 7 Feb 2023 21:58:29 +0800 Subject: [PATCH 0717/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cf1aba16..cc4ca3da 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 403 | 174 | 206 | 23 | +| 404 | 174 | 207 | 23 | ### 题目 @@ -181,6 +181,7 @@ |278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | |279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | |283 | 移动零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/move-zeroes/) | Easy | +|287 | 寻找重复数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-duplicate-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-duplicate-number/) | Medium | |290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | |292 | Nim 游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nim-game.rs) | [leetcode](https://leetcode-cn.com/problems/nim-game/) | Easy | |300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | From 26bfc64d71ce58b85049ca6902aa880efc33bef5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 8 Feb 2023 09:23:38 +0800 Subject: [PATCH 0718/1556] src/bin/serialize-and-deserialize-binary-tree.rs --- .../serialize-and-deserialize-binary-tree.rs | 121 ++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 src/bin/serialize-and-deserialize-binary-tree.rs diff --git a/src/bin/serialize-and-deserialize-binary-tree.rs b/src/bin/serialize-and-deserialize-binary-tree.rs new file mode 100644 index 00000000..7d4757b3 --- /dev/null +++ b/src/bin/serialize-and-deserialize-binary-tree.rs @@ -0,0 +1,121 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + let mut c = Codec::new(); + println!("{:?}", c.deserialize(r#"{"val": 1, "left": {"val": 2, "left": null, "right": null}, "right": {"val": 3, "left": {"val": 4, "left": null, "right": null}, "right": {"val": 5, "left": null, "right": null}}}"#.into())); + println!("{:?}", c.deserialize(r#"{"val": 4, "left": {"val": -7, "left": null, "right": null}, "right": {"val": -3, "left": {"val": -9, "left": {"val": 9, "left": {"val": 6, "left": {"val": 0, "left": null, "right": {"val": -1, "left": null, "right": null}}, "right": {"val": 6, "left": {"val": -4, "left": null, "right": null}, "right": null}}, "right": null}, "right": {"val": -7, "left": {"val": -6, "left": {"val": 5, "left": null, "right": null}, "right": null}, "right": {"val": -6, "left": {"val": 9, "left": {"val": -2, "left": null, "right": null}, "right": null}, "right": null}}}, "right": {"val": -3, "left": {"val": -4, "left": null, "right": null}, "right": null}}}"#.into())); +} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::cell::RefCell; +use std::rc::Rc; +struct Codec { + buffer: String, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl Codec { + fn new() -> Self { + Self { + buffer: String::new(), + } + } + + fn serialize(&mut self, root: Option>>) -> String { + self.s(root); + self.buffer.to_owned() + } + + fn s(&mut self, root: Option>>) { + match root { + None => { + self.buffer.push_str("null"); + } + Some(r) => { + self.buffer.push_str("{"); + self.buffer.push_str(r#""val": "#); + self.buffer.push_str(&format!("{}, ", r.borrow().val)); + self.buffer.push_str(r#""left": "#); + self.s(r.borrow_mut().left.take()); + self.buffer.push_str(", "); + self.buffer.push_str(r#""right": "#); + self.s(r.borrow_mut().right.take()); + self.buffer.push_str("}"); + } + } + } + + fn deserialize(&self, data: String) -> Option>> { + self.d(&mut data.as_bytes()) + } + + fn d(&self, data: &mut &[u8]) -> Option>> { + let mut node = None; + if data.starts_with(&[b'n', b'u', b'l', b'l']) { + *data = &data[4..]; + return node; + } + + loop { + if data.starts_with(&[b'{']) { + *data = &data[1..]; + } else if data.starts_with(&[b'"', b'l', b'e', b'f', b't', b'"', b':', b' ']) { + *data = &data[8..]; + node.get_or_insert(Rc::new(RefCell::new(TreeNode::new(-1)))) + .borrow_mut() + .left = self.d(data); + } else if data.starts_with(&[b'"', b'r', b'i', b'g', b'h', b't', b'"', b':', b' ']) { + *data = &data[9..]; + node.get_or_insert(Rc::new(RefCell::new(TreeNode::new(-1)))) + .borrow_mut() + .right = self.d(data); + } else if data.starts_with(&[b'"', b'v', b'a', b'l', b'"', b':', b' ']) { + *data = &data[7..]; + let mut v = 0; + let mut sign = 1; + let mut i = 0usize; + if data.starts_with(&[b'-']) { + *data = &data[1..]; + sign = -1; + } + + while data[i] >= b'0' && data[i] <= b'9' { + v = v * 10 + (data[i] - b'0') as i32; + *data = &data[1..]; + } + + node.get_or_insert(Rc::new(RefCell::new(TreeNode::new(-1)))) + .borrow_mut() + .val = v * sign; + } else if data.starts_with(&[b'}']) { + *data = &data[1..]; + return node; + } else { + *data = &data[1..]; + } + } + } +} From 19a5801e68307e2e273652b5aa8d8f527846dceb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 8 Feb 2023 09:23:39 +0800 Subject: [PATCH 0719/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cc4ca3da..7f989ef7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 404 | 174 | 207 | 23 | +| 405 | 174 | 207 | 24 | ### 题目 @@ -184,6 +184,7 @@ |287 | 寻找重复数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-duplicate-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-duplicate-number/) | Medium | |290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | |292 | Nim 游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nim-game.rs) | [leetcode](https://leetcode-cn.com/problems/nim-game/) | Easy | +|297 | 二叉树的序列化与反序列化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree/) | Hard | |300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | |303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | |318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | From 234d7e93e9a5b65d3eff4e55b11dda716b97ff80 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 8 Feb 2023 12:30:52 +0800 Subject: [PATCH 0720/1556] src/bin/sliding-window-maximum.rs --- src/bin/sliding-window-maximum.rs | 162 ++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 src/bin/sliding-window-maximum.rs diff --git a/src/bin/sliding-window-maximum.rs b/src/bin/sliding-window-maximum.rs new file mode 100644 index 00000000..6b641242 --- /dev/null +++ b/src/bin/sliding-window-maximum.rs @@ -0,0 +1,162 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + println!( + "{:?}", + Solution::max_sliding_window(vec![1, 3, -1, -3, 5, 3, 6, 7], 3) + ); + println!("{:?}", Solution::max_sliding_window(vec![1], 1)); + println!("{:?}", Solution::max_sliding_window(vec![1, -1], 1)); + let a = vec![ + 7238, 9932, -7015, 6020, 2596, 6189, -7315, 3176, -7751, 7995, 3970, 7008, 4059, 9310, + -3655, -8628, 3249, 6132, 9022, 8156, 8970, 7702, -8248, 9130, -1393, -6814, -8441, 9879, + -2811, 3564, 6491, 8875, -200, 8698, -6756, -5946, 2006, 7604, 7379, -4675, 3323, -544, + 544, 130, -1171, 6535, -6825, 4471, 3580, -1876, -5201, 7337, -3992, -3277, -8251, 5427, + 8989, 4481, -298, 5049, 9762, -4932, -7561, -8209, 1343, 2338, -8612, 5181, 95, 8312, 6140, + 9449, 9283, 5812, 2348, -57, -5351, 4471, 3738, 5256, -1644, -8322, -4507, -6337, 821, + 3626, 3804, 3957, 7675, 2195, 5933, 5699, 545, -3593, -760, 199, -7339, -6963, -8857, 5111, + -2086, -4285, 5260, -6824, -7696, -3032, -1368, -6605, 2119, 5660, 850, 4834, 3333, 7193, + 6465, 1137, -7826, 3972, -4014, -8963, 6244, -5914, 7196, 8119, 4804, -1212, 4780, -5600, + 8125, -5737, -2363, -5635, 3902, 4423, -3962, 7659, -2802, 9953, 6651, 3794, -7302, 5601, + -6981, -9579, 6382, -1355, 6387, 8293, -4281, 393, 507, 3554, -85, 6148, 9009, 9994, 3835, + -8033, -985, -9909, -2869, 1453, -1824, -7902, -5402, -4205, -187, -9707, 7666, 4167, 3762, + -8791, -1256, 9682, -9714, -597, 6671, -8381, -304, -4242, -5095, 6311, -7830, -1480, + -6470, 6264, 8859, -4593, 9514, 1430, 5248, 6556, 8422, -8424, -4742, -6497, -3416, -4005, + -4213, -4945, 6129, 4473, -4092, -6352, 490, -5252, -2591, -5388, 9398, -8349, 3329, -5143, + -5446, 9031, -6319, -4679, -7013, 867, -705, 7882, 5625, 6763, 954, 897, -2191, 4859, + -4321, 4058, 2535, -1918, -9012, -2708, 500, -5448, -3478, -6758, -935, 7277, 979, -2030, + -3152, 9066, -6420, 2590, -7793, -3197, 7510, 8948, -4362, 5464, -981, 4541, -6535, -4853, + -8182, 4128, -4434, 8901, -1384, 1166, -5818, -5866, 3158, -9958, -5805, -959, 4945, -8665, + -5298, 8831, 5525, 3577, -2783, 7743, 7145, -1839, -2936, -8183, 978, 2578, -6729, -7782, + 135, 7508, 7847, + ]; + let b = [ + 9932, 9932, 9310, 9310, 9310, 9310, 9310, 9310, 9310, 9879, 9879, 9879, 9879, 9879, 9879, + 9879, 9879, 9879, 9879, 9879, 9879, 9879, 9879, 9879, 9879, 9879, 9879, 9879, 8875, 8875, + 8875, 8875, 8698, 8698, 7604, 7604, 7604, 7604, 8989, 8989, 8989, 8989, 9762, 9762, 9762, + 9762, 9762, 9762, 9762, 9762, 9762, 9762, 9762, 9762, 9762, 9762, 9762, 9762, 9762, 9762, + 9762, 9449, 9449, 9449, 9449, 9449, 9449, 9449, 9449, 9449, 9449, 9449, 9283, 7675, 7675, + 7675, 7675, 7675, 7675, 7675, 7675, 7675, 7675, 7675, 7675, 7675, 7675, 7675, 7675, 5933, + 5933, 5699, 5660, 5660, 5660, 7193, 7193, 7193, 7193, 7193, 7193, 7193, 7193, 7193, 7196, + 8119, 8119, 8119, 8119, 8119, 8125, 8125, 8125, 8125, 8125, 8125, 8125, 8125, 8125, 9953, + 9953, 9953, 9953, 9953, 9953, 9953, 9953, 9953, 9953, 9953, 9953, 9953, 9953, 9953, 9953, + 9953, 9953, 9994, 9994, 9994, 9994, 9994, 9994, 9994, 9994, 9994, 9994, 9994, 9994, 9994, + 9994, 9994, 9994, 9994, 9994, 9994, 9682, 9682, 9682, 9682, 9682, 9682, 9682, 9682, 9682, + 9682, 9682, 9682, 9682, 9682, 9682, 9682, 9682, 9682, 9514, 9514, 9514, 9514, 9514, 9514, + 9514, 9514, 9514, 9514, 9514, 9514, 9514, 9514, 9514, 8422, 9398, 9398, 9398, 9398, 9398, + 9398, 9398, 9398, 9398, 9398, 9398, 9398, 9398, 9398, 9398, 9398, 9398, 9398, 9398, 9031, + 9031, 9031, 9031, 9031, 7882, 7882, 7882, 7882, 7882, 7882, 7277, 7277, 7277, 9066, 9066, + 9066, 9066, 9066, 9066, 9066, 9066, 9066, 9066, 9066, 9066, 9066, 9066, 9066, 9066, 9066, + 9066, 9066, 8948, 8948, 8948, 8948, 8948, 8948, 8901, 8901, 8901, 8901, 8901, 8901, 8901, + 8901, 8901, 8901, 8831, 8831, 8831, 8831, 8831, 8831, 8831, 8831, 8831, + ]; + + let c = Solution::max_sliding_window(a, 19); + + assert_eq!(c, b); +} + +struct Solution; + +impl Solution { + /// 使用大顶堆 + pub fn max_sliding_window1(nums: Vec, k: i32) -> Vec { + let mut heap = vec![]; + for i in 0..k as usize { + Self::heap_insert(&mut heap, (nums[i], i)); + } + + let mut r = vec![heap[0].0]; + + for i in k as usize..nums.len() { + Self::heap_remove(&mut heap, i - k as usize); + Self::heap_insert(&mut heap, (nums[i], i)); + r.push(heap[0].0); + } + + r + } + + /// 堆插入新的元素 + fn heap_insert(heap: &mut Vec<(i32, usize)>, val: (i32, usize)) { + heap.push(val); + let mut i = heap.len() - 1; + + while i > 0 && heap[(i - 1) / 2].0 < heap[i].0 { + heap.swap(i, (i - 1) / 2); + i = (i - 1) / 2; + } + } + + /// 堆移除元素中,下标大于k的数 + /// 先找到对应的元素 + fn heap_remove(heap: &mut Vec<(i32, usize)>, k: usize) { + while !heap.is_empty() && heap[0].1 <= k { + let last = heap.len() - 1; + heap.swap(0, last); + heap.pop(); + + let mut i = 0; + loop { + match (heap.get(2 * i + 1), heap.get(2 * i + 2)) { + (Some(&left), Some(&right)) => { + if left.0 >= heap[i].0 && right.0 >= heap[i].0 { + if left.0 > right.0 { + heap.swap(i, i * 2 + 1); + i = i * 2 + 1; + } else { + heap.swap(i, i * 2 + 2); + i = i * 2 + 2; + } + } else if left.0 >= heap[i].0 { + heap.swap(i, i * 2 + 1); + i = i * 2 + 1; + } else if right.0 >= heap[i].0 { + heap.swap(i, i * 2 + 2); + i = i * 2 + 2; + } else { + break; + } + } + (Some(&left), None) if left.0 >= heap[i].0 => { + heap.swap(i, 2 * i + 1); + i = i * 2 + 1; + } + + (None, Some(&right)) if right.0 >= heap[i].0 => { + heap.swap(i, 2 * i + 2); + i = i * 2 + 2; + } + _ => break, + } + } + } + } + + pub fn max_sliding_window(nums: Vec, k: i32) -> Vec { + let mut stack = vec![]; + stack.push(0usize); + for i in 1..k as usize { + while !stack.is_empty() && nums[stack[stack.len() - 1]] <= nums[i] { + stack.pop(); + } + stack.push(i); + } + let mut r = vec![nums[stack[0]]]; + + for i in k as usize..nums.len() { + if i - k as usize + 1 > stack[0] { + stack.remove(0); + } + + while !stack.is_empty() && nums[stack[stack.len() - 1]] <= nums[i] { + stack.pop(); + } + stack.push(i); + + r.push(nums[stack[0]]); + } + + r + } +} From 4c50813c4525315d079248d375faa58aff84a1eb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 8 Feb 2023 12:30:53 +0800 Subject: [PATCH 0721/1556] README.md --- README.md | 3 ++- src/bin/longest-valid-parentheses.rs | 6 ------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7f989ef7..3524e7a7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 405 | 174 | 207 | 24 | +| 406 | 174 | 207 | 25 | ### 题目 @@ -171,6 +171,7 @@ |235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | Easy | |236 | 二叉树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/) | Medium | |238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Medium | +|239 | 滑动窗口最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sliding-window-maximum.rs) | [leetcode](https://leetcode-cn.com/problems/sliding-window-maximum/) | Hard | |240 | 搜索二维矩阵 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix-ii/) | Medium | |242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | Easy | |257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | Easy | diff --git a/src/bin/longest-valid-parentheses.rs b/src/bin/longest-valid-parentheses.rs index 8635dfb1..f79238b6 100644 --- a/src/bin/longest-valid-parentheses.rs +++ b/src/bin/longest-valid-parentheses.rs @@ -21,12 +21,6 @@ fn main() { "{}", i.0 ); - assert_eq!( - Solution::stack_longest_valid_parentheses(i.0.into()), - i.1, - "{}", - i.0 - ); } } From 77f324622c3963626c90c60dff7a1fe0fb24075b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 9 Feb 2023 22:40:37 +0800 Subject: [PATCH 0722/1556] add some sort functions --- sort/src/bubble.rs | 19 ++++++++++++++++ sort/src/heap.rs | 37 +++++++++++++++++++++++++++++++ sort/src/insertion.rs | 13 +++++++++++ sort/src/lib.rs | 51 ++++++++++++++++++++++++++++++++++--------- sort/src/merge.rs | 49 +++++++++++++++++++++++++++++++++++++++++ sort/src/quick.rs | 6 ++--- sort/src/selection.rs | 15 +++++++++++++ 7 files changed, 177 insertions(+), 13 deletions(-) create mode 100644 sort/src/bubble.rs create mode 100644 sort/src/heap.rs create mode 100644 sort/src/insertion.rs create mode 100644 sort/src/merge.rs create mode 100644 sort/src/selection.rs diff --git a/sort/src/bubble.rs b/sort/src/bubble.rs new file mode 100644 index 00000000..942e9029 --- /dev/null +++ b/sort/src/bubble.rs @@ -0,0 +1,19 @@ +/// 冒泡排序 +/// 从第一个元素开始挨个与后面的元素比较,前面大于后面则交换顺序,到最后一个元素一定是最大的那一个。 +/// 重复前一步 +/// 优化:如果一段连续到元素到列表末尾都没有交换过,说明此段连续元素都是有序的,因此不需要再次遍历比较这一段。 +pub fn sort(target: &mut [T]) { + let mut i = target.len(); + + while i > 0 { + let mut sort_index = i - 1; + for j in 0..i - 1 { + if target[j] > target[j + 1] { + sort_index = j + 1; + target.swap(j, j + 1); + } + } + + i = sort_index; + } +} diff --git a/sort/src/heap.rs b/sort/src/heap.rs new file mode 100644 index 00000000..f4913b50 --- /dev/null +++ b/sort/src/heap.rs @@ -0,0 +1,37 @@ +/// 构建一个大顶堆,然后去掉第一个元素再构建大顶堆 +pub fn sort(target: &mut [T]) { + if target.is_empty() { + return; + } + + for i in (0..(target.len() - 1) / 2).rev() { + heapfiy(target, i); + } + + let mut target = target; + + let len = target.len(); + for i in (0..len).rev() { + target.swap(0, i); // 堆定与最后一个元素交换 + + target = &mut target[0..i]; + heapfiy(target, 0); + } +} + +/// 从 n / 2 开始,因为后半部分一定是叶子结点。 +fn heapfiy(target: &mut [T], mut middle: usize) { + while middle * 2 + 1 < target.len() { + let mut max = middle * 2 + 1; + if middle * 2 + 2 < target.len() && target[max] < target[middle * 2 + 2] { + max = middle * 2 + 2; + } + + if target[middle] < target[max] { + target.swap(max, middle); + middle = max; + } else { + break; + } + } +} diff --git a/sort/src/insertion.rs b/sort/src/insertion.rs new file mode 100644 index 00000000..469d4846 --- /dev/null +++ b/sort/src/insertion.rs @@ -0,0 +1,13 @@ +/// 插入排序,遍历一个数,把它插入到前面合适的位置,其他的数往后移动 +pub fn sort(target: &mut [T]) { + for mut i in 1..target.len() { + for j in (0..i).rev() { + if target[j] > target[i] { + target.swap(i, j); + i = j; + } else { + break; + } + } + } +} diff --git a/sort/src/lib.rs b/sort/src/lib.rs index c466b70f..407c3531 100644 --- a/sort/src/lib.rs +++ b/sort/src/lib.rs @@ -1,19 +1,50 @@ +pub mod bubble; +pub mod heap; +pub mod insertion; +pub mod merge; pub mod quick; +pub mod selection; -pub use quick::quick_sort; +pub use bubble::sort as bubble_sort; +pub use heap::sort as heap_sort; +pub use insertion::sort as insertion_sort; +pub use merge::sort as merge_sort; +pub use quick::sort as quick_sort; +pub use selection::sort as selection_sort; #[cfg(test)] mod tests { - use super::*; + macro_rules! test_case { + ($($func_name:ident),+) => { + $( + #[test] + fn $func_name() { + use super::$func_name as sort; + let s = "The Waker type allows for a loose coupling between the reactor-part and the executor-part of a runtime"; + let mut m: Vec = s.split(" ").map(|x| x.to_string()).collect(); + let mut m1 = m.clone(); + sort(&mut m1); + m.sort(); - #[test] - fn test_sort() { - let s = "The Waker type allows for a loose coupling between the reactor-part and the executor-part of a runtime"; - let mut m: Vec = s.split(" ").map(|x| x.to_string()).collect(); - let mut m1 = m.clone(); - quick_sort(&mut m1); - m.sort(); + assert_eq!(m, m1); - assert_eq!(m, m1); + let mut m = vec![32,12,243,42,321,543,3213,21,33,5443,5,433]; + let mut m1 = m.clone(); + sort(&mut m1); + m.sort(); + + assert_eq!(m, m1); + } + )* + }; + } + + test_case! { + bubble_sort, + quick_sort, + selection_sort, + heap_sort, + insertion_sort, + merge_sort } } diff --git a/sort/src/merge.rs b/sort/src/merge.rs new file mode 100644 index 00000000..4b91e352 --- /dev/null +++ b/sort/src/merge.rs @@ -0,0 +1,49 @@ +/// 把序列分割成n个小块,然后再合并这n个小块 +pub fn sort(target: &mut [T]) { + merge(target); +} + +fn merge(target: &mut [T]) { + if target.is_empty() || target.len() == 1 { + return; + } + + if target.len() == 2 { + if target[0] > target[1] { + target.swap(0, 1); + } + return; + } + let len = target.len(); + + merge(&mut target[0..len >> 1]); + merge(&mut target[len >> 1..len]); + + // 合并两段, 使用双指针 + // p3 是 v的索引 + let (mut p1, mut p2, mut p3) = (0, len >> 1, 0); + + let v: Vec = target[0..len >> 1].into_iter().map(|x| x.clone()).collect(); + + while p1 < len { + if p2 < len && p3 < v.len() { + if target[p2] > v[p3] { + target[p1] = v[p3].clone(); + p3 += 1; + } else { + target[p1] = target[p2].clone(); + p2 += 1; + } + } else if p2 < len { + target[p1] = target[p2].clone(); + p2 += 1; + } else if p3 < v.len() { + target[p1] = v[p3].clone(); + p3 += 1; + } else { + return; + } + + p1 += 1; + } +} diff --git a/sort/src/quick.rs b/sort/src/quick.rs index 55d53c0a..a0ad0473 100644 --- a/sort/src/quick.rs +++ b/sort/src/quick.rs @@ -8,7 +8,7 @@ /// 6.再次重复2-5步,直到begin == end为止 /// 7.最后s[begin] = p /// 8.递归快速排序以begin为分界线的两部分序列 -pub fn quick_sort(target: &mut [T]) { +pub fn sort(target: &mut [T]) { if target.len() < 2 { return; } @@ -41,6 +41,6 @@ pub fn quick_sort(target: &mut [T]) { target[begin] = p; - quick_sort(&mut target[..begin]); - quick_sort(&mut target[begin + 1..]); + sort(&mut target[..begin]); + sort(&mut target[begin + 1..]); } diff --git a/sort/src/selection.rs b/sort/src/selection.rs new file mode 100644 index 00000000..60dd94a4 --- /dev/null +++ b/sort/src/selection.rs @@ -0,0 +1,15 @@ +/// 从头开始遍历,遍历到最大的元素,与最后一个元素交换 +/// 然后又从头开始遍历,直到遍历完成为止 +pub fn sort(target: &mut [T]) { + for i in (0..target.len()).rev() { + let mut max = 0; + + for j in 0..=i { + if target[j] > target[max] { + max = j; + } + } + + target.swap(max, i); + } +} From fbc24e1b8eb8726f5070bf86251415146240128c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 13 Feb 2023 22:20:07 +0800 Subject: [PATCH 0723/1556] add quick sort --- sort/src/quick.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sort/src/quick.rs b/sort/src/quick.rs index a0ad0473..9f0e9081 100644 --- a/sort/src/quick.rs +++ b/sort/src/quick.rs @@ -32,7 +32,7 @@ pub fn sort(target: &mut [T]) { std::cmp::Ordering::Less => { target[end] = target[begin].clone(); end -= 1; - break; + break; } _ => begin += 1, } From f06593f759388cf6fc5d6421bf4cddcb45bca9e8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 14 Feb 2023 09:37:51 +0800 Subject: [PATCH 0724/1556] src/bin/7WHec2.rs --- src/bin/7WHec2.rs | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/bin/7WHec2.rs diff --git a/src/bin/7WHec2.rs b/src/bin/7WHec2.rs new file mode 100644 index 00000000..9f721a6c --- /dev/null +++ b/src/bin/7WHec2.rs @@ -0,0 +1,77 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} +impl Solution { + /// 归并排序 + pub fn sort_list(mut head: Option>) -> Option> { + let mut length = 0; + let mut ptr = head.as_ref(); + + while ptr.is_some() { + length += 1; + ptr = ptr.and_then(|x| x.next.as_ref()); + } + + Self::sort(head, length) + } + + pub fn sort(mut head: Option>, length: i32) -> Option> { + if head.is_none() || head.as_ref().unwrap().next.is_none() { + return head; + } + + let mut middle = head.as_mut(); + + for _j in 0..length / 2 - 1 { + middle = middle.and_then(|x| x.next.as_mut()); + } + + let right = middle.and_then(|x| x.next.take()); + + let mut right = Self::sort(right, length - (length / 2)); + let mut left = Self::sort(head, length / 2); + + let mut ans = Some(Box::new(ListNode::new(-1))); + let mut current = &mut ans.as_mut().unwrap().next; + + while left.is_some() || right.is_some() { + if left.is_none() { + current.insert(right.unwrap()); + break; + } else if right.is_none() { + current.insert(left.unwrap()); + break; + } else { + if left.as_ref().unwrap().val < right.as_ref().unwrap().val { + let new_left = left.as_mut().unwrap().next.take(); + current.insert(left.unwrap()); + left = new_left; + } else { + let new_right = right.as_mut().unwrap().next.take(); + current.insert(right.unwrap()); + right = new_right; + } + + current = &mut current.as_mut().unwrap().next; + } + } + + ans.and_then(|mut x| x.next.take()) + } +} From 135a588752db148792bba7e26bfa11da3de7e54a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 14 Feb 2023 09:37:52 +0800 Subject: [PATCH 0725/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3524e7a7..81fa2dec 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 406 | 174 | 207 | 25 | +| 407 | 174 | 208 | 25 | ### 题目 @@ -414,3 +414,4 @@ |100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | |1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | +|1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From f096b9064a91db90992b35d256985a29a5fcb691 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 15 Feb 2023 09:40:13 +0800 Subject: [PATCH 0726/1556] add new version longest-increasing-subsequence --- src/bin/longest-increasing-subsequence.rs | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/bin/longest-increasing-subsequence.rs b/src/bin/longest-increasing-subsequence.rs index 6a8da25e..c346f25d 100644 --- a/src/bin/longest-increasing-subsequence.rs +++ b/src/bin/longest-increasing-subsequence.rs @@ -7,11 +7,20 @@ fn main() { ); println!("{}", Solution::length_of_lis(vec![0, 1, 0, 3, 2, 3])); println!("{}", Solution::length_of_lis(vec![7, 7, 7, 7, 7, 7, 7])); + + println!( + "{}", + Solution::length_of_lis1(vec![10, 9, 2, 5, 3, 7, 101, 18]) + ); + println!("{}", Solution::length_of_lis1(vec![0, 1, 0, 3, 2, 3])); + println!("{}", Solution::length_of_lis1(vec![7, 7, 7, 7, 7, 7, 7])); } struct Solution; impl Solution { + /// 动态规划 + /// dp[i] = max(dp[j] + 1, dp[i]), 0 <= j <= i && nums[j] < nums[i] pub fn length_of_lis(nums: Vec) -> i32 { let mut v = vec![1; nums.len()]; @@ -25,4 +34,41 @@ impl Solution { v.into_iter().fold(0, |x, y| x.max(y)) } + + /// 动态规划 + 二分查找 + /// 比如序列是78912345,前三个遍历完以后tail是789, + /// 这时候遍历到1,就得把1放到合适的位置, + /// 于是在tail二分查找1的位置,变成了189(如果序列在此时结束,因为res不变,所以依旧输出3), + /// 再遍历到2成为129,然后是123直到12345 + /// + /// 很具小巧思。新建数组 cell,用于保存最长上升子序列。 + /// 对原序列进行遍历,将每位元素二分插入 cell 中。 + /// 如果 cell 中元素都比它小,将它插到最后 + /// 否则,用它覆盖掉比它大的元素中最小的那个。 + /// 总之,思想就是让 cell 中存储比较小的元素。这样,cell 未必是真实的最长上升子序列,但长度是对的。 + pub fn length_of_lis1(nums: Vec) -> i32 { + let mut v = vec![nums[0]]; + + for &num in &nums[1..] { + if num > v[v.len() - 1] { + v.push(num); + continue; + } + + let (mut i, mut j) = (0, v.len() - 1); + + while i < j { + let middle = (i + j) / 2; + if v[middle] < num { + i = middle + 1; + } else { + j = middle; + } + } + + v[i] = num; + } + + v.len() as i32 + } } From 501313107ecf8c3025ef74502587728c16e83c33 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 15 Feb 2023 12:49:41 +0800 Subject: [PATCH 0727/1556] src/bin/best-time-to-buy-and-sell-stock-with-cooldown.rs --- ...ime-to-buy-and-sell-stock-with-cooldown.rs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bin/best-time-to-buy-and-sell-stock-with-cooldown.rs diff --git a/src/bin/best-time-to-buy-and-sell-stock-with-cooldown.rs b/src/bin/best-time-to-buy-and-sell-stock-with-cooldown.rs new file mode 100644 index 00000000..3331d4ea --- /dev/null +++ b/src/bin/best-time-to-buy-and-sell-stock-with-cooldown.rs @@ -0,0 +1,40 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::max_profit(vec![1, 2, 3, 0, 2]), 3); + assert_eq!(Solution::max_profit(vec![1]), 0); +} + +struct Solution; + +impl Solution { + /// 第i天有几种状态 + /// 1.持有股票,这时可能是持有的第i-1天的股票,或者是新买的股票 + /// 2.没有股票且处于冻结期(当天把股票卖了) + /// 3.没有股票且不处于冻结期 + /// + /// f[i][0]代表第一种情况 + /// f[i][2]代表第二种情况 + /// f[i][3]代表第三种情况 + /// + /// f[i][0] = max(f[i-1][2]-price, f[i-1][0]) + /// f[i][1] = f[i-1][0]+price + /// f[i][2] = max(f[i-1][2], f[i-1][1]) + pub fn max_profit(prices: Vec) -> i32 { + // 使用三个变量替代 + // let mut v = vec![vec![0; 3]; prices.len()]; + // v[0][0] = -prices[0]; + let (mut v0, mut v1, mut v2) = (-prices[0], 0, 0); + + for index in 1..prices.len() { + let new_v0 = v0.max(v2 - prices[index]); + let new_v1 = v0 + prices[index]; + let new_v2 = v1.max(v2); + + v0 = new_v0; + v1 = new_v1; + v2 = new_v2; + } + v0.max(v1).max(v2) + } +} From 542ad923aa4bc534e0b0d4402fd2feb2ddd447ec Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 15 Feb 2023 12:49:42 +0800 Subject: [PATCH 0728/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 81fa2dec..fb8464f9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 407 | 174 | 208 | 25 | +| 408 | 174 | 209 | 25 | ### 题目 @@ -188,6 +188,7 @@ |297 | 二叉树的序列化与反序列化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree/) | Hard | |300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | |303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | +|309 | 最佳买卖股票时机含冷冻期 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-with-cooldown.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/) | Medium | |318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | |319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | |322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | From ce45b5458e8e6957f809d6aeaa889035510097c2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 16 Feb 2023 13:39:12 +0800 Subject: [PATCH 0729/1556] src/bin/house-robber-iii.rs --- src/bin/house-robber-iii.rs | 89 +++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/bin/house-robber-iii.rs diff --git a/src/bin/house-robber-iii.rs b/src/bin/house-robber-iii.rs new file mode 100644 index 00000000..bcb44fe4 --- /dev/null +++ b/src/bin/house-robber-iii.rs @@ -0,0 +1,89 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::cell::RefCell; +use std::rc::Rc; + +impl Solution { + // 每个节点都有偷或者不偷两种情况 + pub fn force_rob(root: Option>>) -> i32 { + Self::r(root.clone(), true).max(Self::r(root.clone(), false)) + } + + pub fn r(root: Option>>, steal: bool) -> i32 { + if root.is_none() { + return 0; + } + + let mut r = 0; + // 如果当前节点可以偷,那么下一个节点就不能偷 + let r1 = if steal { + let mut r1 = root.clone().unwrap().borrow().val; + r1 += Self::r(root.clone().unwrap().borrow().left.clone(), false); + r1 += Self::r(root.clone().unwrap().borrow().right.clone(), false); + r1 + } else { + // 如果当前节点不能偷,那么下一个节点可偷可不偷 + let mut r1 = 0; + r1 += Self::r(root.clone().unwrap().borrow().left.clone(), true) + .max(Self::r(root.clone().unwrap().borrow().left.clone(), false)); + r1 += Self::r(root.clone().unwrap().borrow().right.clone(), true) + .max(Self::r(root.clone().unwrap().borrow().right.clone(), false)); + r1 + }; + + r1 + } + + /// 每个节点都有偷或者不偷两种情况 + /// 先计算高度,然后每个节点都有偷或者不偷两种情况,因此 + /// i节点的最大值 = max(i节点可偷值 + i的子节点不偷的情况下的值, i节点不可偷+i的左子节点可偷+i右子节点可偷, i节点不可偷+i的左子节点不可偷+i右子节点不可偷, i节点不可偷+i的左子节点可偷+i右子节点不可偷, i节点不可偷+i的左子节点不可偷+i右子节点可偷) + /// 因此定义 + pub fn rob(root: Option>>) -> i32 { + let r = Self::r1(root); + + r.0.max(r.1) + } + + /// 设ans为返回值 + /// ans.0表示选择此节点的值 + /// ans.1表示不选择此节点的值 + /// 则: + /// ans.0 = l.1 + r.1 + node.val + /// ans.1 = l.0.max(l.1) + r.0.max(r.1) + fn r1(root: Option>>) -> (i32, i32) { + if root.is_none() { + return (0, 0); + } + + let l = Self::r1(root.clone().unwrap().borrow().left.clone()); + let r = Self::r1(root.clone().unwrap().borrow().right.clone()); + + ( + l.1 + r.1 + root.unwrap().borrow().val, + l.0.max(l.1) + r.0.max(r.1), + ) + } +} From 17417a0ff8ec258d860ef37ee1d783d917a5563a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 16 Feb 2023 13:39:13 +0800 Subject: [PATCH 0730/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fb8464f9..30e443dc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 408 | 174 | 209 | 25 | +| 409 | 174 | 210 | 25 | ### 题目 @@ -193,6 +193,7 @@ |319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | |322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | |326 | 3 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | +|337 | 打家劫舍 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-iii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-iii/) | Medium | |344 | 反转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string/) | Easy | |345 | 反转字符串中的元音字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-vowels-of-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-vowels-of-a-string/) | Easy | |349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | From 46218482da666708ff3e0707ed107c3ffa4a85b7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 17 Feb 2023 08:24:45 +0800 Subject: [PATCH 0731/1556] src/bin/counting-bits.rs --- src/bin/counting-bits.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/counting-bits.rs diff --git a/src/bin/counting-bits.rs b/src/bin/counting-bits.rs new file mode 100644 index 00000000..2e288c69 --- /dev/null +++ b/src/bin/counting-bits.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() { + assert_eq!(Solution::count_bits(5), vec![0, 1, 1, 2, 1, 2]); + assert_eq!( + Solution::count_bits(10), + vec![0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2] + ); +} + +struct Solution; + +impl Solution { + pub fn count_bits(n: i32) -> Vec { + if n == 0 { + return vec![0]; + } + + let mut r = vec![0; n as usize + 1]; + let mut start = 0; + let mut mask = 1; + for i in 1..=n as usize { + if i == mask { + start = 0; + mask *= 2; + } + + r[i] = r[start] + 1; + start += 1; + } + + r + } +} From 93128178246092e866906be630e41d5260659cee Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 17 Feb 2023 08:24:46 +0800 Subject: [PATCH 0732/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 30e443dc..6b29b80a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 409 | 174 | 210 | 25 | +| 410 | 175 | 210 | 25 | ### 题目 @@ -194,6 +194,7 @@ |322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | |326 | 3 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | |337 | 打家劫舍 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-iii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-iii/) | Medium | +|338 | 比特位计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-bits.rs) | [leetcode](https://leetcode-cn.com/problems/counting-bits/) | Easy | |344 | 反转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string/) | Easy | |345 | 反转字符串中的元音字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-vowels-of-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-vowels-of-a-string/) | Easy | |349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | From cd08e09a56394746b086b7975aee05ad00b1347b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 17 Feb 2023 09:30:03 +0800 Subject: [PATCH 0733/1556] src/bin/top-k-frequent-elements.rs --- src/bin/top-k-frequent-elements.rs | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/bin/top-k-frequent-elements.rs diff --git a/src/bin/top-k-frequent-elements.rs b/src/bin/top-k-frequent-elements.rs new file mode 100644 index 00000000..ce7c92fa --- /dev/null +++ b/src/bin/top-k-frequent-elements.rs @@ -0,0 +1,84 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() { + assert_eq!( + Solution::top_k_frequent(vec![1, 1, 1, 2, 2, 3], 2), + vec![2, 1] + ); + + assert_eq!(Solution::top_k_frequent(vec![1], 1), vec![1]); + assert_eq!(Solution::top_k_frequent(vec![3, 0, 1, 0], 1), vec![0]); +} + +struct Solution; + +impl Solution { + /// 先获取数字对应的次数,再用小顶堆,再遍历堆 + pub fn top_k_frequent(nums: Vec, k: i32) -> Vec { + let mut hash = std::collections::HashMap::new(); + + for i in nums { + hash.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + + let mut heap = vec![]; + + for (x, y) in hash { + Self::buildHeap(&mut heap, k as usize, (x, y)); + } + + heap.into_iter().map(|x| x.0).collect() + } + + fn buildHeap(heap: &mut Vec<(i32, i32)>, length: usize, elem: (i32, i32)) { + if heap.len() == length { + if heap[0].1 < elem.1 { + // 先删除掉第一个元素 + heap.swap(0, length - 1); + heap.remove(length - 1); + let mut start = 0; + // 堆顶向下比较 + while start < length { + if start * 2 + 1 < heap.len() && start * 2 + 2 < heap.len() { + let mut min = start * 2 + 1; + if heap[start * 2 + 1].1 > heap[start * 2 + 2].1 { + min = start * 2 + 2; + } + + if heap[min].1 < heap[start].1 { + heap.swap(start, min); + start = min; + } else { + break; + } + } else if start * 2 + 1 < heap.len() { + if heap[start * 2 + 1].1 < heap[start].1 { + heap.swap(start, start * 2 + 1); + start = start * 2 + 1; + } else { + break; + } + } else { + break; + } + } + } else { + return; + } + } + + heap.push(elem); + let mut start = heap.len() - 1; + + while start > 0 { + if heap[(start - 1) / 2].1 > heap[start].1 { + heap.swap(start, (start - 1) / 2); + start = (start - 1) / 2; + } else { + return; + } + } + } +} From 8e952d1957de3299b007f6f5e73868535fabfbd3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 17 Feb 2023 09:30:04 +0800 Subject: [PATCH 0734/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b29b80a..a3fb1811 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 410 | 175 | 210 | 25 | +| 411 | 175 | 211 | 25 | ### 题目 @@ -197,6 +197,7 @@ |338 | 比特位计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-bits.rs) | [leetcode](https://leetcode-cn.com/problems/counting-bits/) | Easy | |344 | 反转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string/) | Easy | |345 | 反转字符串中的元音字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-vowels-of-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-vowels-of-a-string/) | Easy | +|347 | 前 K 个高频元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/top-k-frequent-elements.rs) | [leetcode](https://leetcode-cn.com/problems/top-k-frequent-elements/) | Medium | |349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | |350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | |357 | 统计各位数字都不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | From d3e0f128d5dfc7798116e7937008e98f06a0cafe Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 18 Feb 2023 12:06:15 +0800 Subject: [PATCH 0735/1556] src/bin/queue-reconstruction-by-height.rs --- src/bin/queue-reconstruction-by-height.rs | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/bin/queue-reconstruction-by-height.rs diff --git a/src/bin/queue-reconstruction-by-height.rs b/src/bin/queue-reconstruction-by-height.rs new file mode 100644 index 00000000..dbef04f4 --- /dev/null +++ b/src/bin/queue-reconstruction-by-height.rs @@ -0,0 +1,59 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!( + Solution::reconstruct_queue(vec![ + vec![7, 0], + vec![4, 4], + vec![7, 1], + vec![5, 0], + vec![6, 1], + vec![5, 2] + ]), + vec![ + vec![5, 0], + vec![7, 0], + vec![5, 2], + vec![6, 1], + vec![4, 4], + vec![7, 1] + ] + ) +} + +struct Solution; + +impl Solution { + /// 对于最矮的人来说,前面有n个人就说明他的位置是n+1 + /// 因此先按小到大排序,遍历已经寻找到为止的数组 + /// 当出现空位置或者出现高于的人,说明前面可以放一定数量的人。 + pub fn reconstruct_queue(people: Vec>) -> Vec> { + let mut people = people; + let mut v = vec![vec![]; people.len()]; + people.sort(); + + for i in people { + let mut k = i[1]; + let mut index = 0; + + while index < v.len() - 1 { + if v[index].is_empty() { + if k == 0 { + break; + } + k -= 1; + } else { + if v[index][0] >= i[0] { + k -= 1; + } + } + + index += 1; + } + + v[index] = i; + } + + v + } +} From 614cb4bbc036ccb0a7bd15d2ef125d69fecdf96a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 18 Feb 2023 12:06:16 +0800 Subject: [PATCH 0736/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a3fb1811..0942dd1d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 411 | 175 | 211 | 25 | +| 412 | 175 | 212 | 25 | ### 题目 @@ -220,6 +220,7 @@ |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |400 | 第 N 位数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nth-digit.rs) | [leetcode](https://leetcode-cn.com/problems/nth-digit/) | Medium | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | +|406 | 根据身高重建队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/queue-reconstruction-by-height.rs) | [leetcode](https://leetcode-cn.com/problems/queue-reconstruction-by-height/) | Medium | |409 | 最长回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindrome/) | Easy | |412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | |413 | 等差数列划分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/arithmetic-slices.rs) | [leetcode](https://leetcode-cn.com/problems/arithmetic-slices/) | Medium | From 7c384756fa4b5fd4e04e6905412293bd628c6d14 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 19 Feb 2023 22:14:51 +0800 Subject: [PATCH 0737/1556] src/bin/find-all-anagrams-in-a-string.rs --- src/bin/find-all-anagrams-in-a-string.rs | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/bin/find-all-anagrams-in-a-string.rs diff --git a/src/bin/find-all-anagrams-in-a-string.rs b/src/bin/find-all-anagrams-in-a-string.rs new file mode 100644 index 00000000..96ed9f91 --- /dev/null +++ b/src/bin/find-all-anagrams-in-a-string.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 滑动窗口 + /// 记录滑动窗口里面的元素个数和p的元素个数是否相同,相同则表示满足条件 + pub fn find_anagrams(s: String, p: String) -> Vec { + if s.len() < p.len() { + return Vec::new(); + } + + let mut ans = vec![]; + let mut p_count = [0; 26]; + + for &i in p.as_bytes() { + p_count[(i - b'a') as usize] += 1; + } + + let mut s_count = [0; 26]; + + let bytes = s.as_bytes(); + + for i in 0..s.len() { + if i < p.len() { + s_count[(bytes[i] - b'a') as usize] += 1; + } else { + s_count[(bytes[i] - b'a') as usize] += 1; + s_count[(bytes[i - p.len()] - b'a') as usize] -= 1; + } + + if s_count == p_count { + ans.push((i - p.len() + 1) as i32); + } + } + + ans + } +} From 2623cd37b2a82de54eae53921bb6f44eaa394577 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 19 Feb 2023 22:14:52 +0800 Subject: [PATCH 0738/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0942dd1d..b45c2acf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 412 | 175 | 212 | 25 | +| 413 | 175 | 213 | 25 | ### 题目 @@ -228,6 +228,7 @@ |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | +|438 | 找到字符串中所有字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-anagrams-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-anagrams-in-a-string/) | Medium | |442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | |445 | 两数相加 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers-ii.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers-ii/) | Medium | |448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | From 2838d30e0edb073d3e80a2e54b58afc0c7e3554c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 20 Feb 2023 08:31:23 +0800 Subject: [PATCH 0739/1556] src/bin/hamming-distance.rs --- src/bin/hamming-distance.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/hamming-distance.rs diff --git a/src/bin/hamming-distance.rs b/src/bin/hamming-distance.rs new file mode 100644 index 00000000..ea6cd9e4 --- /dev/null +++ b/src/bin/hamming-distance.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn hamming_distance(x: i32, y: i32) -> i32 { + let mut a = x ^ y; + let mut r = 0; + + while a > 0 { + if a & 1 == 1 { + r += 1; + } + + a >>= 1; + } + + r + } + + /// s & s-1能去掉最后一个1 + /// 比如 s = 0b11001000 + /// 则 s - 1 = 0b11000111 + /// s & s1 = 0b11000000 去掉了第三个1 + pub fn hamming_distance1(x: i32, y: i32) -> i32 { + let (mut s, mut r) = (x ^ y, 0); + while s > 0 { + s = s & (s - 1); + r += 1; + } + + r + } +} From e4244217c8720677c3b1abbd100a337ed4c87c30 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 20 Feb 2023 08:31:23 +0800 Subject: [PATCH 0740/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b45c2acf..eed33937 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 413 | 175 | 213 | 25 | +| 414 | 176 | 213 | 25 | ### 题目 @@ -233,6 +233,7 @@ |445 | 两数相加 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers-ii.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers-ii/) | Medium | |448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | |449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | +|461 | 汉明距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/hamming-distance.rs) | [leetcode](https://leetcode-cn.com/problems/hamming-distance/) | Easy | |476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | From 1e045a7a08ee82e1349fc93cad8e7f30802dcb4d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 21 Feb 2023 09:36:32 +0800 Subject: [PATCH 0741/1556] src/bin/convert-bst-to-greater-tree.rs --- src/bin/convert-bst-to-greater-tree.rs | 99 ++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/bin/convert-bst-to-greater-tree.rs diff --git a/src/bin/convert-bst-to-greater-tree.rs b/src/bin/convert-bst-to-greater-tree.rs new file mode 100644 index 00000000..75e993ca --- /dev/null +++ b/src/bin/convert-bst-to-greater-tree.rs @@ -0,0 +1,99 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; + +impl Solution { + /// 先求出总和 + /// 因为中序遍历是按大小遍历的,所以记录下前缀和,则当前节点的 + pub fn convert_bst1(root: Option>>) -> Option>> { + if root.is_none() { + return None; + } + let mut total = 0; + let mut stack = vec![root.clone()]; + while !stack.is_empty() { + let s = stack.pop().unwrap(); + total += s.clone().unwrap().borrow().val; + if s.clone().unwrap().borrow().left.is_some() { + stack.push(s.clone().unwrap().borrow().left.clone()); + } + + if s.clone().unwrap().borrow().right.is_some() { + stack.push(s.clone().unwrap().borrow().right.clone()); + } + } + + Self::retrive1(root.clone(), total); + + root + } + + /// 输入前缀和 + /// 当前节点的和 = total - left节点的和 + fn retrive1(root: Option>>, total: i32) -> i32 { + if root.is_none() { + return 0; + } + let mut prefix_sum = 0; + // 左节点 + prefix_sum += Self::retrive1(root.clone().unwrap().borrow().left.clone(), total); + + let val = root.clone().unwrap().borrow().val; + + // 当前root的和为total - 左节点的前缀和 + root.clone().unwrap().borrow_mut().val = total - prefix_sum; + prefix_sum += val; + + // 右节点 + prefix_sum += Self::retrive1( + root.clone().unwrap().borrow().right.clone(), + total - prefix_sum, + ); + + prefix_sum + } + + /// 倒叙中序遍历, 右,中,左的顺序遍历 + pub fn convert_bst(root: Option>>) -> Option>> { + let mut sum = 0; + + Self::retive(root.clone(), &mut sum); + root + } + + pub fn retive(root: Option>>, sum: &mut i32) { + if root.is_none() { + return; + } + + Self::retive(root.clone().unwrap().borrow().right.clone(), sum); + + *sum += root.clone().unwrap().borrow().val; + root.clone().unwrap().borrow_mut().val = *sum; + + Self::retive(root.clone().unwrap().borrow().left.clone(), sum); + } +} From 9f3c55577519aa36edb51058260f73a9c93774b6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 21 Feb 2023 09:36:33 +0800 Subject: [PATCH 0742/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eed33937..c14d1103 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 414 | 176 | 213 | 25 | +| 415 | 176 | 214 | 25 | ### 题目 @@ -249,6 +249,7 @@ |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | |530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | |535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | +|538 | 把二叉搜索树转换为累加树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-bst-to-greater-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-bst-to-greater-tree/) | Medium | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |560 | 和为 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | |565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | From b672756639356338fa2e8ac8ce5f478cf0be52c7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 21 Feb 2023 09:48:50 +0800 Subject: [PATCH 0743/1556] src/bin/diameter-of-binary-tree.rs --- src/bin/diameter-of-binary-tree.rs | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/bin/diameter-of-binary-tree.rs diff --git a/src/bin/diameter-of-binary-tree.rs b/src/bin/diameter-of-binary-tree.rs new file mode 100644 index 00000000..60877ef4 --- /dev/null +++ b/src/bin/diameter-of-binary-tree.rs @@ -0,0 +1,49 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + /// 左边的最深度 + 右边的最深度 + pub fn diameter_of_binary_tree(root: Option>>) -> i32 { + let (_, r) = Self::height(root); + r + } + + /// 返回深度和对应节点上的最大直径 + pub fn height(root: Option>>) -> (i32, i32) { + if root.is_none() { + return (0, 0); + } + + let (left, max_left) = Self::height(root.clone().unwrap().borrow().left.clone()); + let (right, max_right) = Self::height(root.clone().unwrap().borrow().right.clone()); + + ( + left.max(right) + 1, + (left + right).max(max_left).max(max_right), + ) + } +} From f53743cb946732eb78502925cbac926087733de0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 21 Feb 2023 09:48:51 +0800 Subject: [PATCH 0744/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c14d1103..9fee57eb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 415 | 176 | 214 | 25 | +| 416 | 177 | 214 | 25 | ### 题目 @@ -250,6 +250,7 @@ |530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | |535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |538 | 把二叉搜索树转换为累加树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-bst-to-greater-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-bst-to-greater-tree/) | Medium | +|543 | 二叉树的直径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diameter-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/diameter-of-binary-tree/) | Easy | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |560 | 和为 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | |565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | From 4b70752b777e0727e37011d640c99b87162e3d8b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 22 Feb 2023 10:49:53 +0800 Subject: [PATCH 0745/1556] src/bin/shortest-unsorted-continuous-subarray.rs --- .../shortest-unsorted-continuous-subarray.rs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/bin/shortest-unsorted-continuous-subarray.rs diff --git a/src/bin/shortest-unsorted-continuous-subarray.rs b/src/bin/shortest-unsorted-continuous-subarray.rs new file mode 100644 index 00000000..36f2ac0b --- /dev/null +++ b/src/bin/shortest-unsorted-continuous-subarray.rs @@ -0,0 +1,64 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 普通法 + /// 排序,挨个比较 + pub fn find_unsorted_subarray1(nums: Vec) -> i32 { + let mut n = nums.clone(); + n.sort(); + let (mut start, mut end) = (-1, -1); + + for i in 0..nums.len() { + if nums[i] != n[i] { + if start == -1 { + start = i as i32; + } else { + end = i as i32; + } + } + } + + if start == -1 { + 0 + } else { + end - start + 1 + } + } + + // pub fn find_unsorted_subarray(nums: Vec) -> i32 { + // let mut start = 0; + // let mut end = nums.len() - 1; + + // for i in 1..nums.len() { + // if nums[i] > nums[i - 1] { + // start = i; + // } else { + // break; + // } + // } + + // for i in (0..nums.len() - 1).rev() { + // if nums[i] < nums[i + 1] { + // end = i; + // } else { + // break; + // } + // } + + // for i in start..end { + // while nums[i] < nums[start] { + // start -= 1; + // } + + // while nums[i] > nums[end] { + // end += 1; + // } + // } + + // (end - start + 1) as i32 + // } +} From 5d0ea36594365b5a3915ec83bf6d8169b2661159 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 22 Feb 2023 10:49:54 +0800 Subject: [PATCH 0746/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9fee57eb..eb01aab3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 416 | 177 | 214 | 25 | +| 417 | 177 | 215 | 25 | ### 题目 @@ -254,6 +254,7 @@ |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |560 | 和为 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | |565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | +|581 | 最短无序连续子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shortest-unsorted-continuous-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/shortest-unsorted-continuous-subarray/) | Medium | |594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | |599 | 两个列表的最小索引总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-index-sum-of-two-lists.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-index-sum-of-two-lists/) | Easy | |605 | 种花问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/can-place-flowers.rs) | [leetcode](https://leetcode-cn.com/problems/can-place-flowers/) | Easy | From 19d0b9075b02374cc7022895b3ddb57a66b861ad Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 24 Feb 2023 08:59:51 +0800 Subject: [PATCH 0747/1556] src/bin/task-scheduler.rs --- src/bin/task-scheduler.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/bin/task-scheduler.rs diff --git a/src/bin/task-scheduler.rs b/src/bin/task-scheduler.rs new file mode 100644 index 00000000..416a1702 --- /dev/null +++ b/src/bin/task-scheduler.rs @@ -0,0 +1,22 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn least_interval(tasks: Vec, n: i32) -> i32 { + let mut count = [0; 26]; + + for &v in tasks.iter() { + count[(v as u8 - b'A') as usize] += 1 + } + + let max = count.iter().map(|x| *x).max().unwrap(); + + let mut t = 0; + let t = count.iter().filter(|x| **x == max).count(); // 与max数量一致的任务数量 + + (tasks.len() as i32).max((n + 1) * (max - 1) + t as i32) + } +} From ea1da7486db2356dfa5c5eeab845084dae290b1b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 24 Feb 2023 08:59:52 +0800 Subject: [PATCH 0748/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eb01aab3..a31c1872 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 417 | 177 | 215 | 25 | +| 418 | 177 | 216 | 25 | ### 题目 @@ -259,6 +259,7 @@ |599 | 两个列表的最小索引总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-index-sum-of-two-lists.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-index-sum-of-two-lists/) | Easy | |605 | 种花问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/can-place-flowers.rs) | [leetcode](https://leetcode-cn.com/problems/can-place-flowers/) | Easy | |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | +|621 | 任务调度器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/task-scheduler.rs) | [leetcode](https://leetcode-cn.com/problems/task-scheduler/) | Medium | |623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | |637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | |643 | 子数组最大平均数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-average-subarray-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-average-subarray-i/) | Easy | From ccae5f6cce5563426c8674fee6367a092e62e1ba Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 24 Feb 2023 10:57:10 +0800 Subject: [PATCH 0749/1556] src/bin/palindromic-substrings.rs --- src/bin/palindromic-substrings.rs | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/bin/palindromic-substrings.rs diff --git a/src/bin/palindromic-substrings.rs b/src/bin/palindromic-substrings.rs new file mode 100644 index 00000000..4b9a68e3 --- /dev/null +++ b/src/bin/palindromic-substrings.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::count_substrings("abc".into()), 3); + assert_eq!(Solution::count_substrings("aaa".into()), 6); +} + +struct Solution; + +impl Solution { + /// 设f(i, j)表示是否s[i..j]为回文串(包含j) + /// f(i, j) = f(i+1, j-1) && s[i] == s[j] + pub fn count_substrings(s: String) -> i32 { + let s = s.as_bytes(); + let mut dp = vec![vec![false; s.len()]; s.len()]; + let mut ans = 0; + + // 从长度为2开始遍历 + for sub_string_length in 0..s.len() { + for j in 0..s.len() { + if j + sub_string_length > s.len() - 1 { + break; + } + + if sub_string_length == 0 { + dp[j][j + sub_string_length] = true; + } else if sub_string_length == 1 { + dp[j][j + sub_string_length] = s[j] == s[j + sub_string_length]; + } else { + dp[j][j + sub_string_length] = + dp[j + 1][j + sub_string_length - 1] && s[j] == s[j + sub_string_length]; + } + + if dp[j][j + sub_string_length] { + ans += 1; + } + } + } + ans + } +} From 5aa76bdf4605d74c8bf487fa8d1d1c200f31720d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 24 Feb 2023 10:57:10 +0800 Subject: [PATCH 0750/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a31c1872..0395fddc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 418 | 177 | 216 | 25 | +| 419 | 177 | 217 | 25 | ### 题目 @@ -263,6 +263,7 @@ |623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | |637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | |643 | 子数组最大平均数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-average-subarray-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-average-subarray-i/) | Easy | +|647 | 回文子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindromic-substrings.rs) | [leetcode](https://leetcode-cn.com/problems/palindromic-substrings/) | Medium | |649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | |650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | |653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | From 08fb423242390e8cfeaafabb4f033eb9adf2da8c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 24 Feb 2023 11:23:36 +0800 Subject: [PATCH 0751/1556] src/bin/daily-temperatures.rs --- src/bin/daily-temperatures.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/daily-temperatures.rs diff --git a/src/bin/daily-temperatures.rs b/src/bin/daily-temperatures.rs new file mode 100644 index 00000000..2a7f8eb0 --- /dev/null +++ b/src/bin/daily-temperatures.rs @@ -0,0 +1,31 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +impl Solution { + /// 单调栈保存单调递减的温度, + /// 遍历到一个温度时,弹出单调栈顶的元素,如果当前温度比栈顶的温度高,则就是第一次出现大于栈顶的温度,直接下标求差即为相差的天数。 + /// 然后把当前温度入栈。 + pub fn daily_temperatures(temperatures: Vec) -> Vec { + let mut stack = vec![]; + let mut ans = vec![0; temperatures.len()]; + for i in 0..temperatures.len() { + while !stack.is_empty() { + if temperatures[stack[stack.len() - 1]] < temperatures[i] { + ans[stack[stack.len() - 1]] = (i - (stack[stack.len() - 1])) as i32; + stack.pop(); + } else { + break; + } + } + + stack.push(i); + } + + ans + } +} From 1377fa097b3d2dd9234c49e2279ad10175f8ad47 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 24 Feb 2023 11:23:36 +0800 Subject: [PATCH 0752/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0395fddc..5178dcdc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 419 | 177 | 217 | 25 | +| 420 | 177 | 218 | 25 | ### 题目 @@ -271,6 +271,7 @@ |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | |718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | +|739 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/daily-temperatures.rs) | [leetcode](https://leetcode-cn.com/problems/daily-temperatures/) | Medium | |742 | 转换成小写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/to-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/to-lower-case/) | Easy | |782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | |783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | From b9ea1e06a6156318286a32685d93fe4ea4407584 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 Feb 2023 09:20:48 +0800 Subject: [PATCH 0753/1556] src/bin/xoh6Oh.rs --- src/bin/xoh6Oh.rs | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/bin/xoh6Oh.rs diff --git a/src/bin/xoh6Oh.rs b/src/bin/xoh6Oh.rs new file mode 100644 index 00000000..c3ad2c0a --- /dev/null +++ b/src/bin/xoh6Oh.rs @@ -0,0 +1,48 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + println!("{}", Solution::divide(15, 2)); + println!("{}", Solution::divide(-7, 3)); + println!("{}", Solution::divide(7, -3)); + println!("{}", Solution::divide(-2, 3)); + println!("{}", Solution::divide(0, 3)); +} + +struct Solution; + +impl Solution { + pub fn divide(a: i32, b: i32) -> i32 { + let mut sign: i64 = if a.signum() == b.signum() { 1 } else { -1 }; + + let mut a = if a > 0 { a as i64 } else { 0 - a as i64 }; + let mut b = if b > 0 { b as i64 } else { 0 - b as i64 }; + + let mut ans = 0 as i64; + let mut r = 1; + let mut new_b = b; + loop { + if a < b { + break; + } + + if a < new_b + new_b { + ans += r; + a -= new_b; + r = 1; + new_b = b; + continue; + } + + new_b += new_b; + r += r; + } + + let ans = if sign == 1 { ans } else { 0 - ans }; + + if ans > i32::MAX as i64 { + i32::MAX + } else { + ans as i32 + } + } +} From 57f2214d537c26c5ea4e4590f2675209a52c01d9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 Feb 2023 09:20:49 +0800 Subject: [PATCH 0754/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5178dcdc..c150774d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 420 | 177 | 218 | 25 | +| 421 | 178 | 218 | 25 | ### 题目 @@ -427,4 +427,5 @@ |100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | |1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | +|1000228 | 整数除法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xoh6Oh.rs) | [leetcode](https://leetcode-cn.com/problems/xoh6Oh/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From c7a5f4e7aec6a4d31868138c147a6781174ea255 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 Feb 2023 09:49:25 +0800 Subject: [PATCH 0755/1556] src/bin/JFETK5.rs --- src/bin/JFETK5.rs | 99 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/bin/JFETK5.rs diff --git a/src/bin/JFETK5.rs b/src/bin/JFETK5.rs new file mode 100644 index 00000000..51b3508a --- /dev/null +++ b/src/bin/JFETK5.rs @@ -0,0 +1,99 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + println!("{}", Solution::add_binary("11".into(), "10".into())); + println!("{}", Solution::add_binary("1010".into(), "1011".into())); +} + +struct Solution; + +impl Solution { + pub fn add_binary(a: String, b: String) -> String { + let mut ans = vec![0; a.len().max(b.len()) + 1]; + let l = ans.len(); + let mut sign = b'0'; // 符号位 + let (a, b) = (a.as_bytes(), b.as_bytes()); + + let mut i = 1; + + while i <= a.len() || i <= b.len() { + if i <= a.len() && i <= b.len() { + match (a[a.len() - i], b[b.len() - i], sign) { + (b'0', b'0', s) => { + ans[l - i] = s; + sign = b'0'; + } + (b'1', b'0', s) => { + if s == b'1' { + ans[l - i] = b'0'; + sign = b'1'; + } else { + ans[l - i] = b'1'; + sign = b'0'; + } + } + (b'0', b'1', s) => { + if s == b'1' { + ans[l - i] = b'0'; + sign = b'1'; + } else { + ans[l - i] = b'1'; + sign = b'0'; + } + } + (b'1', b'1', s) => { + ans[l - i] = s; + sign = b'1'; + } + _ => unreachable!(), + } + } else if i <= a.len() { + match (a[a.len() - i], sign) { + (b'0', s) => { + ans[l - i] = s; + sign = b'0'; + } + (b'1', s) => { + if s == b'0' { + ans[l - i] = b'1'; + sign = b'0'; + } else { + ans[l - i] = b'0'; + sign = b'1'; + } + } + _ => unreachable!(), + } + } else { + match (b[b.len() - i], sign) { + (b'0', s) => { + ans[l - i] = s; + sign = b'0'; + } + (b'1', s) => { + if s == b'0' { + ans[l - i] = b'1'; + sign = b'0'; + } else { + ans[l - i] = b'0'; + sign = b'1'; + } + } + _ => unreachable!(), + } + } + + i += 1; + } + + if sign == b'1' { + ans[l - i] = b'1'; + } + + if ans[0] == b'1' { + String::from_utf8_lossy(&ans).to_string() + } else { + String::from_utf8_lossy(&ans[1..]).to_string() + } + } +} From 110f7a55d19ec4292ac7175a4ee720dc73a1f4ab Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 Feb 2023 09:49:25 +0800 Subject: [PATCH 0756/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c150774d..e6efc6a2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 421 | 178 | 218 | 25 | +| 422 | 179 | 218 | 25 | ### 题目 @@ -428,4 +428,5 @@ |1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | |1000228 | 整数除法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xoh6Oh.rs) | [leetcode](https://leetcode-cn.com/problems/xoh6Oh/) | Easy | +|1000231 | 二进制加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/JFETK5.rs) | [leetcode](https://leetcode-cn.com/problems/JFETK5/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 6d571c0df9ad47a382d04898766217be50d1e53b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 Feb 2023 10:04:34 +0800 Subject: [PATCH 0757/1556] src/bin/w3tCBm.rs --- src/bin/w3tCBm.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/w3tCBm.rs diff --git a/src/bin/w3tCBm.rs b/src/bin/w3tCBm.rs new file mode 100644 index 00000000..61c2ea9a --- /dev/null +++ b/src/bin/w3tCBm.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::count_bits(2), vec![0, 1, 1]); + assert_eq!(Solution::count_bits(5), vec![0, 1, 1, 2, 1, 2]); +} + +struct Solution; + +impl Solution { + pub fn count_bits(n: i32) -> Vec { + let mut ans = vec![0; n as usize + 1]; + let mut start = 0; + let mut pow = 1; + for i in 1..=n { + if i == pow { + start = 0; + pow <<= 1; + } + + ans[i as usize] = ans[start] + 1; + start += 1; + } + + ans + } +} From bc35be12fe936a955366f37955de4bfd41b13048 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 Feb 2023 10:04:34 +0800 Subject: [PATCH 0758/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e6efc6a2..e77109e0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 422 | 179 | 218 | 25 | +| 423 | 180 | 218 | 25 | ### 题目 @@ -428,5 +428,6 @@ |1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | |1000228 | 整数除法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xoh6Oh.rs) | [leetcode](https://leetcode-cn.com/problems/xoh6Oh/) | Easy | +|1000230 | 前 n 个数字二进制中 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/w3tCBm.rs) | [leetcode](https://leetcode-cn.com/problems/w3tCBm/) | Easy | |1000231 | 二进制加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/JFETK5.rs) | [leetcode](https://leetcode-cn.com/problems/JFETK5/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 26b15728af1b5cf8751b6659e5b871849720a6ef Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 27 Feb 2023 08:25:22 +0800 Subject: [PATCH 0759/1556] src/bin/WGki4K.rs --- src/bin/WGki4K.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/bin/WGki4K.rs diff --git a/src/bin/WGki4K.rs b/src/bin/WGki4K.rs new file mode 100644 index 00000000..d020177b --- /dev/null +++ b/src/bin/WGki4K.rs @@ -0,0 +1,65 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::single_number(vec![2, 2, 3, 2]), 3); + assert_eq!(Solution::single_number(vec![0, 1, 0, 1, 0, 1, 100]), 100); + assert_eq!( + Solution::single_number(vec![-2, -2, 1, 1, 4, 1, 4, 4, -4, -2]), + -4 + ); + assert_eq!( + Solution::single_number(vec![ + 43, + 16, + 45, + 89, + 45, + -2147483648, + 45, + 2147483646, + -2147483647, + -2147483648, + 43, + 2147483647, + -2147483646, + -2147483648, + 89, + -2147483646, + 89, + -2147483646, + -2147483647, + 2147483646, + -2147483647, + 16, + 16, + 2147483646, + 43 + ]), + 2147483647 + ); +} + +struct Solution; + +impl Solution { + pub fn single_number(nums: Vec) -> i32 { + let mut v = [0; std::mem::size_of::() * 8]; + + for mut i in nums { + for j in 0..32 { + if (i >> j) & 1 == 1 { + v[j] = (v[j] + 1) % 3; + } + } + } + + let mut ans = 0; + for i in 0..v.len() { + if v[i] == 1 { + ans += (1 << i); + } + } + + ans + } +} From a60f2639b953e83b7569bd3a6881a7c5d1d071a2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 27 Feb 2023 08:25:23 +0800 Subject: [PATCH 0760/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e77109e0..2bfa0a47 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 423 | 180 | 218 | 25 | +| 424 | 180 | 219 | 25 | ### 题目 @@ -430,4 +430,5 @@ |1000228 | 整数除法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xoh6Oh.rs) | [leetcode](https://leetcode-cn.com/problems/xoh6Oh/) | Easy | |1000230 | 前 n 个数字二进制中 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/w3tCBm.rs) | [leetcode](https://leetcode-cn.com/problems/w3tCBm/) | Easy | |1000231 | 二进制加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/JFETK5.rs) | [leetcode](https://leetcode-cn.com/problems/JFETK5/) | Easy | +|1000233 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WGki4K.rs) | [leetcode](https://leetcode-cn.com/problems/WGki4K/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 8c84a65a61900b5f9f8625728181494d6d951ed5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 27 Feb 2023 08:45:56 +0800 Subject: [PATCH 0761/1556] src/bin/aseY1I.rs --- src/bin/aseY1I.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/bin/aseY1I.rs diff --git a/src/bin/aseY1I.rs b/src/bin/aseY1I.rs new file mode 100644 index 00000000..2fde032f --- /dev/null +++ b/src/bin/aseY1I.rs @@ -0,0 +1,51 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() { + assert_eq!( + Solution::max_product( + vec!["abcw", "baz", "foo", "bar", "xtfn", "abcdef"] + .into_iter() + .map(|x| x.to_string()) + .collect() + ), + 16 + ) +} + +struct Solution; + +impl Solution { + /// 用一个i32表示 b'a' - b'z' 存在的数,比如存在b'a',则此i32的最低位为1 + /// 然后两个数相与的结果为0的话则表示不存在相同的字母。 + /// 然后长度相乘得到结果。 + pub fn max_product(words: Vec) -> i32 { + let v = words + .iter() + .map(|s| { + let mut i = 0; + for x in s.as_bytes() { + i |= (1 << (x - b'a')); + } + i + }) + .collect::>(); + + let mut ans = 0; + + for i in 0..v.len() { + for j in 0..v.len() { + if i == j { + continue; + } + + if v[i] & v[j] == 0 { + ans = ans.max(words[i].len() * words[j].len()); + } + } + } + + ans as i32 + } +} From f0976492a18fc9d6e7c4c0c58be36462230ae567 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 27 Feb 2023 08:45:57 +0800 Subject: [PATCH 0762/1556] README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2bfa0a47..d6a56481 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 424 | 180 | 219 | 25 | +| 425 | 180 | 220 | 25 | ### 题目 @@ -430,5 +430,6 @@ |1000228 | 整数除法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xoh6Oh.rs) | [leetcode](https://leetcode-cn.com/problems/xoh6Oh/) | Easy | |1000230 | 前 n 个数字二进制中 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/w3tCBm.rs) | [leetcode](https://leetcode-cn.com/problems/w3tCBm/) | Easy | |1000231 | 二进制加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/JFETK5.rs) | [leetcode](https://leetcode-cn.com/problems/JFETK5/) | Easy | -|1000233 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WGki4K.rs) | [leetcode](https://leetcode-cn.com/problems/WGki4K/) | Medium | +|1000233 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WGki4K.rs) | [leetcode](https://leetcode-cn.com/problems/WGki4K/) | Medium | +|1000236 | 单词长度的最大乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aseY1I.rs) | [leetcode](https://leetcode-cn.com/problems/aseY1I/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 5c0251ee1c6504fb6583afe76131e751acfdfe63 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 27 Feb 2023 08:58:12 +0800 Subject: [PATCH 0763/1556] src/bin/kLl5u1.rs --- src/bin/kLl5u1.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/bin/kLl5u1.rs diff --git a/src/bin/kLl5u1.rs b/src/bin/kLl5u1.rs new file mode 100644 index 00000000..91118c74 --- /dev/null +++ b/src/bin/kLl5u1.rs @@ -0,0 +1,38 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 简单方式:记录每个数的下标, + /// 如果当前数为current,然后通过查找target-current的下标,如果存在则说明就是这两个数 + pub fn two_sum1(numbers: Vec, target: i32) -> Vec { + let mut map = std::collections::HashMap::new(); + + for (i, v) in numbers.into_iter().enumerate() { + if let Some(&x) = map.get(&(target - v)) { + return vec![x, i as i32]; + } + + map.insert(v, i as i32); + } + + unreachable!() + } + + /// 双指针。 + /// 因为数是已排序的,则两个指针,一个从前往后,一个从后往前遍历即可 + pub fn two_sum(numbers: Vec, target: i32) -> Vec { + let (mut p1, mut p2) = (0, numbers.len() - 1); + while p1 < p2 { + match (numbers[p1] + numbers[p2]).cmp(&target) { + std::cmp::Ordering::Equal => return vec![p1 as i32, p2 as i32], + std::cmp::Ordering::Less => p1 += 1, + std::cmp::Ordering::Greater => p2 -= 1, + } + } + + unreachable!() + } +} From cd887d8cba781ace8f1260c64c700d87898e8b56 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 27 Feb 2023 08:58:13 +0800 Subject: [PATCH 0764/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6a56481..87813e63 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 425 | 180 | 220 | 25 | +| 426 | 181 | 220 | 25 | ### 题目 @@ -432,4 +432,5 @@ |1000231 | 二进制加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/JFETK5.rs) | [leetcode](https://leetcode-cn.com/problems/JFETK5/) | Easy | |1000233 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WGki4K.rs) | [leetcode](https://leetcode-cn.com/problems/WGki4K/) | Medium | |1000236 | 单词长度的最大乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aseY1I.rs) | [leetcode](https://leetcode-cn.com/problems/aseY1I/) | Medium | +|1000237 | 排序数组中两个数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kLl5u1.rs) | [leetcode](https://leetcode-cn.com/problems/kLl5u1/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From aa25de40e7e0f61521061714edba6b7637a80133 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 28 Feb 2023 10:57:51 +0800 Subject: [PATCH 0765/1556] src/bin/2VG8Kg.rs --- src/bin/2VG8Kg.rs | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/bin/2VG8Kg.rs diff --git a/src/bin/2VG8Kg.rs b/src/bin/2VG8Kg.rs new file mode 100644 index 00000000..389cae6a --- /dev/null +++ b/src/bin/2VG8Kg.rs @@ -0,0 +1,48 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::min_sub_array_len(7, vec![2, 3, 1, 2, 4, 3]), 2); + assert_eq!(Solution::min_sub_array_len(4, vec![1, 4, 4]), 1); + assert_eq!( + Solution::min_sub_array_len(11, vec![1, 1, 1, 1, 1, 1, 1, 1]), + 0 + ); +} + +struct Solution; + +impl Solution { + /// 两个指针 start和end,start和end的和为sum + /// 如果sum >= target,则说明区间满足条件,start向前移动,sum减去start后移前下标位置的值 + /// 否则的话,end后移,sum加上当前end后移后当前下标的值 + pub fn min_sub_array_len(target: i32, nums: Vec) -> i32 { + let (mut start, mut end) = (0, 1); + let mut sum = nums[0]; + let mut ans = nums.len() + 1; + + loop { + if sum >= target { + ans = ans.min(end - start); + sum -= nums[start]; + start += 1; + } else { + end += 1; + if end > nums.len() { + break; + } + + sum += nums[end - 1]; + } + + if ans == 1 { + break; + } + } + + if ans == nums.len() + 1 { + 0 + } else { + ans as i32 + } + } +} From 98e8758425d59374f79ed87ad7dfa698d683be65 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 28 Feb 2023 10:57:52 +0800 Subject: [PATCH 0766/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 87813e63..72edc2d4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 426 | 181 | 220 | 25 | +| 427 | 181 | 221 | 25 | ### 题目 @@ -433,4 +433,5 @@ |1000233 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WGki4K.rs) | [leetcode](https://leetcode-cn.com/problems/WGki4K/) | Medium | |1000236 | 单词长度的最大乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aseY1I.rs) | [leetcode](https://leetcode-cn.com/problems/aseY1I/) | Medium | |1000237 | 排序数组中两个数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kLl5u1.rs) | [leetcode](https://leetcode-cn.com/problems/kLl5u1/) | Easy | +|1000242 | 和大于等于 target 的最短子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2VG8Kg.rs) | [leetcode](https://leetcode-cn.com/problems/2VG8Kg/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 5283a9518e8e8436739f9eef3a6843af4f249f9e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Mar 2023 08:56:17 +0800 Subject: [PATCH 0767/1556] src/bin/ZVAVXX.rs --- src/bin/ZVAVXX.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/bin/ZVAVXX.rs diff --git a/src/bin/ZVAVXX.rs b/src/bin/ZVAVXX.rs new file mode 100644 index 00000000..f0b4de9b --- /dev/null +++ b/src/bin/ZVAVXX.rs @@ -0,0 +1,43 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!( + Solution::num_subarray_product_less_than_k(vec![10, 5, 2, 6], 100), + 8 + ); + assert_eq!( + Solution::num_subarray_product_less_than_k(vec![1, 2, 3], 0), + 0 + ); + + assert_eq!( + Solution::num_subarray_product_less_than_k(vec![1, 1, 1], 2), + 6 + ); +} + +struct Solution; + +impl Solution { + /// 两个指针 start和end,start和end的子数组的积为 product + /// 先以start为起点,递增end,判断 product 是否满足条件,不满足条件的时候停止递增 + /// 然后递增start,直到start等于end为止, + /// 然后重复2,3步直到最后一步 + pub fn num_subarray_product_less_than_k(nums: Vec, k: i32) -> i32 { + let mut start = 0; + let mut product = 1; + let mut ans = 0; + for (i, &v) in nums.iter().enumerate() { + product *= v; + + while start <= i && product >= k { + product /= nums[start]; + start += 1; + } + + ans += (i as i32 - start as i32) + 1; + } + + ans + } +} From f7e35a122f21784386f2a6a1ee925ece8095653a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Mar 2023 08:56:17 +0800 Subject: [PATCH 0768/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 72edc2d4..ff04740c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 427 | 181 | 221 | 25 | +| 428 | 181 | 222 | 25 | ### 题目 @@ -434,4 +434,5 @@ |1000236 | 单词长度的最大乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aseY1I.rs) | [leetcode](https://leetcode-cn.com/problems/aseY1I/) | Medium | |1000237 | 排序数组中两个数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kLl5u1.rs) | [leetcode](https://leetcode-cn.com/problems/kLl5u1/) | Easy | |1000242 | 和大于等于 target 的最短子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2VG8Kg.rs) | [leetcode](https://leetcode-cn.com/problems/2VG8Kg/) | Medium | +|1000244 | 乘积小于 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ZVAVXX.rs) | [leetcode](https://leetcode-cn.com/problems/ZVAVXX/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From ece6e75a4b516d302a1fa609f9d980269a3c6ee9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Mar 2023 22:43:58 +0800 Subject: [PATCH 0769/1556] src/bin/QTMn0o.rs --- src/bin/QTMn0o.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/bin/QTMn0o.rs diff --git a/src/bin/QTMn0o.rs b/src/bin/QTMn0o.rs new file mode 100644 index 00000000..8bc38f2d --- /dev/null +++ b/src/bin/QTMn0o.rs @@ -0,0 +1,33 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::subarray_sum(vec![1, 1, 1], 2), 2); + assert_eq!(Solution::subarray_sum(vec![1, 2, 3], 3), 2); +} + +struct Solution; + +impl Solution { + /// 先求出前缀和 + /// 然后遍历前缀和列表,如果当前值为k,则说明此位置的前缀和满足条件 + /// 然后再判断是否有当前值-k存在,获取存在的数量 + pub fn subarray_sum(mut nums: Vec, k: i32) -> i32 { + for i in 1..nums.len() { + let (x, y) = (nums[i], nums[i - 1]); + nums[i] = x + y; + } + + let mut map = std::collections::HashMap::new(); + let mut ans = 0; + for i in nums { + if i == k { + ans += 1; + } + + ans += *map.get(&(i - k)).unwrap_or(&0); + map.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + + ans + } +} From 450162ca0bbb29cdd4a6835f716b610dbbea5c40 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Mar 2023 22:43:59 +0800 Subject: [PATCH 0770/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ff04740c..a3c56936 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 428 | 181 | 222 | 25 | +| 429 | 181 | 223 | 25 | ### 题目 @@ -435,4 +435,5 @@ |1000237 | 排序数组中两个数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kLl5u1.rs) | [leetcode](https://leetcode-cn.com/problems/kLl5u1/) | Easy | |1000242 | 和大于等于 target 的最短子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2VG8Kg.rs) | [leetcode](https://leetcode-cn.com/problems/2VG8Kg/) | Medium | |1000244 | 乘积小于 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ZVAVXX.rs) | [leetcode](https://leetcode-cn.com/problems/ZVAVXX/) | Medium | +|1000246 | 和为 k 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/QTMn0o.rs) | [leetcode](https://leetcode-cn.com/problems/QTMn0o/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 74c73b6d8448302173c84deeec7e60d4ae454043 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Mar 2023 23:22:15 +0800 Subject: [PATCH 0771/1556] src/bin/A1NYOS.rs --- src/bin/A1NYOS.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/bin/A1NYOS.rs diff --git a/src/bin/A1NYOS.rs b/src/bin/A1NYOS.rs new file mode 100644 index 00000000..f8ad56cd --- /dev/null +++ b/src/bin/A1NYOS.rs @@ -0,0 +1,43 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::find_max_length(vec![0, 1]), 2); + assert_eq!(Solution::find_max_length(vec![0, 1, 0]), 2); + assert_eq!(Solution::find_max_length(vec![0, 0, 1, 0, 0, 0, 1, 1]), 6); +} + +struct Solution; + +impl Solution { + /// count记录0的数量-1的数量 + /// 当counter为0时,则说明此时满足条件 + /// 当counter不为0时,找到相同counter时的子数组,则减去相同counter的子数组剩余的数组就是0和1相同数量的子数组 + pub fn find_max_length(nums: Vec) -> i32 { + let mut nums = nums; + let mut count = 0; // 0的数量-1的数量 + + let mut ans = 0; + let mut map = std::collections::HashMap::new(); + + for i in 0..nums.len() { + if nums[i] == 0 { + count += 1; + } else { + count -= 1; + } + + if count == 0 { + ans = ans.max(i as i32 + 1); + } else { + match map.get(&count) { + Some(&x) => ans = ans.max(i as i32 - x), + None => {} + } + + map.entry(count).or_insert(i as i32); + } + } + + ans + } +} From e6aa94aa91c4883154337061306330b9358b5a7d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Mar 2023 23:22:16 +0800 Subject: [PATCH 0772/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a3c56936..c3818ddd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 429 | 181 | 223 | 25 | +| 430 | 181 | 224 | 25 | ### 题目 @@ -436,4 +436,5 @@ |1000242 | 和大于等于 target 的最短子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2VG8Kg.rs) | [leetcode](https://leetcode-cn.com/problems/2VG8Kg/) | Medium | |1000244 | 乘积小于 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ZVAVXX.rs) | [leetcode](https://leetcode-cn.com/problems/ZVAVXX/) | Medium | |1000246 | 和为 k 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/QTMn0o.rs) | [leetcode](https://leetcode-cn.com/problems/QTMn0o/) | Medium | +|1000247 | 0 和 1 个数相同的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/A1NYOS.rs) | [leetcode](https://leetcode-cn.com/problems/A1NYOS/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 5ca651c5ac7ca3c4f3464e9307cf68a978130782 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 2 Mar 2023 10:46:19 +0800 Subject: [PATCH 0773/1556] src/bin/tvdfij.rs --- src/bin/tvdfij.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/bin/tvdfij.rs diff --git a/src/bin/tvdfij.rs b/src/bin/tvdfij.rs new file mode 100644 index 00000000..1e00f884 --- /dev/null +++ b/src/bin/tvdfij.rs @@ -0,0 +1,26 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::pivot_index(vec![1, 2, 3]), -1); + assert_eq!(Solution::pivot_index(vec![2, 1, -1]), 0); + assert_eq!(Solution::pivot_index(vec![1, 7, 3, 6, 5, 6]), 3); +} + +struct Solution; + +impl Solution { + pub fn pivot_index(nums: Vec) -> i32 { + let sum: i32 = nums.iter().map(|x| *x).sum(); + + let mut left = 0; + for i in 0..nums.len() { + if left == sum - left - nums[i] { + return i as i32; + } + + left += nums[i]; + } + + -1 + } +} From 782bcc556209579c5aa9cf30051d7a8db9dd63f8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 2 Mar 2023 10:46:19 +0800 Subject: [PATCH 0774/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c3818ddd..3aea6bda 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 430 | 181 | 224 | 25 | +| 431 | 182 | 224 | 25 | ### 题目 @@ -437,4 +437,5 @@ |1000244 | 乘积小于 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ZVAVXX.rs) | [leetcode](https://leetcode-cn.com/problems/ZVAVXX/) | Medium | |1000246 | 和为 k 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/QTMn0o.rs) | [leetcode](https://leetcode-cn.com/problems/QTMn0o/) | Medium | |1000247 | 0 和 1 个数相同的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/A1NYOS.rs) | [leetcode](https://leetcode-cn.com/problems/A1NYOS/) | Medium | +|1000248 | 左右两边子数组的和相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tvdfij.rs) | [leetcode](https://leetcode-cn.com/problems/tvdfij/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From b0afc04863604f573671538578c666c5b31dcdb1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 2 Mar 2023 20:59:50 +0800 Subject: [PATCH 0775/1556] src/bin/O4NDxx.rs --- src/bin/O4NDxx.rs | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/bin/O4NDxx.rs diff --git a/src/bin/O4NDxx.rs b/src/bin/O4NDxx.rs new file mode 100644 index 00000000..ad8ea35e --- /dev/null +++ b/src/bin/O4NDxx.rs @@ -0,0 +1,82 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + let n = NumMatrix::new(vec![ + vec![3, 0, 1, 4, 2], + vec![5, 6, 3, 2, 1], + vec![1, 2, 0, 1, 5], + vec![4, 1, 0, 1, 7], + vec![1, 0, 3, 0, 5], + ]); + + assert_eq!(n.sum_region(2, 1, 4, 3), 8); +} + +struct Solution; + +struct NumMatrix { + matrix: Vec>, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl NumMatrix { + ///[ + /// [3,0,1,4,2], + /// [5,6,3,2,1], + /// [1,2,0,1,5], + /// [4,1,0,1,7], + /// [1,0,3,0,5] + /// ] + /// + /// [ + /// [3,3,4,8,10], + /// [5,11,14,16,17], + /// [1,3,3,4,9], + /// [4,5,5,6,13], + /// [1,1,4,4,9] + /// ] + /// + /// [ + /// [0,0,0,0,0,0], + /// [0,3,3,4,8,10], + /// [0,8,14,18,24,27], + /// [0,9,17,21,28,36], + /// [0,13,22,26,34,49], + /// [0,14,23,30,38,58] + /// ] + /// + /// sum = sum[row2 + 1][col2 + 1] - sum[row1][col2 + 1] - sum[row2 + 1][col1] + sum[row1][col1] + fn new(matrix: Vec>) -> Self { + let mut matrix = matrix; + + for i in 0..matrix.len() { + for j in 1..matrix[0].len() { + matrix[i][j] += matrix[i][j - 1]; + } + } + + let mut m = vec![vec![0; matrix[0].len() + 1]; matrix.len() + 1]; + + for i in 0..matrix.len() { + for j in 0..matrix[0].len() { + if i != 0 { + matrix[i][j] += matrix[i - 1][j]; + } + + m[i + 1][j + 1] = matrix[i][j]; + } + } + + Self { matrix: m } + } + + fn sum_region(&self, row1: i32, col1: i32, row2: i32, col2: i32) -> i32 { + self.matrix[row2 as usize + 1][col2 as usize + 1] + - self.matrix[row1 as usize][col2 as usize + 1] + - self.matrix[row2 as usize + 1][col1 as usize] + + self.matrix[row1 as usize][col1 as usize] + } +} From ec3c3c4f3361a298a9d5e4ebf3aac144dce0789e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 2 Mar 2023 20:59:51 +0800 Subject: [PATCH 0776/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3aea6bda..bc7c400f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 431 | 182 | 224 | 25 | +| 432 | 182 | 225 | 25 | ### 题目 @@ -438,4 +438,5 @@ |1000246 | 和为 k 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/QTMn0o.rs) | [leetcode](https://leetcode-cn.com/problems/QTMn0o/) | Medium | |1000247 | 0 和 1 个数相同的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/A1NYOS.rs) | [leetcode](https://leetcode-cn.com/problems/A1NYOS/) | Medium | |1000248 | 左右两边子数组的和相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tvdfij.rs) | [leetcode](https://leetcode-cn.com/problems/tvdfij/) | Easy | +|1000249 | 二维子矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/O4NDxx.rs) | [leetcode](https://leetcode-cn.com/problems/O4NDxx/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From f881b365ef7fac8a631c065a806a9f78d82c9025 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 3 Mar 2023 09:22:51 +0800 Subject: [PATCH 0777/1556] src/bin/MPnaiL.rs --- src/bin/MPnaiL.rs | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/bin/MPnaiL.rs diff --git a/src/bin/MPnaiL.rs b/src/bin/MPnaiL.rs new file mode 100644 index 00000000..63b56a5f --- /dev/null +++ b/src/bin/MPnaiL.rs @@ -0,0 +1,67 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert!(Solution::check_inclusion("ab".into(), "eidbaooo".into())); +} + +struct Solution; + +impl Solution { + pub fn check_inclusion(s1: String, s2: String) -> bool { + if s1.len() > s2.len() { + return false; + } + + let mut cnt = [0; 26]; + + for i in 0..s1.len() { + cnt[(s1.as_bytes()[i] - b'a') as usize] -= 1; + cnt[(s2.as_bytes()[i] - b'a') as usize] += 1; + } + + let mut diff = 0; // 统计不同字符的个数 + + for &i in cnt.iter() { + if i != 0 { + diff += 1; + } + } + + if diff == 0 { + return true; + } + + for i in s1.len()..s2.len() { + let (a, b) = (s2.as_bytes()[i - s1.len()], s2.as_bytes()[i]); + if a == b { + continue; + } + + if cnt[(a - b'a') as usize] == 0 { + diff += 1; + } + + cnt[(a - b'a') as usize] -= 1; + + if cnt[(a - b'a') as usize] == 0 { + diff -= 1; + } + + if cnt[(b - b'a') as usize] == 0 { + diff += 1; + } + + cnt[(b - b'a') as usize] += 1; + + if cnt[(b - b'a') as usize] == 0 { + diff -= 1; + } + + if diff == 0 { + return true; + } + } + + false + } +} From 6a890b07b4095f47d5318de856f218a16b6310cf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 3 Mar 2023 09:22:51 +0800 Subject: [PATCH 0778/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bc7c400f..3014661a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 432 | 182 | 225 | 25 | +| 433 | 182 | 226 | 25 | ### 题目 @@ -439,4 +439,5 @@ |1000247 | 0 和 1 个数相同的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/A1NYOS.rs) | [leetcode](https://leetcode-cn.com/problems/A1NYOS/) | Medium | |1000248 | 左右两边子数组的和相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tvdfij.rs) | [leetcode](https://leetcode-cn.com/problems/tvdfij/) | Easy | |1000249 | 二维子矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/O4NDxx.rs) | [leetcode](https://leetcode-cn.com/problems/O4NDxx/) | Medium | +|1000250 | 字符串中的变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/MPnaiL.rs) | [leetcode](https://leetcode-cn.com/problems/MPnaiL/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 4b0d05738225e5d375555fad080d5640703fec22 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 4 Mar 2023 23:03:27 +0800 Subject: [PATCH 0779/1556] src/bin/VabMRr.rs --- src/bin/VabMRr.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/bin/VabMRr.rs diff --git a/src/bin/VabMRr.rs b/src/bin/VabMRr.rs new file mode 100644 index 00000000..665d5576 --- /dev/null +++ b/src/bin/VabMRr.rs @@ -0,0 +1,65 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!( + Solution::find_anagrams("cbaebabacd".into(), "abc".into()), + vec![0, 6] + ); + assert_eq!( + Solution::find_anagrams("abab".into(), "ab".into()), + vec![0, 1, 2] + ); +} + +struct Solution; + +impl Solution { + pub fn find_anagrams(s: String, p: String) -> Vec { + if s.len() < p.len() { + return vec![]; + } + let mut v = [0; 26]; + for i in 0..p.len() { + v[(s.as_bytes()[i] - b'a') as usize] += 1; + v[(p.as_bytes()[i] - b'a') as usize] -= 1; + } + + let mut ans = vec![]; + let mut diff = 0; + for &i in v.iter() { + if i != 0 { + diff += 1; + } + } + + if diff == 0 { + ans.push(0); + } + + for i in p.len()..s.len() { + if v[(s.as_bytes()[i - p.len()] - b'a') as usize] == 0 { + diff += 1; + } + + v[(s.as_bytes()[i - p.len()] - b'a') as usize] -= 1; + if v[(s.as_bytes()[i - p.len()] - b'a') as usize] == 0 { + diff -= 1; + } + + if v[(s.as_bytes()[i] - b'a') as usize] == 0 { + diff += 1; + } + + v[(s.as_bytes()[i] - b'a') as usize] += 1; + if v[(s.as_bytes()[i] - b'a') as usize] == 0 { + diff -= 1; + } + + if diff == 0 { + ans.push((i - p.len() + 1) as i32); + } + } + + ans + } +} From 367af9373237980e4241906a15297a30241b2545 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 4 Mar 2023 23:03:27 +0800 Subject: [PATCH 0780/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3014661a..53a87698 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 433 | 182 | 226 | 25 | +| 434 | 182 | 227 | 25 | ### 题目 @@ -440,4 +440,5 @@ |1000248 | 左右两边子数组的和相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tvdfij.rs) | [leetcode](https://leetcode-cn.com/problems/tvdfij/) | Easy | |1000249 | 二维子矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/O4NDxx.rs) | [leetcode](https://leetcode-cn.com/problems/O4NDxx/) | Medium | |1000250 | 字符串中的变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/MPnaiL.rs) | [leetcode](https://leetcode-cn.com/problems/MPnaiL/) | Medium | +|1000251 | 字符串中的所有变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/VabMRr.rs) | [leetcode](https://leetcode-cn.com/problems/VabMRr/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From e66aa88ec4c8f16956047a8f5682ec9bdb37d878 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 5 Mar 2023 10:51:22 +0800 Subject: [PATCH 0781/1556] src/bin/wtcaE1.rs --- src/bin/wtcaE1.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/wtcaE1.rs diff --git a/src/bin/wtcaE1.rs b/src/bin/wtcaE1.rs new file mode 100644 index 00000000..775b38c7 --- /dev/null +++ b/src/bin/wtcaE1.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::length_of_longest_substring("abcabcbb".into()), 3); + assert_eq!(Solution::length_of_longest_substring("bbbbb".into()), 1); + assert_eq!(Solution::length_of_longest_substring("pwwkew".into()), 3); +} + +struct Solution; + +impl Solution { + /// 使用set来判断是否已经存在,如果存在的话,移动p直到把重复的元素移除为止 + /// abcabcbb + /// 如果当前下标为4,p需要移动到2,也就是把重复的b字符移除为止,这时就不包含重复的字符了。 + pub fn length_of_longest_substring(s: String) -> i32 { + let mut set = std::collections::HashSet::new(); + let mut ans = 0; + let mut p = 0; + + for i in 0..s.len() { + while set.contains(&(s.as_bytes()[i])) { + set.remove(&(s.as_bytes()[p])); + p += 1; + } + + set.insert(s.as_bytes()[i]); + ans = ans.max(i - p + 1); + } + + ans as i32 + } +} From 141337427add0c215fcc3a308e0d242a1dd62922 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 5 Mar 2023 10:51:23 +0800 Subject: [PATCH 0782/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 53a87698..1839b550 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 434 | 182 | 227 | 25 | +| 435 | 182 | 228 | 25 | ### 题目 @@ -441,4 +441,5 @@ |1000249 | 二维子矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/O4NDxx.rs) | [leetcode](https://leetcode-cn.com/problems/O4NDxx/) | Medium | |1000250 | 字符串中的变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/MPnaiL.rs) | [leetcode](https://leetcode-cn.com/problems/MPnaiL/) | Medium | |1000251 | 字符串中的所有变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/VabMRr.rs) | [leetcode](https://leetcode-cn.com/problems/VabMRr/) | Medium | +|1000252 | 不含重复字符的最长子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wtcaE1.rs) | [leetcode](https://leetcode-cn.com/problems/wtcaE1/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From a44d74d82e65810bffaed16b24d683108916dba8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 Mar 2023 07:58:10 +0800 Subject: [PATCH 0783/1556] src/bin/XltzEq.rs --- src/bin/XltzEq.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/bin/XltzEq.rs diff --git a/src/bin/XltzEq.rs b/src/bin/XltzEq.rs new file mode 100644 index 00000000..2653db82 --- /dev/null +++ b/src/bin/XltzEq.rs @@ -0,0 +1,54 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert!(Solution::is_palindrome( + "A man, a plan, a canal: Panama".into() + )); + assert!(!Solution::is_palindrome("race a car".into())); +} + +struct Solution; + +impl Solution { + pub fn is_palindrome(s: String) -> bool { + if s.is_empty() { + return true; + } + + let (mut start, mut end) = (0, s.len() - 1); + let s = s.as_bytes(); + + while start < end { + if matches!(s[start], b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9') + && matches!(s[end], b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9') + { + if s[start] == s[end] { + start += 1; + end -= 1; + } else if matches!(s[start], b'a'..=b'z') + && matches!(s[end], b'A'..=b'Z') + && s[end] + 32 == s[start] + { + start += 1; + end -= 1; + } else if matches!(s[end], b'a'..=b'z') + && matches!(s[start], b'A'..=b'Z') + && s[start] + 32 == s[end] + { + start += 1; + end -= 1; + } else { + return false; + } + } else if !matches!(s[start], b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9') { + start += 1; + } else if !matches!(s[end], b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9') { + end -= 1; + } else { + unreachable!() + } + } + + true + } +} From 814c73dc1ce9edae6c12015286cc29dba7527ae4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 Mar 2023 07:58:11 +0800 Subject: [PATCH 0784/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1839b550..86c6e573 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 435 | 182 | 228 | 25 | +| 436 | 183 | 228 | 25 | ### 题目 @@ -442,4 +442,5 @@ |1000250 | 字符串中的变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/MPnaiL.rs) | [leetcode](https://leetcode-cn.com/problems/MPnaiL/) | Medium | |1000251 | 字符串中的所有变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/VabMRr.rs) | [leetcode](https://leetcode-cn.com/problems/VabMRr/) | Medium | |1000252 | 不含重复字符的最长子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wtcaE1.rs) | [leetcode](https://leetcode-cn.com/problems/wtcaE1/) | Medium | +|1000254 | 有效的回文 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XltzEq.rs) | [leetcode](https://leetcode-cn.com/problems/XltzEq/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From e1154bc1ce2bd83490c2e82637e5598675a7c2f2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 Mar 2023 08:51:43 +0800 Subject: [PATCH 0785/1556] src/bin/RQku0D.rs --- src/bin/RQku0D.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bin/RQku0D.rs diff --git a/src/bin/RQku0D.rs b/src/bin/RQku0D.rs new file mode 100644 index 00000000..ee64fe0d --- /dev/null +++ b/src/bin/RQku0D.rs @@ -0,0 +1,40 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert!(Solution::valid_palindrome("aba".into())); + assert!(Solution::valid_palindrome("abca".into())); + assert!(!Solution::valid_palindrome("abc".into())); + assert!(Solution::valid_palindrome("cbbcc".into())); + assert!(Solution::valid_palindrome("aguokepatgbnvfqmgmlcupuufxoohdfpgjdmysgvhmvffcnqxjjxqncffvmhvgsymdjgpfdhooxfuupuculmgmqfvnbgtapekouga".into())); +} + +struct Solution; + +impl Solution { + /// 定义两个指针 p1, p2,如果p1 != p2, 则可以移除p1或者p2, 这时只要p1..p2-1 或者p1+1..p2这两个子串是回文串即可以满足删除一行是回文串的需求。 + pub fn valid_palindrome(s: String) -> bool { + Self::valid(s.as_bytes(), false) + } + + fn valid(s: &[u8], flag: bool) -> bool { + if s.is_empty() { + return true; + } + let (mut start, mut end) = (0, s.len() - 1); + while start < end { + if s[start] == s[end] { + start += 1; + end -= 1; + } else { + if !flag { + return Self::valid(&s[start + 1..=end], true) + || Self::valid(&s[start..=end - 1], true); + } + + return false; + } + } + + true + } +} From d606b85987bad21f0ee0aa6fd6aa67c03fa21918 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 Mar 2023 08:51:43 +0800 Subject: [PATCH 0786/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 86c6e573..f9916905 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 436 | 183 | 228 | 25 | +| 437 | 184 | 228 | 25 | ### 题目 @@ -443,4 +443,5 @@ |1000251 | 字符串中的所有变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/VabMRr.rs) | [leetcode](https://leetcode-cn.com/problems/VabMRr/) | Medium | |1000252 | 不含重复字符的最长子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wtcaE1.rs) | [leetcode](https://leetcode-cn.com/problems/wtcaE1/) | Medium | |1000254 | 有效的回文 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XltzEq.rs) | [leetcode](https://leetcode-cn.com/problems/XltzEq/) | Easy | +|1000255 | 最多删除一个字符得到回文 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/RQku0D.rs) | [leetcode](https://leetcode-cn.com/problems/RQku0D/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From cbbc2e0a34ecf7ffb17f61b85d633e68976b3be4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 Mar 2023 09:10:25 +0800 Subject: [PATCH 0787/1556] src/bin/a7VOhD.rs --- src/bin/a7VOhD.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/bin/a7VOhD.rs diff --git a/src/bin/a7VOhD.rs b/src/bin/a7VOhD.rs new file mode 100644 index 00000000..3b44c6af --- /dev/null +++ b/src/bin/a7VOhD.rs @@ -0,0 +1,43 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::count_substrings("abc".into()), 3); + assert_eq!(Solution::count_substrings("aaa".into()), 6); +} + +struct Solution; + +impl Solution { + /// dp[i][j] = bool, 表示子串s[i..j] 是否为回文字符串 + /// - dp[i+1][j-1] && s[i] == s[j], j - i > 1 + /// - + /// dp[i][j] + /// - + /// - s[i] == s[j], j-i==1 + /// + pub fn count_substrings(s: String) -> i32 { + let mut dp = vec![vec![false; s.len()]; s.len()]; + let mut ans = 0; + + let mut len = 0; + let s = s.as_bytes(); + + while len <= s.len() { + for i in 0..s.len() - len { + if len <= 1 { + dp[i][i + len] = s[i] == s[i + len]; + } else { + dp[i][i + len] = s[i] == s[i + len] && dp[i + 1][i + len - 1]; + } + + if dp[i][i + len] { + ans += 1; + } + } + + len += 1; + } + + ans + } +} From 0a1332f92c3d8574687a309ad5be39f6a91243cc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 Mar 2023 09:10:25 +0800 Subject: [PATCH 0788/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f9916905..081d439c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 437 | 184 | 228 | 25 | +| 438 | 184 | 229 | 25 | ### 题目 @@ -444,4 +444,5 @@ |1000252 | 不含重复字符的最长子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wtcaE1.rs) | [leetcode](https://leetcode-cn.com/problems/wtcaE1/) | Medium | |1000254 | 有效的回文 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XltzEq.rs) | [leetcode](https://leetcode-cn.com/problems/XltzEq/) | Easy | |1000255 | 最多删除一个字符得到回文 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/RQku0D.rs) | [leetcode](https://leetcode-cn.com/problems/RQku0D/) | Easy | +|1000256 | 回文子字符串的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/a7VOhD.rs) | [leetcode](https://leetcode-cn.com/problems/a7VOhD/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From ac8dbed6bc55b6fe7289f0ff47c15bdcd5297812 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 7 Mar 2023 22:48:55 +0800 Subject: [PATCH 0789/1556] src/bin/lMSNwu.rs --- src/bin/lMSNwu.rs | 97 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/bin/lMSNwu.rs diff --git a/src/bin/lMSNwu.rs b/src/bin/lMSNwu.rs new file mode 100644 index 00000000..68b873a7 --- /dev/null +++ b/src/bin/lMSNwu.rs @@ -0,0 +1,97 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} + +impl Solution { + pub fn add_two_numbers( + l1: Option>, + l2: Option>, + ) -> Option> { + let mut a = vec![]; + let mut current = l1.as_deref(); + while current.is_some() { + let c = current.unwrap(); + a.push(c.val); + current = c.next.as_deref(); + } + + let mut b = vec![]; + let mut current = l2.as_deref(); + while current.is_some() { + let c = current.unwrap(); + b.push(c.val); + current = c.next.as_deref(); + } + + let mut dummy = Some(Box::new(ListNode::new(-1))); + let mut f = 0; + loop { + let val = match (a.pop(), b.pop()) { + (Some(x), Some(y)) => { + let mut v = x + y + f; + f = 0; + if v > 9 { + f = v / 10; + v = v % 10; + } + + v + } + + (Some(x), None) => { + let mut v = x + f; + f = 0; + if v > 9 { + f = v / 10; + v = v % 10; + } + + v + } + + (None, Some(y)) => { + let mut v = y + f; + f = 0; + if v > 9 { + f = v / 10; + v = v % 10; + } + + v + } + + (None, None) => break, + }; + + let n = dummy.as_deref_mut().and_then(|x| x.next.take()); + let mut c = Box::new(ListNode { val, next: n }); + + dummy.as_deref_mut().unwrap().next.insert(c); + } + + if f != 0 { + let n = dummy.as_deref_mut().and_then(|x| x.next.take()); + let mut c = Box::new(ListNode { val: f, next: n }); + + dummy.as_deref_mut().unwrap().next.insert(c); + } + + dummy.unwrap().next + } +} From 6b8a12501025a042fa6af25a465b7224465ddb0a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 7 Mar 2023 22:48:56 +0800 Subject: [PATCH 0790/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 081d439c..5a8f1de4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 438 | 184 | 229 | 25 | +| 439 | 184 | 230 | 25 | ### 题目 @@ -445,4 +445,5 @@ |1000254 | 有效的回文 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XltzEq.rs) | [leetcode](https://leetcode-cn.com/problems/XltzEq/) | Easy | |1000255 | 最多删除一个字符得到回文 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/RQku0D.rs) | [leetcode](https://leetcode-cn.com/problems/RQku0D/) | Easy | |1000256 | 回文子字符串的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/a7VOhD.rs) | [leetcode](https://leetcode-cn.com/problems/a7VOhD/) | Medium | +|1000261 | 链表中的两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lMSNwu.rs) | [leetcode](https://leetcode-cn.com/problems/lMSNwu/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From b3d53a857604a72873ae2cd8b3ab878e24dfd8c6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 8 Mar 2023 22:42:45 +0800 Subject: [PATCH 0791/1556] src/bin/LGjMqU.rs --- src/bin/LGjMqU.rs | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/bin/LGjMqU.rs diff --git a/src/bin/LGjMqU.rs b/src/bin/LGjMqU.rs new file mode 100644 index 00000000..f5e5cb1a --- /dev/null +++ b/src/bin/LGjMqU.rs @@ -0,0 +1,96 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} +impl Solution { + /// 1.双指针找到链表的中心 + /// 2.然后翻转后半部分的链表 + /// 3.合并前后部分 + pub fn reorder_list(head: &mut Option>) { + // 注意:找到后半部分可以使用快慢指针,但是rust我不会 + let mut len = 0; + let mut current = head.as_deref(); + while current.is_some() { + len += 1; + current = current.unwrap().next.as_deref(); + } + let mut middle = head.as_deref_mut(); + for i in 0..len / 2 { + middle = middle.unwrap().next.as_deref_mut(); + } + + if middle.is_none() { + return; + } + + let mut middle = middle.unwrap().next.take(); + // 翻转middle + let mut dummy = Box::new(ListNode::new(-1)); + while middle.is_some() { + let n = dummy.next.take(); + let c = middle.as_deref_mut().unwrap().next.take(); + + dummy.next = middle; + dummy.next.as_deref_mut().unwrap().next = n; + + middle = c; + } + + let (mut l1, mut l2) = (head.as_deref_mut().unwrap().next.take(), dummy.next.take()); + + let mut dummy = Box::new(ListNode::new(-1)); + let mut current = &mut dummy.next; + + loop { + match (l1, l2) { + (Some(mut x1), Some(mut x2)) => { + l1 = x1.next.take(); + l2 = x2.next.take(); + + current.insert(x2); + current = &mut current.as_deref_mut().unwrap().next; + + current.insert(x1); + current = &mut current.as_deref_mut().unwrap().next; + } + + (Some(mut x1), None) => { + l1 = x1.next.take(); + l2 = None; + + current.insert(x1); + current = &mut current.as_deref_mut().unwrap().next; + } + + (None, Some(mut x2)) => { + l1 = None; + l2 = x2.next.take(); + + current.insert(x2); + current = &mut current.as_deref_mut().unwrap().next; + } + + _ => break, + } + } + + head.as_deref_mut().unwrap().next = dummy.next.take(); + } +} From 8b153644efad141215ea49b0d3cc286a04c2944a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 8 Mar 2023 22:42:46 +0800 Subject: [PATCH 0792/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a8f1de4..d6425ddd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 439 | 184 | 230 | 25 | +| 440 | 184 | 231 | 25 | ### 题目 @@ -446,4 +446,5 @@ |1000255 | 最多删除一个字符得到回文 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/RQku0D.rs) | [leetcode](https://leetcode-cn.com/problems/RQku0D/) | Easy | |1000256 | 回文子字符串的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/a7VOhD.rs) | [leetcode](https://leetcode-cn.com/problems/a7VOhD/) | Medium | |1000261 | 链表中的两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lMSNwu.rs) | [leetcode](https://leetcode-cn.com/problems/lMSNwu/) | Medium | +|1000262 | 重排链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/LGjMqU.rs) | [leetcode](https://leetcode-cn.com/problems/LGjMqU/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From e7be22e416fb3e2aaa054ead30c147a5254f0301 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 9 Mar 2023 10:32:49 +0800 Subject: [PATCH 0793/1556] src/bin/aMhZSa.rs --- src/bin/aMhZSa.rs | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/bin/aMhZSa.rs diff --git a/src/bin/aMhZSa.rs b/src/bin/aMhZSa.rs new file mode 100644 index 00000000..8567f3c7 --- /dev/null +++ b/src/bin/aMhZSa.rs @@ -0,0 +1,60 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} +impl Solution { + /// 找到下半部分,翻转上半部分,再比较上下两部分 + pub fn is_palindrome(mut head: Option>) -> bool { + let mut len = 0; + let mut current = head.as_deref(); + + while current.is_some() { + len += 1; + current = current.unwrap().next.as_deref(); + } + + let mut dummy = Box::new(ListNode::new(-1)); + + for i in 0..len / 2 { + let next = head.as_deref_mut().unwrap().next.take(); + let n = dummy.next.take(); + head.as_deref_mut().unwrap().next = n; + dummy.next = head; + head = next; + } + + let (mut left, mut right) = if len % 2 == 0 { + (dummy.next.take(), head) + } else { + (dummy.next.take(), head.unwrap().next.take()) + }; + + loop { + match (left, right) { + (Some(mut x), Some(mut y)) if x.val == y.val => { + left = x.next.take(); + right = y.next.take(); + } + (None, None) => break, + _ => return false, + } + } + + true + } +} From 5a81e2f17dd835d6c431dcad619879726cc09b49 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 9 Mar 2023 10:32:49 +0800 Subject: [PATCH 0794/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6425ddd..c808a69e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 440 | 184 | 231 | 25 | +| 441 | 185 | 231 | 25 | ### 题目 @@ -447,4 +447,5 @@ |1000256 | 回文子字符串的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/a7VOhD.rs) | [leetcode](https://leetcode-cn.com/problems/a7VOhD/) | Medium | |1000261 | 链表中的两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lMSNwu.rs) | [leetcode](https://leetcode-cn.com/problems/lMSNwu/) | Medium | |1000262 | 重排链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/LGjMqU.rs) | [leetcode](https://leetcode-cn.com/problems/LGjMqU/) | Medium | +|1000263 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aMhZSa.rs) | [leetcode](https://leetcode-cn.com/problems/aMhZSa/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From a717c3d68769b43fced24f8f7ece7c0dd5a421c4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 12 Mar 2023 22:13:53 +0800 Subject: [PATCH 0795/1556] src/bin/dKk3P7.rs --- src/bin/dKk3P7.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/dKk3P7.rs diff --git a/src/bin/dKk3P7.rs b/src/bin/dKk3P7.rs new file mode 100644 index 00000000..2cb89c14 --- /dev/null +++ b/src/bin/dKk3P7.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn is_anagram(s: String, t: String) -> bool { + if s.len() != t.len() { + return false; + } + + let mut v = [0; 26]; + let mut f = false; + for i in 0..s.len() { + if !f && s.as_bytes()[i] != t.as_bytes()[i] { + f = true; + } + + v[(s.as_bytes()[i] - b'a') as usize] += 1; + v[(t.as_bytes()[i] - b'a') as usize] -= 1; + } + + if !f { + return false; + } + + for i in v { + if i != 0 { + return false; + } + } + + true + } +} From a6aed9c9ae1328e7693093ebc53cc5e6aadf1ca6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 12 Mar 2023 22:13:53 +0800 Subject: [PATCH 0796/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c808a69e..96f14717 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 441 | 185 | 231 | 25 | +| 442 | 186 | 231 | 25 | ### 题目 @@ -448,4 +448,5 @@ |1000261 | 链表中的两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lMSNwu.rs) | [leetcode](https://leetcode-cn.com/problems/lMSNwu/) | Medium | |1000262 | 重排链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/LGjMqU.rs) | [leetcode](https://leetcode-cn.com/problems/LGjMqU/) | Medium | |1000263 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aMhZSa.rs) | [leetcode](https://leetcode-cn.com/problems/aMhZSa/) | Easy | +|1000273 | 有效的变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dKk3P7.rs) | [leetcode](https://leetcode-cn.com/problems/dKk3P7/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From bc41c14347db5795d9ba6ae7b8bdffa27b9a3209 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 13 Mar 2023 11:11:01 +0800 Subject: [PATCH 0797/1556] src/bin/sfvd7V.rs --- src/bin/sfvd7V.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/sfvd7V.rs diff --git a/src/bin/sfvd7V.rs b/src/bin/sfvd7V.rs new file mode 100644 index 00000000..29c3f408 --- /dev/null +++ b/src/bin/sfvd7V.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn group_anagrams(strs: Vec) -> Vec> { + let mut map = std::collections::HashMap::<[u8; 26], Vec>::new(); + + for s in strs { + let mut v = [0u8; 26]; + for &j in s.as_bytes() { + v[(j - b'a') as usize] += 1; + } + + match map.entry(v) { + std::collections::hash_map::Entry::Occupied(mut entry) => { + entry.get_mut().push(s); + } + std::collections::hash_map::Entry::Vacant(entry) => { + entry.insert(vec![s]); + } + } + } + + map.into_iter().map(|(x, y)| y).collect() + } +} From 34a5dae1cb3787c315f07de1bc88109b0930ca0e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 13 Mar 2023 11:11:02 +0800 Subject: [PATCH 0798/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 96f14717..95329dac 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 442 | 186 | 231 | 25 | +| 443 | 186 | 232 | 25 | ### 题目 @@ -449,4 +449,5 @@ |1000262 | 重排链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/LGjMqU.rs) | [leetcode](https://leetcode-cn.com/problems/LGjMqU/) | Medium | |1000263 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aMhZSa.rs) | [leetcode](https://leetcode-cn.com/problems/aMhZSa/) | Easy | |1000273 | 有效的变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dKk3P7.rs) | [leetcode](https://leetcode-cn.com/problems/dKk3P7/) | Easy | +|1000275 | 变位词组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sfvd7V.rs) | [leetcode](https://leetcode-cn.com/problems/sfvd7V/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 20936a44b30848222f60ff1d33174944cc6dcf08 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 14 Mar 2023 23:11:03 +0800 Subject: [PATCH 0799/1556] src/bin/lwyVBB.rs --- src/bin/lwyVBB.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bin/lwyVBB.rs diff --git a/src/bin/lwyVBB.rs b/src/bin/lwyVBB.rs new file mode 100644 index 00000000..dfe4ca2f --- /dev/null +++ b/src/bin/lwyVBB.rs @@ -0,0 +1,40 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn is_alien_sorted(words: Vec, order: String) -> bool { + let mut dict = [0; 26]; + for (i, &v) in order.as_bytes().into_iter().enumerate() { + dict[(v - b'a') as usize] = i + } + + for i in 1..words.len() { + let mut index = 0; + loop { + match ( + words[i - 1].as_bytes().get(index), + words[i].as_bytes().get(index), + ) { + (Some(&x), Some(&y)) => { + if dict[(x - b'a') as usize] > dict[(y - b'a') as usize] { + return false; + } else if dict[(x - b'a') as usize] < dict[(y - b'a') as usize] { + break; + } + } + (Some(&x), None) => return false, + _ => { + break; + } + } + + index += 1; + } + } + + true + } +} From 8b5326e69266bcf09780191720619c3284ff7c84 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 14 Mar 2023 23:11:03 +0800 Subject: [PATCH 0800/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 95329dac..a57f1d56 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 443 | 186 | 232 | 25 | +| 444 | 187 | 232 | 25 | ### 题目 @@ -450,4 +450,5 @@ |1000263 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aMhZSa.rs) | [leetcode](https://leetcode-cn.com/problems/aMhZSa/) | Easy | |1000273 | 有效的变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dKk3P7.rs) | [leetcode](https://leetcode-cn.com/problems/dKk3P7/) | Easy | |1000275 | 变位词组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sfvd7V.rs) | [leetcode](https://leetcode-cn.com/problems/sfvd7V/) | Medium | +|1000276 | 外星语言是否排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lwyVBB.rs) | [leetcode](https://leetcode-cn.com/problems/lwyVBB/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From da57274b6a83ab4d6f797c261363c9683f1ac975 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 15 Mar 2023 23:02:54 +0800 Subject: [PATCH 0801/1556] src/bin/569nqc.rs --- src/bin/569nqc.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/bin/569nqc.rs diff --git a/src/bin/569nqc.rs b/src/bin/569nqc.rs new file mode 100644 index 00000000..dba91787 --- /dev/null +++ b/src/bin/569nqc.rs @@ -0,0 +1,43 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use core::time; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_min_difference(time_points: Vec) -> i32 { + // 因为只有1440种可能,因此大于这个值的话必定有2个相同的,直接返回0即可 + // 鸽巢原理/抽屉原理 + if time_points.len() > 1440 { + return 0; + } + + let mut time_points = time_points; + time_points.sort(); + + let (h1, m1) = time_points[time_points.len() - 1].split_once(':').unwrap(); + let (h2, m2) = time_points[0].split_once(':').unwrap(); + + let mut t = h2.trim_start_matches('0').parse::().unwrap_or(0) * 60 + + m2.parse::().unwrap_or(0) + + (23 - h1.trim_start_matches('0').parse::().unwrap_or(0)) * 60 + + (60 - m1.trim_start_matches('0').parse::().unwrap_or(0)); + + for i in 1..time_points.len() { + let (h1, m1) = time_points[i - 1].split_once(':').unwrap(); + let (h2, m2) = time_points[i].split_once(':').unwrap(); + + t = t.min( + (h2.trim_start_matches('0').parse::().unwrap_or(0) + - h1.trim_start_matches('0').parse::().unwrap_or(0)) + * 60 + + m2.trim_start_matches('0').parse::().unwrap_or(0) + - m1.trim_start_matches('0').parse::().unwrap_or(0), + ); + } + + t + } +} From 27582533a95919668d461e5f268bda3e4acbd0f1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 15 Mar 2023 23:02:55 +0800 Subject: [PATCH 0802/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a57f1d56..82ce6b2f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 444 | 187 | 232 | 25 | +| 445 | 187 | 233 | 25 | ### 题目 @@ -451,4 +451,5 @@ |1000273 | 有效的变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dKk3P7.rs) | [leetcode](https://leetcode-cn.com/problems/dKk3P7/) | Easy | |1000275 | 变位词组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sfvd7V.rs) | [leetcode](https://leetcode-cn.com/problems/sfvd7V/) | Medium | |1000276 | 外星语言是否排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lwyVBB.rs) | [leetcode](https://leetcode-cn.com/problems/lwyVBB/) | Easy | +|1000278 | 最小时间差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/569nqc.rs) | [leetcode](https://leetcode-cn.com/problems/569nqc/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From eec30f6b5c220815cdc14f83d52e0b536b6ada94 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 16 Mar 2023 08:47:21 +0800 Subject: [PATCH 0803/1556] src/bin/8Zf90G.rs --- src/bin/8Zf90G.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/bin/8Zf90G.rs diff --git a/src/bin/8Zf90G.rs b/src/bin/8Zf90G.rs new file mode 100644 index 00000000..0d893b9f --- /dev/null +++ b/src/bin/8Zf90G.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 逆波兰表达式配合栈 + pub fn eval_rpn(tokens: Vec) -> i32 { + let mut stack = vec![]; + for i in tokens { + match &*i { + "+" => { + let x = stack.pop().unwrap(); + let y = stack.pop().unwrap(); + stack.push(x + y); + } + "-" => { + let x = stack.pop().unwrap(); + let y = stack.pop().unwrap(); + stack.push(y - x); + } + "*" => { + let x = stack.pop().unwrap(); + let y = stack.pop().unwrap(); + stack.push(x * y); + } + "/" => { + let x = stack.pop().unwrap(); + let y = stack.pop().unwrap(); + stack.push(y / x); + } + s => { + stack.push(s.parse().unwrap()); + } + } + } + + stack.pop().unwrap() + } +} From 719009b03440f1f836892738f8802ed36269373a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 16 Mar 2023 08:47:22 +0800 Subject: [PATCH 0804/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 82ce6b2f..9087d203 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 445 | 187 | 233 | 25 | +| 446 | 187 | 234 | 25 | ### 题目 @@ -452,4 +452,5 @@ |1000275 | 变位词组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sfvd7V.rs) | [leetcode](https://leetcode-cn.com/problems/sfvd7V/) | Medium | |1000276 | 外星语言是否排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lwyVBB.rs) | [leetcode](https://leetcode-cn.com/problems/lwyVBB/) | Easy | |1000278 | 最小时间差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/569nqc.rs) | [leetcode](https://leetcode-cn.com/problems/569nqc/) | Medium | +|1000279 | 后缀表达式 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/8Zf90G.rs) | [leetcode](https://leetcode-cn.com/problems/8Zf90G/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 66418bc2e239f66b26ce83980e671ed95d9ee4d0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 16 Mar 2023 09:44:39 +0800 Subject: [PATCH 0805/1556] src/bin/XagZNi.rs --- src/bin/XagZNi.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/bin/XagZNi.rs diff --git a/src/bin/XagZNi.rs b/src/bin/XagZNi.rs new file mode 100644 index 00000000..8215eaef --- /dev/null +++ b/src/bin/XagZNi.rs @@ -0,0 +1,52 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() { + assert_eq!(Solution::asteroid_collision(vec![5, 10, -5]), vec![5, 10]); + assert_eq!(Solution::asteroid_collision(vec![8, -8]), vec![]); + assert_eq!(Solution::asteroid_collision(vec![10, 2, -5]), vec![10]); + assert_eq!( + Solution::asteroid_collision(vec![-2, -1, 1, 2]), + vec![-2, -1, 1, 2] + ); +} + +struct Solution; + +impl Solution { + pub fn asteroid_collision(asteroids: Vec) -> Vec { + let mut v = vec![]; + + for i in asteroids { + v.push(i); + while v.len() > 1 { + let l1 = v[v.len() - 1]; + if l1 > 0 { + break; + } + + let l2 = v[v.len() - 2]; + + if l1 < 0 && l2 > 0 { + if l1.abs() > l2 { + let i = v.len() - 2; + v[i] = l1; + v.pop(); + } else if l1.abs() == l2 { + v.pop(); + v.pop(); + break; + } else { + v.pop(); + break; + } + } else { + break; + } + } + } + + v + } +} From c35af9de6b745fc869759bd1e9112f5f61320dfa Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 16 Mar 2023 09:44:39 +0800 Subject: [PATCH 0806/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9087d203..7a8ef93a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 446 | 187 | 234 | 25 | +| 447 | 187 | 235 | 25 | ### 题目 @@ -453,4 +453,5 @@ |1000276 | 外星语言是否排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lwyVBB.rs) | [leetcode](https://leetcode-cn.com/problems/lwyVBB/) | Easy | |1000278 | 最小时间差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/569nqc.rs) | [leetcode](https://leetcode-cn.com/problems/569nqc/) | Medium | |1000279 | 后缀表达式 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/8Zf90G.rs) | [leetcode](https://leetcode-cn.com/problems/8Zf90G/) | Medium | +|1000281 | 小行星碰撞 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XagZNi.rs) | [leetcode](https://leetcode-cn.com/problems/XagZNi/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 13968ad197d53e0bc00dd6b44faea82c0ab57358 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 19 Mar 2023 20:32:27 +0800 Subject: [PATCH 0807/1556] src/bin/iIQa4I.rs --- src/bin/iIQa4I.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/bin/iIQa4I.rs diff --git a/src/bin/iIQa4I.rs b/src/bin/iIQa4I.rs new file mode 100644 index 00000000..fee60fe8 --- /dev/null +++ b/src/bin/iIQa4I.rs @@ -0,0 +1,33 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!( + Solution::daily_temperatures(vec![73, 74, 75, 71, 69, 72, 76, 73]), + vec![1, 1, 4, 2, 1, 1, 0, 0] + ) +} + +struct Solution; + +impl Solution { + /// 单调递减栈,保存下标 + pub fn daily_temperatures(temperatures: Vec) -> Vec { + let mut stack = vec![]; + let mut ans = vec![0; temperatures.len()]; + + for i in 0..temperatures.len() { + while !stack.is_empty() { + if temperatures[stack[stack.len() - 1]] < temperatures[i] { + ans[stack[stack.len() - 1]] = (i - stack[stack.len() - 1]) as i32; + stack.pop(); + } else { + break; + } + } + + stack.push(i); + } + + ans + } +} From 7cc64654c26c87f3e8693f7ba06fa29da2bf742b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 19 Mar 2023 20:32:28 +0800 Subject: [PATCH 0808/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a8ef93a..7c87166e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 447 | 187 | 235 | 25 | +| 448 | 187 | 236 | 25 | ### 题目 @@ -454,4 +454,5 @@ |1000278 | 最小时间差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/569nqc.rs) | [leetcode](https://leetcode-cn.com/problems/569nqc/) | Medium | |1000279 | 后缀表达式 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/8Zf90G.rs) | [leetcode](https://leetcode-cn.com/problems/8Zf90G/) | Medium | |1000281 | 小行星碰撞 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XagZNi.rs) | [leetcode](https://leetcode-cn.com/problems/XagZNi/) | Medium | +|1000282 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/iIQa4I.rs) | [leetcode](https://leetcode-cn.com/problems/iIQa4I/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From c19dce848bb1c36d2d5b4d5466d5e151fc389ef6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 20 Mar 2023 12:22:43 +0800 Subject: [PATCH 0809/1556] src/bin/qIsx9U.rs --- src/bin/qIsx9U.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/bin/qIsx9U.rs diff --git a/src/bin/qIsx9U.rs b/src/bin/qIsx9U.rs new file mode 100644 index 00000000..6ead6d30 --- /dev/null +++ b/src/bin/qIsx9U.rs @@ -0,0 +1,45 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +struct MovingAverage { + v: Vec, + len: f64, + index: usize, + sum: f64, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl MovingAverage { + /** Initialize your data structure here. */ + fn new(size: i32) -> Self { + Self { + v: vec![0f64; size as usize], + len: 0f64, + index: 0, + sum: 0f64, + } + } + + fn next(&mut self, val: i32) -> f64 { + self.sum += val as f64; + self.sum -= self.v[self.index]; + self.v[self.index] = val as f64; + self.index += 1; + + if self.len < self.v.len() as f64 { + self.len += 1f64; + } + + if self.index >= self.v.len() { + self.index = 0; + } + + self.sum / self.len as f64 + } +} From 485bd26382839ae49dd70a8ac8004ca4b302c286 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 20 Mar 2023 12:22:45 +0800 Subject: [PATCH 0810/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c87166e..5ae17e99 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 448 | 187 | 236 | 25 | +| 449 | 188 | 236 | 25 | ### 题目 @@ -455,4 +455,5 @@ |1000279 | 后缀表达式 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/8Zf90G.rs) | [leetcode](https://leetcode-cn.com/problems/8Zf90G/) | Medium | |1000281 | 小行星碰撞 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XagZNi.rs) | [leetcode](https://leetcode-cn.com/problems/XagZNi/) | Medium | |1000282 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/iIQa4I.rs) | [leetcode](https://leetcode-cn.com/problems/iIQa4I/) | Medium | +|1000292 | 滑动窗口的平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qIsx9U.rs) | [leetcode](https://leetcode-cn.com/problems/qIsx9U/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From c91a10e64d9e2d9f72d1d20da55f698932662580 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 21 Mar 2023 23:22:39 +0800 Subject: [PATCH 0811/1556] src/bin/NaqhDT.rs --- src/bin/NaqhDT.rs | 99 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/bin/NaqhDT.rs diff --git a/src/bin/NaqhDT.rs b/src/bin/NaqhDT.rs new file mode 100644 index 00000000..2d576547 --- /dev/null +++ b/src/bin/NaqhDT.rs @@ -0,0 +1,99 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::{cell::RefCell, rc::Rc}; + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +struct CBTInserter { + count: i32, + root: Option>>, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +impl CBTInserter { + fn new(root: Option>>) -> Self { + let mut count = 0; + let mut stack = vec![]; + if root.is_some() { + stack.push(root.clone().unwrap()); + } + while !stack.is_empty() { + let mut new_stack = vec![]; + while let Some(s) = stack.pop() { + if s.borrow().left.is_some() { + new_stack.push(s.borrow().left.clone().unwrap()); + } + + if s.borrow().right.is_some() { + new_stack.push(s.borrow().right.clone().unwrap()); + } + count += 1; + } + + stack = new_stack; + } + + Self { root, count } + } + + fn insert(&mut self, v: i32) -> i32 { + self.count += 1; + + let mut node = self.root.clone(); + + for i in (1..=self.get_bits_len() - 2).rev() { + if self.count >> i & 1 == 0 { + node = node.map(|x| x.borrow().left.clone().unwrap()); + } else { + node = node.map(|x| x.borrow().right.clone().unwrap()); + } + } + let ans = node.as_deref().unwrap().borrow().val; + + if self.count & 1 == 0 { + node.unwrap().borrow_mut().left = Some(Rc::new(RefCell::new(TreeNode::new(v)))); + } else { + node.unwrap().borrow_mut().right = Some(Rc::new(RefCell::new(TreeNode::new(v)))); + } + + ans + } + + fn get_root(&self) -> Option>> { + self.root.clone() + } + + fn get_bits_len(&self) -> i32 { + let mut ans = 0; + let mut c = self.count; + while c > 0 { + ans += 1; + c >>= 1; + } + + ans + } +} From 1c4c98515f5a4d01e4fd2337ee3dbfd989dd9772 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 21 Mar 2023 23:22:39 +0800 Subject: [PATCH 0812/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ae17e99..f24291cb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 449 | 188 | 236 | 25 | +| 450 | 188 | 237 | 25 | ### 题目 @@ -456,4 +456,5 @@ |1000281 | 小行星碰撞 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XagZNi.rs) | [leetcode](https://leetcode-cn.com/problems/XagZNi/) | Medium | |1000282 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/iIQa4I.rs) | [leetcode](https://leetcode-cn.com/problems/iIQa4I/) | Medium | |1000292 | 滑动窗口的平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qIsx9U.rs) | [leetcode](https://leetcode-cn.com/problems/qIsx9U/) | Easy | +|1000295 | 往完全二叉树添加节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NaqhDT.rs) | [leetcode](https://leetcode-cn.com/problems/NaqhDT/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 2b334f400344314dc60d84506ef8c4581600e866 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 22 Mar 2023 21:56:09 +0800 Subject: [PATCH 0813/1556] src/bin/hPov7L.rs --- src/bin/hPov7L.rs | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/bin/hPov7L.rs diff --git a/src/bin/hPov7L.rs b/src/bin/hPov7L.rs new file mode 100644 index 00000000..81422274 --- /dev/null +++ b/src/bin/hPov7L.rs @@ -0,0 +1,64 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +use std::vec; +impl Solution { + pub fn largest_values(root: Option>>) -> Vec { + let mut stack = vec![]; + let mut ans = vec![]; + + if root.is_some() { + stack.push(root); + } + + while !stack.is_empty() { + let mut new_stack = vec![]; + let mut max = 0; + + for (i, node) in stack.into_iter().enumerate() { + let node = node.unwrap(); + if node.borrow().left.is_some() { + new_stack.push(node.borrow_mut().left.take()); + } + + if node.borrow().right.is_some() { + new_stack.push(node.borrow_mut().right.take()); + } + + if i == 0 { + max = node.borrow().val; + } else { + max = max.max(node.borrow().val); + } + } + + stack = new_stack; + ans.push(max); + } + + ans + } +} From d38d5c644e048510b119a90a0fbacd3ad1ea4631 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 22 Mar 2023 21:56:10 +0800 Subject: [PATCH 0814/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f24291cb..d6236d26 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 450 | 188 | 237 | 25 | +| 451 | 188 | 238 | 25 | ### 题目 @@ -457,4 +457,5 @@ |1000282 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/iIQa4I.rs) | [leetcode](https://leetcode-cn.com/problems/iIQa4I/) | Medium | |1000292 | 滑动窗口的平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qIsx9U.rs) | [leetcode](https://leetcode-cn.com/problems/qIsx9U/) | Easy | |1000295 | 往完全二叉树添加节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NaqhDT.rs) | [leetcode](https://leetcode-cn.com/problems/NaqhDT/) | Medium | +|1000297 | 二叉树每层的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/hPov7L.rs) | [leetcode](https://leetcode-cn.com/problems/hPov7L/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 7a79560e89812274d558b7a31ebf77c7b8bd9e1f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 23 Mar 2023 20:44:17 +0800 Subject: [PATCH 0815/1556] src/bin/LwUNpT.rs --- src/bin/LwUNpT.rs | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/bin/LwUNpT.rs diff --git a/src/bin/LwUNpT.rs b/src/bin/LwUNpT.rs new file mode 100644 index 00000000..e2a66bed --- /dev/null +++ b/src/bin/LwUNpT.rs @@ -0,0 +1,60 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::cell::RefCell; +use std::rc::Rc; +use std::vec; + +impl Solution { + pub fn find_bottom_left_value(root: Option>>) -> i32 { + let mut stack = vec![root]; + + let mut ans = 0; + + while !stack.is_empty() { + let mut new_stack = vec![]; + + for i in 0..stack.len() { + if i == 0 { + ans = stack[i].clone().as_deref().unwrap().borrow().val; + } + + let node = stack[i].clone().unwrap(); + + if node.borrow().left.is_some() { + new_stack.push(node.borrow_mut().left.take()); + } + + if node.borrow().right.is_some() { + new_stack.push(node.borrow_mut().right.take()); + } + } + + stack = new_stack; + } + + ans + } +} From bc4d01a67eee183983377ca3751f9e01f1346851 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 23 Mar 2023 20:44:18 +0800 Subject: [PATCH 0816/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6236d26..c726830f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 451 | 188 | 238 | 25 | +| 452 | 188 | 239 | 25 | ### 题目 @@ -458,4 +458,5 @@ |1000292 | 滑动窗口的平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qIsx9U.rs) | [leetcode](https://leetcode-cn.com/problems/qIsx9U/) | Easy | |1000295 | 往完全二叉树添加节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NaqhDT.rs) | [leetcode](https://leetcode-cn.com/problems/NaqhDT/) | Medium | |1000297 | 二叉树每层的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/hPov7L.rs) | [leetcode](https://leetcode-cn.com/problems/hPov7L/) | Medium | +|1000298 | 二叉树最底层最左边的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/LwUNpT.rs) | [leetcode](https://leetcode-cn.com/problems/LwUNpT/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 1dadf82158b3a20f49d8daefbf7acdbcabfac128 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 24 Mar 2023 20:10:45 +0800 Subject: [PATCH 0817/1556] src/bin/WNC0Lk.rs --- src/bin/WNC0Lk.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/bin/WNC0Lk.rs diff --git a/src/bin/WNC0Lk.rs b/src/bin/WNC0Lk.rs new file mode 100644 index 00000000..cba13d42 --- /dev/null +++ b/src/bin/WNC0Lk.rs @@ -0,0 +1,54 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::borrow::BorrowMut; +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn right_side_view(root: Option>>) -> Vec { + let mut ans = vec![]; + let mut stack = vec![]; + if root.is_some() { + stack.push(root); + } + + while !stack.is_empty() { + let mut new_stack = vec![]; + ans.push(stack[stack.len() - 1].as_deref().unwrap().borrow().val); + for i in 0..stack.len() { + if stack[i].as_deref().unwrap().borrow().left.is_some() { + new_stack.push(stack[i].as_deref().unwrap().borrow_mut().left.take()); + } + + if stack[i].as_deref().unwrap().borrow().right.is_some() { + new_stack.push(stack[i].as_deref().unwrap().borrow_mut().right.take()); + } + } + + stack = new_stack; + } + + ans + } +} From 5d7528d1f1a8972c1ca2bd9f42c6bb06280ede8a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 24 Mar 2023 20:10:46 +0800 Subject: [PATCH 0818/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c726830f..3e2722d5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 452 | 188 | 239 | 25 | +| 453 | 188 | 240 | 25 | ### 题目 @@ -459,4 +459,5 @@ |1000295 | 往完全二叉树添加节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NaqhDT.rs) | [leetcode](https://leetcode-cn.com/problems/NaqhDT/) | Medium | |1000297 | 二叉树每层的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/hPov7L.rs) | [leetcode](https://leetcode-cn.com/problems/hPov7L/) | Medium | |1000298 | 二叉树最底层最左边的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/LwUNpT.rs) | [leetcode](https://leetcode-cn.com/problems/LwUNpT/) | Medium | +|1000299 | 二叉树的右侧视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WNC0Lk.rs) | [leetcode](https://leetcode-cn.com/problems/WNC0Lk/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 657f810550645bccd4de8b45ed35af169d7ec11e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 Mar 2023 21:13:11 +0800 Subject: [PATCH 0819/1556] src/bin/pOCWxh.rs --- src/bin/pOCWxh.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/bin/pOCWxh.rs diff --git a/src/bin/pOCWxh.rs b/src/bin/pOCWxh.rs new file mode 100644 index 00000000..67a19625 --- /dev/null +++ b/src/bin/pOCWxh.rs @@ -0,0 +1,46 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn prune_tree(root: Option>>) -> Option>> { + if root.is_none() { + return None; + } + + let left = Self::prune_tree(root.clone().unwrap().borrow_mut().left.take()); + let right = Self::prune_tree(root.clone().unwrap().borrow_mut().right.take()); + + if left.is_none() && right.is_none() && root.clone().unwrap().borrow().val == 0 { + return None; + } + + root.clone().unwrap().borrow_mut().left = left; + root.clone().unwrap().borrow_mut().right = right; + + root + } +} From eca49417d360de7ce95b81892aceb981d4a335b0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 Mar 2023 21:13:12 +0800 Subject: [PATCH 0820/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e2722d5..6c499fb8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 453 | 188 | 240 | 25 | +| 454 | 188 | 241 | 25 | ### 题目 @@ -460,4 +460,5 @@ |1000297 | 二叉树每层的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/hPov7L.rs) | [leetcode](https://leetcode-cn.com/problems/hPov7L/) | Medium | |1000298 | 二叉树最底层最左边的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/LwUNpT.rs) | [leetcode](https://leetcode-cn.com/problems/LwUNpT/) | Medium | |1000299 | 二叉树的右侧视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WNC0Lk.rs) | [leetcode](https://leetcode-cn.com/problems/WNC0Lk/) | Medium | +|1000301 | 二叉树剪枝 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pOCWxh.rs) | [leetcode](https://leetcode-cn.com/problems/pOCWxh/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 057f680c703c02e24cad98d70378559f3cfda883 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 26 Mar 2023 22:36:06 +0800 Subject: [PATCH 0821/1556] src/bin/3Etpl5.rs --- src/bin/3Etpl5.rs | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/bin/3Etpl5.rs diff --git a/src/bin/3Etpl5.rs b/src/bin/3Etpl5.rs new file mode 100644 index 00000000..a09ba051 --- /dev/null +++ b/src/bin/3Etpl5.rs @@ -0,0 +1,56 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn sum_numbers(root: Option>>) -> i32 { + let mut sum = 0; + Self::f(&mut sum, 0, root); + sum + } + + fn f(sum: &mut i32, val: i32, root: Option>>) { + if root.is_none() { + return; + } + + let v = root.clone().unwrap().borrow().val; + let left = root.clone().unwrap().borrow_mut().left.take(); + let right = root.clone().unwrap().borrow_mut().right.take(); + + if left.is_none() && right.is_none() { + *sum += v + val * 10; + return; + } + + if left.is_some() { + Self::f(sum, v + val * 10, left); + } + + if right.is_some() { + Self::f(sum, v + val * 10, right); + } + } +} From 8a19e5ff8473c286c7f9982aa21fc5af5059f306 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 26 Mar 2023 22:36:08 +0800 Subject: [PATCH 0822/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c499fb8..43775fce 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 454 | 188 | 241 | 25 | +| 455 | 188 | 242 | 25 | ### 题目 @@ -461,4 +461,5 @@ |1000298 | 二叉树最底层最左边的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/LwUNpT.rs) | [leetcode](https://leetcode-cn.com/problems/LwUNpT/) | Medium | |1000299 | 二叉树的右侧视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WNC0Lk.rs) | [leetcode](https://leetcode-cn.com/problems/WNC0Lk/) | Medium | |1000301 | 二叉树剪枝 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pOCWxh.rs) | [leetcode](https://leetcode-cn.com/problems/pOCWxh/) | Medium | +|1000306 | 从根节点到叶节点的路径数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3Etpl5.rs) | [leetcode](https://leetcode-cn.com/problems/3Etpl5/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 77f34eefb4f68ddc31a08784f241d994f60f8402 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 28 Mar 2023 22:45:19 +0800 Subject: [PATCH 0823/1556] src/bin/6eUYwP.rs --- src/bin/6eUYwP.rs | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/bin/6eUYwP.rs diff --git a/src/bin/6eUYwP.rs b/src/bin/6eUYwP.rs new file mode 100644 index 00000000..8fbc6690 --- /dev/null +++ b/src/bin/6eUYwP.rs @@ -0,0 +1,56 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn path_sum(root: Option>>, target_sum: i32) -> i32 { + let mut ans = 0; + ans += Self::travel(root.clone(), target_sum as i64); + if root.is_some() { + ans += Self::path_sum(root.clone().unwrap().borrow().left.clone(), target_sum); + ans += Self::path_sum(root.clone().unwrap().borrow().right.clone(), target_sum); + } + + ans + } + + pub fn travel(root: Option>>, target_sum: i64) -> i32 { + if root.is_none() { + return 0; + } + + let mut ans = 0; + let root = root.unwrap(); + let val = root.borrow().val as i64; + if target_sum == val { + ans += 1; + } + + let left = root.borrow().left.clone(); + let right = root.borrow().right.clone(); + + ans + Self::travel(left, target_sum - val) + Self::travel(right, target_sum - val) + } +} From 28b1631a094ca311866dfff39fa423d8107d534a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 28 Mar 2023 22:45:20 +0800 Subject: [PATCH 0824/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 43775fce..e07663dd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 455 | 188 | 242 | 25 | +| 456 | 188 | 243 | 25 | ### 题目 @@ -462,4 +462,5 @@ |1000299 | 二叉树的右侧视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WNC0Lk.rs) | [leetcode](https://leetcode-cn.com/problems/WNC0Lk/) | Medium | |1000301 | 二叉树剪枝 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pOCWxh.rs) | [leetcode](https://leetcode-cn.com/problems/pOCWxh/) | Medium | |1000306 | 从根节点到叶节点的路径数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3Etpl5.rs) | [leetcode](https://leetcode-cn.com/problems/3Etpl5/) | Medium | +|1000307 | 向下的路径节点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/6eUYwP.rs) | [leetcode](https://leetcode-cn.com/problems/6eUYwP/) | Medium | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 0aed70998b65f75e0cfeefd18f32d31cf8c0bfca Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 29 Mar 2023 22:25:54 +0800 Subject: [PATCH 0825/1556] src/bin/NYBBNL.rs --- src/bin/NYBBNL.rs | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/bin/NYBBNL.rs diff --git a/src/bin/NYBBNL.rs b/src/bin/NYBBNL.rs new file mode 100644 index 00000000..70327e8b --- /dev/null +++ b/src/bin/NYBBNL.rs @@ -0,0 +1,67 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn increasing_bst(root: Option>>) -> Option>> { + if root.is_none() { + return None; + } + + let (ans, _) = Self::f(root); + ans + } + + // 返回头部和尾部 + fn f( + root: Option>>, + ) -> (Option>>, Option>>) { + let root = root.unwrap(); + let left = root.borrow_mut().left.take(); + let right = root.borrow_mut().right.take(); + + match (left, right) { + (Some(l), Some(r)) => { + let (n1, m1) = Self::f(Some(l)); + let (n2, m2) = Self::f(Some(r)); + m1.clone().unwrap().borrow_mut().right = Some(root.clone()); + root.borrow_mut().right = n2; + (n1, m2) + } + (Some(l), None) => { + let (n, m) = Self::f(Some(l)); + m.clone().unwrap().borrow_mut().right = Some(root.clone()); + (n, Some(root.clone())) + } + (None, Some(r)) => { + let (n, m) = Self::f(Some(r)); + root.borrow_mut().right = n; + (Some(root), m) + } + (None, None) => (Some(root.clone()), Some(root.clone())), + } + } +} From c4c70a2d9c1967ed1afcc7e8b007d5dcea263791 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 29 Mar 2023 22:25:55 +0800 Subject: [PATCH 0826/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e07663dd..ffa64e00 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 456 | 188 | 243 | 25 | +| 457 | 189 | 243 | 25 | ### 题目 @@ -463,4 +463,5 @@ |1000301 | 二叉树剪枝 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pOCWxh.rs) | [leetcode](https://leetcode-cn.com/problems/pOCWxh/) | Medium | |1000306 | 从根节点到叶节点的路径数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3Etpl5.rs) | [leetcode](https://leetcode-cn.com/problems/3Etpl5/) | Medium | |1000307 | 向下的路径节点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/6eUYwP.rs) | [leetcode](https://leetcode-cn.com/problems/6eUYwP/) | Medium | +|1000311 | 展平二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NYBBNL.rs) | [leetcode](https://leetcode-cn.com/problems/NYBBNL/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 2b045425fd273547c01d99884f099624bcfa99a7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 31 Mar 2023 23:36:51 +0800 Subject: [PATCH 0827/1556] src/bin/opLdQZ.rs --- src/bin/opLdQZ.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/bin/opLdQZ.rs diff --git a/src/bin/opLdQZ.rs b/src/bin/opLdQZ.rs new file mode 100644 index 00000000..9108e8b2 --- /dev/null +++ b/src/bin/opLdQZ.rs @@ -0,0 +1,52 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn find_target(root: Option>>, k: i32) -> bool { + let mut hash = std::collections::HashMap::new(); + Self::f(root, &mut hash, k) + } + + pub fn f( + root: Option>>, + hash: &mut std::collections::HashMap, + k: i32, + ) -> bool { + if root.is_none() { + return false; + } + let val = root.clone().unwrap().borrow().val; + if hash.contains_key(&(k - val)) { + return true; + } + + hash.insert(val, ()); + let left = root.clone().unwrap().borrow().left.clone(); + let right = root.clone().unwrap().borrow().right.clone(); + + Self::f(left, hash, k) || Self::f(right, hash, k) + } +} From 2af01857fed1268bc013750b3fcd308246a4cb28 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 31 Mar 2023 23:36:54 +0800 Subject: [PATCH 0828/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ffa64e00..b8f27f8d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 457 | 189 | 243 | 25 | +| 458 | 190 | 243 | 25 | ### 题目 @@ -464,4 +464,5 @@ |1000306 | 从根节点到叶节点的路径数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3Etpl5.rs) | [leetcode](https://leetcode-cn.com/problems/3Etpl5/) | Medium | |1000307 | 向下的路径节点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/6eUYwP.rs) | [leetcode](https://leetcode-cn.com/problems/6eUYwP/) | Medium | |1000311 | 展平二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NYBBNL.rs) | [leetcode](https://leetcode-cn.com/problems/NYBBNL/) | Easy | +|1000319 | 二叉搜索树中两个节点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/opLdQZ.rs) | [leetcode](https://leetcode-cn.com/problems/opLdQZ/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From be813d0847188be248bfdb790f792dd0af87a2ae Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 1 Apr 2023 22:33:29 +0800 Subject: [PATCH 0829/1556] src/bin/B1IidL.rs --- src/bin/B1IidL.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/B1IidL.rs diff --git a/src/bin/B1IidL.rs b/src/bin/B1IidL.rs new file mode 100644 index 00000000..9b91cb10 --- /dev/null +++ b/src/bin/B1IidL.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn peak_index_in_mountain_array(arr: Vec) -> i32 { + let (mut start, mut end) = (0, arr.len() - 1); + + while start < end { + let mut middle = (start + end) / 2; + if arr[middle] > arr[middle - 1] && arr[middle] > arr[middle + 1] { + return middle as i32; + } else if arr[middle] > arr[middle - 1] && arr[middle] < arr[middle + 1] { + start = middle + 1; + } else { + end = middle; + } + } + + unreachable!() + } +} From 7569b55dafa0f087401c7802ced141f61db16dc5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 1 Apr 2023 22:33:29 +0800 Subject: [PATCH 0830/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b8f27f8d..21471684 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 458 | 190 | 243 | 25 | +| 459 | 191 | 243 | 25 | ### 题目 @@ -465,4 +465,5 @@ |1000307 | 向下的路径节点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/6eUYwP.rs) | [leetcode](https://leetcode-cn.com/problems/6eUYwP/) | Medium | |1000311 | 展平二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NYBBNL.rs) | [leetcode](https://leetcode-cn.com/problems/NYBBNL/) | Easy | |1000319 | 二叉搜索树中两个节点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/opLdQZ.rs) | [leetcode](https://leetcode-cn.com/problems/opLdQZ/) | Easy | +|1000333 | 山峰数组的顶部 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/B1IidL.rs) | [leetcode](https://leetcode-cn.com/problems/B1IidL/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From 3a48732e448e15bc2435fe3b1f0f4a9061295833 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 2 Apr 2023 23:09:28 +0800 Subject: [PATCH 0831/1556] src/bin/YaVDxD.rs --- src/bin/YaVDxD.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/YaVDxD.rs diff --git a/src/bin/YaVDxD.rs b/src/bin/YaVDxD.rs new file mode 100644 index 00000000..59f4eb82 --- /dev/null +++ b/src/bin/YaVDxD.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_target_sum_ways(nums: Vec, target: i32) -> i32 { + Self::f(&nums[..], target) + } + + fn f(nums: &[i32], target: i32) -> i32 { + if nums.len() == 0 { + if target == 0 { + return 1; + } else { + return 0; + } + } + + Self::f(&nums[1..], target - nums[0]) + Self::f(&nums[1..], target + nums[0]) + } +} From cbf2d30b21e0d8f0ad173c16604e50a4988d102c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 2 Apr 2023 23:09:29 +0800 Subject: [PATCH 0832/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 21471684..ecb2f368 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 459 | 191 | 243 | 25 | +| 460 | 191 | 244 | 25 | ### 题目 @@ -455,6 +455,7 @@ |1000279 | 后缀表达式 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/8Zf90G.rs) | [leetcode](https://leetcode-cn.com/problems/8Zf90G/) | Medium | |1000281 | 小行星碰撞 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XagZNi.rs) | [leetcode](https://leetcode-cn.com/problems/XagZNi/) | Medium | |1000282 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/iIQa4I.rs) | [leetcode](https://leetcode-cn.com/problems/iIQa4I/) | Medium | +|1000288 | 加减的目标值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/YaVDxD.rs) | [leetcode](https://leetcode-cn.com/problems/YaVDxD/) | Medium | |1000292 | 滑动窗口的平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qIsx9U.rs) | [leetcode](https://leetcode-cn.com/problems/qIsx9U/) | Easy | |1000295 | 往完全二叉树添加节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NaqhDT.rs) | [leetcode](https://leetcode-cn.com/problems/NaqhDT/) | Medium | |1000297 | 二叉树每层的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/hPov7L.rs) | [leetcode](https://leetcode-cn.com/problems/hPov7L/) | Medium | From 45208bf886191c7ec40a526b0e1e15928e7f9fe8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 5 Apr 2023 23:02:48 +0800 Subject: [PATCH 0833/1556] src/bin/7WqeDu.rs --- src/bin/7WqeDu.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/7WqeDu.rs diff --git a/src/bin/7WqeDu.rs b/src/bin/7WqeDu.rs new file mode 100644 index 00000000..d3bba7c2 --- /dev/null +++ b/src/bin/7WqeDu.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn contains_nearby_almost_duplicate(nums: Vec, k: i32, t: i32) -> bool { + for i in 0..nums.len() { + for j in 0..nums.len() { + if i == j { + continue; + } + + if (nums[i] as i64 - nums[j] as i64).abs() <= t as i64 + && (i as i32 - j as i32).abs() <= k + { + return true; + } + } + } + + false + } +} From 6df22031945a8e19bcc1569cd6aa2e8fdbe5c615 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 5 Apr 2023 23:02:48 +0800 Subject: [PATCH 0834/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ecb2f368..277bcc9a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 460 | 191 | 244 | 25 | +| 461 | 191 | 245 | 25 | ### 题目 @@ -466,5 +466,6 @@ |1000307 | 向下的路径节点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/6eUYwP.rs) | [leetcode](https://leetcode-cn.com/problems/6eUYwP/) | Medium | |1000311 | 展平二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NYBBNL.rs) | [leetcode](https://leetcode-cn.com/problems/NYBBNL/) | Easy | |1000319 | 二叉搜索树中两个节点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/opLdQZ.rs) | [leetcode](https://leetcode-cn.com/problems/opLdQZ/) | Easy | +|1000321 | 值和下标之差都在给定的范围内 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WqeDu.rs) | [leetcode](https://leetcode-cn.com/problems/7WqeDu/) | Medium | |1000333 | 山峰数组的顶部 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/B1IidL.rs) | [leetcode](https://leetcode-cn.com/problems/B1IidL/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | From d0e183cd6c34323fcc56b1d3e4185569cc49a00f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 18 Apr 2023 20:56:47 +0800 Subject: [PATCH 0835/1556] src/bin/merge-strings-alternately.rs --- src/bin/merge-strings-alternately.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/merge-strings-alternately.rs diff --git a/src/bin/merge-strings-alternately.rs b/src/bin/merge-strings-alternately.rs new file mode 100644 index 00000000..13e7896b --- /dev/null +++ b/src/bin/merge-strings-alternately.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn merge_alternately(word1: String, word2: String) -> String { + let mut ans = Vec::with_capacity(word1.len() + word2.len()); + let mut i = 0; + + while i < word1.len() && i < word2.len() { + ans.push(word1.as_bytes()[i]); + ans.push(word2.as_bytes()[i]); + i += 1; + } + + ans.extend(word1.as_bytes()[i..].iter()); + ans.extend(word2.as_bytes()[i..].iter()); + + unsafe { String::from_utf8_unchecked(ans) } + } +} From 58e56a1a26fdcf3a0598d5afca3e28a4a7e04c10 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 18 Apr 2023 20:56:47 +0800 Subject: [PATCH 0836/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 277bcc9a..1cdc66e1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 461 | 191 | 245 | 25 | +| 462 | 192 | 245 | 25 | ### 题目 @@ -342,6 +342,7 @@ |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | |1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | +|1894 | 交替合并字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-strings-alternately.rs) | [leetcode](https://leetcode-cn.com/problems/merge-strings-alternately/) | Easy | |1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | |1952 | 最少侧跳次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sideway-jumps.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sideway-jumps/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | From d2bd7a9f3d7af0437a6df340320863d8bc19725c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 10 Jun 2023 22:08:23 +0800 Subject: [PATCH 0837/1556] src/bin/compare-strings-by-frequency-of-the-smallest-character.rs --- ...-by-frequency-of-the-smallest-character.rs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/bin/compare-strings-by-frequency-of-the-smallest-character.rs diff --git a/src/bin/compare-strings-by-frequency-of-the-smallest-character.rs b/src/bin/compare-strings-by-frequency-of-the-smallest-character.rs new file mode 100644 index 00000000..fb0884cb --- /dev/null +++ b/src/bin/compare-strings-by-frequency-of-the-smallest-character.rs @@ -0,0 +1,51 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn num_smaller_by_frequency(queries: Vec, words: Vec) -> Vec { + let s1 = queries + .into_iter() + .map(|x| Self::count(x.as_bytes())) + .collect::>(); + + let s2 = words + .into_iter() + .map(|x| Self::count(x.as_bytes())) + .collect::>(); + + let mut result = vec![]; + + for i in s1 { + let mut count = 0; + + for j in s2.iter() { + if i < *j { + count += 1; + } + } + + result.push(count); + } + + result + } + + fn count(s: &[u8]) -> i32 { + let mut count = 1; + let mut min = s[0]; + + for &i in &s[1..] { + if i < min { + min = i; + count = 1; + } else if i == min { + count += 1; + } + } + + count + } +} From 439dcc1b3f76a76ef9675d14f3cb8d7d5cf73874 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 10 Jun 2023 22:08:23 +0800 Subject: [PATCH 0838/1556] src/bin/elimination-game.rs --- src/bin/elimination-game.rs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/bin/elimination-game.rs diff --git a/src/bin/elimination-game.rs b/src/bin/elimination-game.rs new file mode 100644 index 00000000..374abae3 --- /dev/null +++ b/src/bin/elimination-game.rs @@ -0,0 +1,9 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn last_remaining(n: i32) -> i32 {} +} From b67160fd9de876b0dd201556f52a6cf6270fc5b1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 10 Jun 2023 22:08:24 +0800 Subject: [PATCH 0839/1556] README.md --- README.md | 4 +++- src/bin/elimination-game.rs | 9 --------- 2 files changed, 3 insertions(+), 10 deletions(-) delete mode 100644 src/bin/elimination-game.rs diff --git a/README.md b/README.md index 1cdc66e1..6f4c10b4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 462 | 192 | 245 | 25 | +| 464 | 192 | 247 | 25 | ### 题目 @@ -214,6 +214,7 @@ |386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | |387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | |389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | +|390 | 消除游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/elimination-game.rs) | [leetcode](https://leetcode-cn.com/problems/elimination-game/) | Medium | |392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | |393 | UTF-8 编码验证 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/utf-8-validation.rs) | [leetcode](https://leetcode-cn.com/problems/utf-8-validation/) | Medium | |397 | 整数替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-replacement.rs) | [leetcode](https://leetcode-cn.com/problems/integer-replacement/) | Medium | @@ -308,6 +309,7 @@ |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | |1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | +|1273 | 比较字符串最小字母出现频次 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-strings-by-frequency-of-the-smallest-character.rs) | [leetcode](https://leetcode-cn.com/problems/compare-strings-by-frequency-of-the-smallest-character/) | Medium | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | |1293 | 存在连续三个奇数的数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/three-consecutive-odds.rs) | [leetcode](https://leetcode-cn.com/problems/three-consecutive-odds/) | Easy | |1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | diff --git a/src/bin/elimination-game.rs b/src/bin/elimination-game.rs deleted file mode 100644 index 374abae3..00000000 --- a/src/bin/elimination-game.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![allow(dead_code, unused, unused_variables, non_snake_case)] - -fn main() {} - -struct Solution; - -impl Solution { - pub fn last_remaining(n: i32) -> i32 {} -} From 8399cb052a725f426f02d75d5936f3cc552666e9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 12 Jun 2023 21:20:26 +0800 Subject: [PATCH 0840/1556] src/bin/remove-zero-sum-consecutive-nodes-from-linked-list.rs --- ...-sum-consecutive-nodes-from-linked-list.rs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/bin/remove-zero-sum-consecutive-nodes-from-linked-list.rs diff --git a/src/bin/remove-zero-sum-consecutive-nodes-from-linked-list.rs b/src/bin/remove-zero-sum-consecutive-nodes-from-linked-list.rs new file mode 100644 index 00000000..8dce1e3b --- /dev/null +++ b/src/bin/remove-zero-sum-consecutive-nodes-from-linked-list.rs @@ -0,0 +1,59 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} +impl Solution { + pub fn remove_zero_sum_sublists(head: Option>) -> Option> { + if head.is_none() { + return head; + } + + let mut dummy = Box::new(ListNode::new(0)); + dummy.next = head; + + let mut pre_sum = std::collections::HashMap::new(); + pre_sum.insert(0, dummy.as_ref()); + let mut sum = 0; + let mut p = dummy.next.as_ref(); + + while let Some(n) = p { + sum += n.val; + p = n.next.as_ref(); + pre_sum.insert(sum, n.as_ref()); + } + + let mut ans = Box::new(ListNode::new(0)); + let mut p = Some(&mut ans); + let mut sum = 0; + + while let Some(n) = p { + sum += n.val; + + if let Some(q) = pre_sum.get(&sum) { + n.next = match q.next.as_ref() { + Some(next) => Some(Box::new(ListNode::new(next.val))), + None => None, + } + } + + p = n.next.as_mut(); + } + + ans.next + } +} From 0b599a6af91494a2dc2ba7f35c400214e74969d0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 13 Jun 2023 21:27:28 +0800 Subject: [PATCH 0841/1556] src/bin/number-of-unequal-triplets-in-array.rs --- .../number-of-unequal-triplets-in-array.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/number-of-unequal-triplets-in-array.rs diff --git a/src/bin/number-of-unequal-triplets-in-array.rs b/src/bin/number-of-unequal-triplets-in-array.rs new file mode 100644 index 00000000..79cb58fa --- /dev/null +++ b/src/bin/number-of-unequal-triplets-in-array.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn unequal_triplets(nums: Vec) -> i32 { + let mut h = std::collections::HashMap::new(); + let n = nums.len() as i32; + for i in nums { + h.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + + let mut ans = 0; + let mut x = 0; + // 当前元素的个数为v + // 当前元素前面的元素个数为x + // 当前元素后面的个数为n-x-v + // 则当前元素为中间元素可以组成 x * v * (n - v - x) 个数 + for (_, v) in h.into_iter() { + ans += x * v * (n - v - x); + x += v; + } + + ans + } +} From 48222db6b49d61cf9a399c3e28ca9aaa728e575c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 13 Jun 2023 21:27:29 +0800 Subject: [PATCH 0842/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6f4c10b4..5922836e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 464 | 192 | 247 | 25 | +| 465 | 193 | 247 | 25 | ### 题目 @@ -351,6 +351,7 @@ |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | +|2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | From 278402882f8e1579183bc9cbf768cc4c3662cff5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 14 Jun 2023 20:42:11 +0800 Subject: [PATCH 0843/1556] src/bin/number-of-times-binary-string-is-prefix-aligned.rs --- ...f-times-binary-string-is-prefix-aligned.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/number-of-times-binary-string-is-prefix-aligned.rs diff --git a/src/bin/number-of-times-binary-string-is-prefix-aligned.rs b/src/bin/number-of-times-binary-string-is-prefix-aligned.rs new file mode 100644 index 00000000..d60ac465 --- /dev/null +++ b/src/bin/number-of-times-binary-string-is-prefix-aligned.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn num_times_all_blue(flips: Vec) -> i32 { + let mut ans = 0; + let mut right = 0; + + for (i, v) in flips.into_iter().enumerate() { + right = right.max(v as i32); + if i as i32 + 1 == right { + ans += 1; + } + } + + ans + } +} From 6b97e3f3a51f583c85f4e552ab46dd55be09eaf7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 14 Jun 2023 20:42:12 +0800 Subject: [PATCH 0844/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5922836e..cd07b2d8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 465 | 193 | 247 | 25 | +| 466 | 193 | 248 | 25 | ### 题目 @@ -327,6 +327,7 @@ |1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | |1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | |1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | +|1491 | 二进制字符串前缀一致的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-times-binary-string-is-prefix-aligned.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-times-binary-string-is-prefix-aligned/) | Medium | |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | |1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | |1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | From ac5957c296ca6102ac7ce03906891c863ae8845d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 17 Jun 2023 20:56:43 +0800 Subject: [PATCH 0845/1556] src/bin/minimum-cuts-to-divide-a-circle.rs --- src/bin/minimum-cuts-to-divide-a-circle.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/bin/minimum-cuts-to-divide-a-circle.rs diff --git a/src/bin/minimum-cuts-to-divide-a-circle.rs b/src/bin/minimum-cuts-to-divide-a-circle.rs new file mode 100644 index 00000000..89d169e1 --- /dev/null +++ b/src/bin/minimum-cuts-to-divide-a-circle.rs @@ -0,0 +1,17 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn number_of_cuts(n: i32) -> i32 { + if n % 2 == 0 { + n / 2 + } else if n == 1 { + 0 + } else { + n + } + } +} From b3899e4c6d8aff618248c428d296cbe8bbe1ac8a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 17 Jun 2023 20:56:44 +0800 Subject: [PATCH 0846/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cd07b2d8..98070c07 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 466 | 193 | 248 | 25 | +| 467 | 194 | 248 | 25 | ### 题目 @@ -353,6 +353,7 @@ |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | +|2575 | 分割圆的最少切割次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cuts-to-divide-a-circle.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cuts-to-divide-a-circle/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | From a473dfe30c00acf2a6b770144806e14cdd891cdc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 18 Jun 2023 20:18:38 +0800 Subject: [PATCH 0847/1556] src/bin/number-of-closed-islands.rs --- src/bin/number-of-closed-islands.rs | 67 +++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/bin/number-of-closed-islands.rs diff --git a/src/bin/number-of-closed-islands.rs b/src/bin/number-of-closed-islands.rs new file mode 100644 index 00000000..0b5433d9 --- /dev/null +++ b/src/bin/number-of-closed-islands.rs @@ -0,0 +1,67 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + // 从四个边界开始寻找,找到陆地变成水 + // 然后再次遍历,为陆地的地方即为岛屿? + pub fn closed_island(mut grid: Vec>) -> i32 { + for i in 0..grid[0].len() { + Self::bfs((0, i), &mut grid); + } + + for i in 0..grid[0].len() { + Self::bfs((grid.len() - 1, i), &mut grid); + } + + for i in 0..grid.len() { + Self::bfs((i, 0), &mut grid); + } + + for i in 0..grid.len() { + Self::bfs((i, grid[0].len() - 1), &mut grid); + } + + let mut r = 0; + + for i in 0..grid.len() { + for j in 0..grid[0].len() { + if grid[i][j] == 0 { + r += 1; + Self::bfs((i, j), &mut grid); + } + } + } + + r + } + + fn bfs(start: (usize, usize), grid: &mut Vec>) { + if start.0 > grid.len() - 1 { + return; + } + + if start.1 > grid[0].len() - 1 { + return; + } + + if grid[start.0][start.1] == 1 { + return; + } else { + grid[start.0][start.1] = 1; + } + + if start.0 > 0 { + Self::bfs((start.0 - 1, start.1), grid); + } + + if start.1 > 0 { + Self::bfs((start.0, start.1 - 1), grid); + } + + Self::bfs((start.0 + 1, start.1), grid); + Self::bfs((start.0, start.1 + 1), grid); + } +} From b9deb0bc9218f10e8a0f9ad3cbaafd994044a5ec Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 18 Jun 2023 20:18:39 +0800 Subject: [PATCH 0848/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 98070c07..62ed6eda 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 467 | 194 | 248 | 25 | +| 468 | 194 | 249 | 25 | ### 题目 @@ -319,6 +319,7 @@ |1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | |1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | |1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | +|1380 | 统计封闭岛屿的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-closed-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-closed-islands/) | Medium | |1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | |1426 | 和为零的 N 个不同整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | From 6661acce53b242ec203ae241769f9ca9f1cba829 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 20 Jun 2023 23:25:23 +0800 Subject: [PATCH 0849/1556] src/bin/apply-operations-to-an-array.rs --- src/bin/apply-operations-to-an-array.rs | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/bin/apply-operations-to-an-array.rs diff --git a/src/bin/apply-operations-to-an-array.rs b/src/bin/apply-operations-to-an-array.rs new file mode 100644 index 00000000..20294f60 --- /dev/null +++ b/src/bin/apply-operations-to-an-array.rs @@ -0,0 +1,33 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn apply_operations(mut nums: Vec) -> Vec { + for i in 0..nums.len() - 1 { + if nums[i] == nums[i + 1] { + nums[i] *= 2; + nums[i + 1] = 0; + } + } + + // i: 第一个0的下标 + let mut i = 0; + + for j in 0..nums.len() { + if nums[j] != 0 { + while i < j { + if nums[i] == 0 { + nums.swap(i, j); + break; + } + i += 1; + } + } + } + + nums + } +} From 3718cf6125aaffb510d799b26a4b6b1135e5ab47 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 20 Jun 2023 23:25:27 +0800 Subject: [PATCH 0850/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 62ed6eda..b582f4d2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 468 | 194 | 249 | 25 | +| 469 | 195 | 249 | 25 | ### 题目 @@ -353,6 +353,7 @@ |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | +|2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | |2575 | 分割圆的最少切割次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cuts-to-divide-a-circle.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cuts-to-divide-a-circle/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | From b89c869239107766859c1692353b1491ed87331d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 24 Jun 2023 14:41:00 +0800 Subject: [PATCH 0851/1556] src/bin/maximum-value-of-a-string-in-an-array.rs --- src/bin/maximum-value-of-a-string-in-an-array.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/bin/maximum-value-of-a-string-in-an-array.rs diff --git a/src/bin/maximum-value-of-a-string-in-an-array.rs b/src/bin/maximum-value-of-a-string-in-an-array.rs new file mode 100644 index 00000000..1aebb8eb --- /dev/null +++ b/src/bin/maximum-value-of-a-string-in-an-array.rs @@ -0,0 +1,14 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_value(strs: Vec) -> i32 { + strs.iter() + .map(|s| s.parse().unwrap_or(s.len() as i32)) + .max() + .unwrap() + } +} From a4b4811114b712e08b68a29013492cd34c783cd1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 24 Jun 2023 14:41:01 +0800 Subject: [PATCH 0852/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b582f4d2..0222751d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 469 | 195 | 249 | 25 | +| 470 | 196 | 249 | 25 | ### 题目 @@ -356,6 +356,7 @@ |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | |2575 | 分割圆的最少切割次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cuts-to-divide-a-circle.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cuts-to-divide-a-circle/) | Easy | +|2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | From 183f84eaa43e30a1d59f0003ff57c2f4e17bfccb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jun 2023 21:23:18 +0800 Subject: [PATCH 0853/1556] src/bin/circle-and-rectangle-overlapping.rs --- src/bin/circle-and-rectangle-overlapping.rs | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/circle-and-rectangle-overlapping.rs diff --git a/src/bin/circle-and-rectangle-overlapping.rs b/src/bin/circle-and-rectangle-overlapping.rs new file mode 100644 index 00000000..2d2d317a --- /dev/null +++ b/src/bin/circle-and-rectangle-overlapping.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 找到矩形边上的点到圆心的距离是否小于等于圆的半径 + pub fn check_overlap( + radius: i32, + x_center: i32, + y_center: i32, + x1: i32, + y1: i32, + x2: i32, + y2: i32, + ) -> bool { + let mut d = 0; + if x_center < x1 || x_center > x2 { + d += (x1 - x_center).pow(2).min((x2 - x_center).pow(2)); + } + + if y_center < y1 || y_center > y2 { + d += (y1 - y_center).pow(2).min((y2 - y_center).pow(2)); + } + + d <= radius.pow(2) + } +} From e2958f169a9b9d741a6a48ad46139f778d7f529a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Jun 2023 21:23:19 +0800 Subject: [PATCH 0854/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0222751d..e3567673 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 470 | 196 | 249 | 25 | +| 471 | 196 | 250 | 25 | ### 题目 @@ -329,6 +329,7 @@ |1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | |1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | |1491 | 二进制字符串前缀一致的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-times-binary-string-is-prefix-aligned.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-times-binary-string-is-prefix-aligned/) | Medium | +|1501 | 圆和矩形是否有重叠 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circle-and-rectangle-overlapping.rs) | [leetcode](https://leetcode-cn.com/problems/circle-and-rectangle-overlapping/) | Medium | |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | |1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | |1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | From 00fea11496a9eb1929a57534f381d068c5fea789 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 26 Jun 2023 23:26:01 +0800 Subject: [PATCH 0855/1556] src/bin/find-the-pivot-integer.rs --- src/bin/find-the-pivot-integer.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/find-the-pivot-integer.rs diff --git a/src/bin/find-the-pivot-integer.rs b/src/bin/find-the-pivot-integer.rs new file mode 100644 index 00000000..519b4f36 --- /dev/null +++ b/src/bin/find-the-pivot-integer.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 设值为x + /// (1 + x) * (x - 1 + 1) / 2= (x + n) * (n - x + 1) / 2 + /// (1 + x) * x = (n + x) * (n - x + 1) + /// x**2 + x = n ** 2 - nx + n + nx - x**2 + x + /// 2 * x ** 2 = n ** 2 + n + pub fn pivot_integer(n: i32) -> i32 { + let x = n * n + n; + if x % 2 == 1 { + return -1; + } + + for i in 1..=n { + if i * i == x / 2 { + return i; + } else if i * i > x / 2 { + return -1; + } + } + + -1 + } +} From 4d536118f9bac0f8274e554b929bfca0ddd16aab Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 26 Jun 2023 23:26:01 +0800 Subject: [PATCH 0856/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e3567673..fe169a45 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 471 | 196 | 250 | 25 | +| 472 | 197 | 250 | 25 | ### 题目 @@ -356,6 +356,7 @@ |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | +|2571 | 找出中枢整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-pivot-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-pivot-integer/) | Easy | |2575 | 分割圆的最少切割次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cuts-to-divide-a-circle.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cuts-to-divide-a-circle/) | Easy | |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | From 81182256f4cb9d3051e307f64e4a2502be7d0c5d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 27 Jun 2023 22:11:25 +0800 Subject: [PATCH 0857/1556] src/bin/count-vowel-strings-in-ranges.rs --- src/bin/count-vowel-strings-in-ranges.rs | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/count-vowel-strings-in-ranges.rs diff --git a/src/bin/count-vowel-strings-in-ranges.rs b/src/bin/count-vowel-strings-in-ranges.rs new file mode 100644 index 00000000..882ae79f --- /dev/null +++ b/src/bin/count-vowel-strings-in-ranges.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn vowel_strings(words: Vec, queries: Vec>) -> Vec { + let mut s = vec![0; words.len() + 1]; + + for (i, v) in words.iter().enumerate() { + if matches!(v.as_bytes()[0], b'a' | b'e' | b'i' | b'o' | b'u') + && matches!(v.as_bytes()[v.len() - 1], b'a' | b'e' | b'i' | b'o' | b'u') + { + s[i + 1] = s[i] + 1; + } else { + s[i + 1] = s[i]; + } + } + + let mut result = Vec::with_capacity(queries.len()); + for i in queries.into_iter() { + result.push(s[i[1] as usize + 1] - s[i[0] as usize]); + } + + result + } +} From ff9141accbe55630a0981d9bc5acaa768ad6942d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 27 Jun 2023 22:11:26 +0800 Subject: [PATCH 0858/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fe169a45..dbe4e9c1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 472 | 197 | 250 | 25 | +| 473 | 197 | 251 | 25 | ### 题目 @@ -359,6 +359,7 @@ |2571 | 找出中枢整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-pivot-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-pivot-integer/) | Easy | |2575 | 分割圆的最少切割次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cuts-to-divide-a-circle.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cuts-to-divide-a-circle/) | Easy | |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | +|2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | From 436bd75a8cd1172b86bc71418c049508cb475e3e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 28 Jun 2023 23:04:06 +0800 Subject: [PATCH 0859/1556] src/bin/powerful-integers.rs --- src/bin/powerful-integers.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/powerful-integers.rs diff --git a/src/bin/powerful-integers.rs b/src/bin/powerful-integers.rs new file mode 100644 index 00000000..85c3fc78 --- /dev/null +++ b/src/bin/powerful-integers.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn powerful_integers(x: i32, y: i32, bound: i32) -> Vec { + let mut result = std::collections::HashSet::new(); + let mut i = 0; + + while x.pow(i) <= bound { + let mut j = 0; + while x.pow(i) + y.pow(j) <= bound { + result.insert(x.pow(i) + y.pow(j)); + if y == 1 { + break; + } + j += 1; + } + i += 1; + + if x == 1 { + break; + } + } + + result.into_iter().collect() + } +} From ed32cfa78d1b10b2b5a415ce399882ee4a656b32 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 28 Jun 2023 23:04:07 +0800 Subject: [PATCH 0860/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dbe4e9c1..e227e64b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 473 | 197 | 251 | 25 | +| 474 | 197 | 252 | 25 | ### 题目 @@ -299,6 +299,7 @@ |1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | Medium | |1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | Easy | |1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | +|1010 | 强整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powerful-integers.rs) | [leetcode](https://leetcode-cn.com/problems/powerful-integers/) | Medium | |1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | |1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | From dbd08d64b31b9f914202737d3d8617bf5246e4fb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 29 Jun 2023 22:52:16 +0800 Subject: [PATCH 0861/1556] src/bin/counting-words-with-a-given-prefix.rs --- src/bin/counting-words-with-a-given-prefix.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/bin/counting-words-with-a-given-prefix.rs diff --git a/src/bin/counting-words-with-a-given-prefix.rs b/src/bin/counting-words-with-a-given-prefix.rs new file mode 100644 index 00000000..92ee365d --- /dev/null +++ b/src/bin/counting-words-with-a-given-prefix.rs @@ -0,0 +1,11 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn prefix_count(words: Vec, pref: String) -> i32 { + words.into_iter().filter(|x| x.starts_with(&pref)).count() as i32 + } +} From 316bf4adad3cf8c95024807ee079f13ee50e3863 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 29 Jun 2023 22:52:24 +0800 Subject: [PATCH 0862/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e227e64b..8e0e32f9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 474 | 197 | 252 | 25 | +| 475 | 198 | 252 | 25 | ### 题目 @@ -353,6 +353,7 @@ |1952 | 最少侧跳次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sideway-jumps.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sideway-jumps/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | +|2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | From b9976c764e91f6582e5ed611a254cdaab2b7a5d8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 3 Jul 2023 20:53:03 +0800 Subject: [PATCH 0863/1556] src/bin/circular-sentence.rs --- src/bin/circular-sentence.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/circular-sentence.rs diff --git a/src/bin/circular-sentence.rs b/src/bin/circular-sentence.rs new file mode 100644 index 00000000..8d7d21b9 --- /dev/null +++ b/src/bin/circular-sentence.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn is_circular_sentence(sentence: String) -> bool { + let bytes = sentence.as_bytes(); + if bytes[0] != bytes[bytes.len() - 1] { + return false; + } + + let (mut current, mut flag) = (bytes[0], false); + for i in sentence.bytes() { + if i == b' ' { + flag = true; + } else { + if flag { + if i != current { + return false; + } + flag = false; + } + + current = i; + } + } + + true + } +} From fbdffa99052dadb42f1c9bbcfe881e368293be54 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 3 Jul 2023 20:53:04 +0800 Subject: [PATCH 0864/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e0e32f9..cfc6af02 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 475 | 198 | 252 | 25 | +| 476 | 199 | 252 | 25 | ### 题目 @@ -360,6 +360,7 @@ |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | |2571 | 找出中枢整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-pivot-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-pivot-integer/) | Easy | |2575 | 分割圆的最少切割次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cuts-to-divide-a-circle.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cuts-to-divide-a-circle/) | Easy | +|2580 | 回环句 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circular-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/circular-sentence/) | Easy | |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | From d037f872ec509b6178cbcf5f223f99a7895587de Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 4 Jul 2023 20:22:25 +0800 Subject: [PATCH 0865/1556] src/bin/sum-in-a-matrix.rs --- src/bin/sum-in-a-matrix.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/bin/sum-in-a-matrix.rs diff --git a/src/bin/sum-in-a-matrix.rs b/src/bin/sum-in-a-matrix.rs new file mode 100644 index 00000000..fb287dfd --- /dev/null +++ b/src/bin/sum-in-a-matrix.rs @@ -0,0 +1,26 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn matrix_sum(mut nums: Vec>) -> i32 { + for i in nums.iter_mut() { + i.sort_by(|a, b| a.cmp(b)); + } + + let mut result = 0; + + for i in 0..nums[0].len() { + let mut max = 0; + for j in 0..nums.len() { + max = max.max(nums[j][i]); + } + + result += max; + } + + result + } +} From 422dc961d1c46dbf7e3076f9c7d9906d2d975d9c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 4 Jul 2023 20:22:25 +0800 Subject: [PATCH 0866/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cfc6af02..b11d5c78 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 476 | 199 | 252 | 25 | +| 477 | 199 | 253 | 25 | ### 题目 @@ -363,6 +363,7 @@ |2580 | 回环句 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circular-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/circular-sentence/) | Easy | |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | +|2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | From ce2dfb9315799692aad1918987c50a1491aa16fc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 5 Jul 2023 21:01:51 +0800 Subject: [PATCH 0867/1556] src/bin/k-items-with-the-maximum-sum.rs --- src/bin/k-items-with-the-maximum-sum.rs | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/k-items-with-the-maximum-sum.rs diff --git a/src/bin/k-items-with-the-maximum-sum.rs b/src/bin/k-items-with-the-maximum-sum.rs new file mode 100644 index 00000000..ec68afb5 --- /dev/null +++ b/src/bin/k-items-with-the-maximum-sum.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn k_items_with_maximum_sum( + num_ones: i32, + num_zeros: i32, + num_neg_ones: i32, + k: i32, + ) -> i32 { + let mut k = k; + let mut r = 0; + + if k > num_ones { + k -= num_ones; + r += num_ones; + } else { + return k; + } + + if k > num_zeros { + k -= num_zeros; + } else { + return r; + } + + r - k + } +} From 147c8692c44db0dea773a8d37ac63673e202b2b5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 5 Jul 2023 21:01:51 +0800 Subject: [PATCH 0868/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b11d5c78..a9ec168a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 477 | 199 | 253 | 25 | +| 478 | 200 | 253 | 25 | ### 题目 @@ -363,6 +363,7 @@ |2580 | 回环句 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circular-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/circular-sentence/) | Easy | |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | +|2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | From 08f840fa9ea6ff95ce743f088ed2676c754d04d6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 6 Jul 2023 23:21:54 +0800 Subject: [PATCH 0869/1556] src/bin/maximum-split-of-positive-even-integers.rs --- ...maximum-split-of-positive-even-integers.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/bin/maximum-split-of-positive-even-integers.rs diff --git a/src/bin/maximum-split-of-positive-even-integers.rs b/src/bin/maximum-split-of-positive-even-integers.rs new file mode 100644 index 00000000..5ca1bf80 --- /dev/null +++ b/src/bin/maximum-split-of-positive-even-integers.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_even_split(mut final_sum: i64) -> Vec { + let mut result = vec![]; + if final_sum % 2 == 1 { + return result; + } + + result.push(2); + + loop { + final_sum -= result[result.len() - 1]; + if final_sum <= result[result.len() - 1] { + let last = result[result.len() - 1]; + let len = result.len() - 1; + result[len] = last + final_sum; + break; + } else { + result.push(result[result.len() - 1] + 2); + } + } + + result + } +} From 1ff548cb90f6bafcf0c03cb47833375783516954 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 6 Jul 2023 23:21:54 +0800 Subject: [PATCH 0870/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a9ec168a..59f18e20 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 478 | 200 | 253 | 25 | +| 479 | 200 | 254 | 25 | ### 题目 @@ -353,6 +353,7 @@ |1952 | 最少侧跳次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sideway-jumps.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sideway-jumps/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | +|2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | From 289b8c602f0f4e8c7ee7421ec960cca395be30c1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 8 Jul 2023 20:30:29 +0800 Subject: [PATCH 0871/1556] src/bin/longest-word-lcci.rs --- src/bin/longest-word-lcci.rs | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/bin/longest-word-lcci.rs diff --git a/src/bin/longest-word-lcci.rs b/src/bin/longest-word-lcci.rs new file mode 100644 index 00000000..e85f2ad6 --- /dev/null +++ b/src/bin/longest-word-lcci.rs @@ -0,0 +1,46 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn longest_word(mut words: Vec) -> String { + words.sort_by(|x, y| { + if x.len() == y.len() { + x.cmp(y) + } else { + y.len().cmp(&x.len()) + } + }); + + let mut set = words + .iter() + .map(|x| x.as_bytes()) + .collect::>(); + + for i in words.iter() { + set.remove(i.as_bytes()); + if Self::check(&set, i.as_bytes()) { + return i.into(); + } + set.insert(i.as_bytes()); + } + + "".into() + } + + fn check(set: &std::collections::HashSet<&[u8]>, s: &[u8]) -> bool { + if s.is_empty() || set.contains(s) { + return true; + } + + for i in 0..s.len() { + if set.contains(&s[..i]) && Self::check(set, &s[i..]) { + return true; + } + } + + false + } +} From e3054bc21029ee982767073613db39cf0cc20eca Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 8 Jul 2023 20:30:30 +0800 Subject: [PATCH 0872/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 59f18e20..b1ceb5a4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 479 | 200 | 254 | 25 | +| 480 | 200 | 255 | 25 | ### 题目 @@ -443,6 +443,7 @@ |100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | |100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | |100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | +|1000022 | 最长单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-word-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/longest-word-lcci/) | Medium | |1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | |1000228 | 整数除法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xoh6Oh.rs) | [leetcode](https://leetcode-cn.com/problems/xoh6Oh/) | Easy | From 0c6119398e361a04486cb0cbc789a20c34aaa072 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 9 Jul 2023 20:32:09 +0800 Subject: [PATCH 0873/1556] src/bin/incremental-memory-leak.rs --- src/bin/incremental-memory-leak.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/incremental-memory-leak.rs diff --git a/src/bin/incremental-memory-leak.rs b/src/bin/incremental-memory-leak.rs new file mode 100644 index 00000000..6e598472 --- /dev/null +++ b/src/bin/incremental-memory-leak.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn mem_leak(mut memory1: i32, mut memory2: i32) -> Vec { + let mut t = 1; + + loop { + if t > memory1 && t > memory2 { + return vec![t, memory1, memory2]; + } + + if memory2 > memory1 { + memory2 -= t; + } else { + memory1 -= t; + } + + t += 1; + } + } +} From 1e7e2475d1b8cf27a757df59d3cf5d62ce1c7668 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 9 Jul 2023 20:32:10 +0800 Subject: [PATCH 0874/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b1ceb5a4..90fb5705 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 480 | 200 | 255 | 25 | +| 481 | 200 | 256 | 25 | ### 题目 @@ -351,6 +351,7 @@ |1894 | 交替合并字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-strings-alternately.rs) | [leetcode](https://leetcode-cn.com/problems/merge-strings-alternately/) | Easy | |1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | |1952 | 最少侧跳次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sideway-jumps.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sideway-jumps/) | Medium | +|1971 | 增长的内存泄露 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/incremental-memory-leak.rs) | [leetcode](https://leetcode-cn.com/problems/incremental-memory-leak/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | From bc48f73e50a362725bb1b8566aefec3cfdfad830 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 10 Jul 2023 21:40:28 +0800 Subject: [PATCH 0875/1556] src/bin/smallest-k-lcci.rs --- src/bin/smallest-k-lcci.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/bin/smallest-k-lcci.rs diff --git a/src/bin/smallest-k-lcci.rs b/src/bin/smallest-k-lcci.rs new file mode 100644 index 00000000..922421bc --- /dev/null +++ b/src/bin/smallest-k-lcci.rs @@ -0,0 +1,15 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn smallest_k(mut arr: Vec, k: i32) -> Vec { + arr.sort(); + + arr[..k as usize].into() + } +} From e154781df7054fa84cb7d01ebe81f22ba5aff286 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 10 Jul 2023 21:40:29 +0800 Subject: [PATCH 0876/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 90fb5705..d285205b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 481 | 200 | 256 | 25 | +| 482 | 200 | 257 | 25 | ### 题目 @@ -444,6 +444,7 @@ |100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | |100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | |100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | +|1000021 | 最小K个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-k-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-k-lcci/) | Medium | |1000022 | 最长单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-word-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/longest-word-lcci/) | Medium | |1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | From 51b46135dc7563a4375c05deff79b8ccea03e0aa Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 12 Jul 2023 21:26:15 +0800 Subject: [PATCH 0877/1556] src/bin/maximum-alternating-subsequence-sum.rs --- .../maximum-alternating-subsequence-sum.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/maximum-alternating-subsequence-sum.rs diff --git a/src/bin/maximum-alternating-subsequence-sum.rs b/src/bin/maximum-alternating-subsequence-sum.rs new file mode 100644 index 00000000..8157b86a --- /dev/null +++ b/src/bin/maximum-alternating-subsequence-sum.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// dp[i]表示前i个元素子序列的最大值 + /// 则 dp[i]的值可能为奇数或者偶数 + pub fn max_alternating_sum(nums: Vec) -> i64 { + // odd奇数,even 偶数 + let (mut odd, mut even, mut result) = (0, nums[0] as i64, nums[0] as i64); + + for &i in nums[1..].into_iter() { + even = even.max(odd - i as i64); + odd = odd.max(even + i as i64); + result = odd.max(even); + } + result + } +} From 73fbdad051769ed422c17e94d91ef9dd98061e5c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 12 Jul 2023 21:26:16 +0800 Subject: [PATCH 0878/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d285205b..d523ffb6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 482 | 200 | 257 | 25 | +| 483 | 200 | 258 | 25 | ### 题目 @@ -353,6 +353,7 @@ |1952 | 最少侧跳次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sideway-jumps.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sideway-jumps/) | Medium | |1971 | 增长的内存泄露 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/incremental-memory-leak.rs) | [leetcode](https://leetcode-cn.com/problems/incremental-memory-leak/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | +|2022 | 最大子序列交替和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-alternating-subsequence-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-alternating-subsequence-sum/) | Medium | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | From 36d2ca20b3dfff4a340ebd64e9afc92ee780d0dd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 12 Jul 2023 21:34:15 +0800 Subject: [PATCH 0879/1556] src/bin/alternating-digit-sum.rs --- src/bin/alternating-digit-sum.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/alternating-digit-sum.rs diff --git a/src/bin/alternating-digit-sum.rs b/src/bin/alternating-digit-sum.rs new file mode 100644 index 00000000..5d89fcd3 --- /dev/null +++ b/src/bin/alternating-digit-sum.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn alternate_digit_sum(mut n: i32) -> i32 { + let mut r = 0; + let mut flag = true; + while n > 0 { + if flag { + r += n % 10; + } else { + r -= n % 10; + } + + n /= 10; + flag = !flag; + } + + if !flag { + r + } else { + -r + } + } +} From 6369e34ab8524e55a9a4f29fde618b8258d15cd0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 12 Jul 2023 21:34:15 +0800 Subject: [PATCH 0880/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d523ffb6..714834ab 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 483 | 200 | 258 | 25 | +| 484 | 201 | 258 | 25 | ### 题目 @@ -365,6 +365,7 @@ |2575 | 分割圆的最少切割次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cuts-to-divide-a-circle.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cuts-to-divide-a-circle/) | Easy | |2580 | 回环句 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circular-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/circular-sentence/) | Easy | |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | +|2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | From b1c895a77a967fbe87a25e60356653d998159be9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 13 Jul 2023 22:53:09 +0800 Subject: [PATCH 0881/1556] src/bin/minimum-falling-path-sum.rs --- src/bin/minimum-falling-path-sum.rs | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/bin/minimum-falling-path-sum.rs diff --git a/src/bin/minimum-falling-path-sum.rs b/src/bin/minimum-falling-path-sum.rs new file mode 100644 index 00000000..0251b0f0 --- /dev/null +++ b/src/bin/minimum-falling-path-sum.rs @@ -0,0 +1,34 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_falling_path_sum(mut matrix: Vec>) -> i32 { + let n = matrix.len(); + + for i in (0..n - 1).rev() { + for j in 0..n { + if j == 0 { + matrix[i][j] = matrix[i][j] + matrix[i + 1][j].min(matrix[i + 1][j + 1]); + } else if j == n - 1 { + matrix[i][j] = matrix[i][j] + matrix[i + 1][j - 1].min(matrix[i + 1][j]); + } else { + matrix[i][j] = matrix[i][j] + + matrix[i + 1][j - 1] + .min(matrix[i + 1][j]) + .min(matrix[i + 1][j + 1]); + } + } + } + + let mut r = matrix[0][0]; + + for i in 1..n { + r = r.min(matrix[0][i]); + } + + r + } +} From c1615948f677d01b63b917b028b0cd003affe941 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 13 Jul 2023 22:53:09 +0800 Subject: [PATCH 0882/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 714834ab..8bddbd97 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 484 | 201 | 258 | 25 | +| 485 | 201 | 259 | 25 | ### 题目 @@ -291,6 +291,7 @@ |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | |947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | +|967 | 下降路径最小和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-falling-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-falling-path-sum/) | Medium | |977 | 不同的子序列 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distinct-subsequences-ii.rs) | [leetcode](https://leetcode-cn.com/problems/distinct-subsequences-ii/) | Hard | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | |981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | From 2a454900d603afcc3929a3cfc90270d991b7c856 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 16 Jul 2023 23:59:40 +0800 Subject: [PATCH 0883/1556] src/bin/reverse-only-letters.rs --- src/bin/reverse-only-letters.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/bin/reverse-only-letters.rs diff --git a/src/bin/reverse-only-letters.rs b/src/bin/reverse-only-letters.rs new file mode 100644 index 00000000..5d1b8d3e --- /dev/null +++ b/src/bin/reverse-only-letters.rs @@ -0,0 +1,17 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn reverse_only_letters(mut s: String) -> String { + let mut bytes = unsafe { s.as_bytes_mut() }; + let (mut start, mut end) = (0, s.len() - 1); + + while start < end { + if !matches(bytes[start], b'a'..=b'z', b'A'..=b'Z') {} + } + s + } +} From 024ec588e4a88f82ad28c8971c03745c59dd306c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 16 Jul 2023 23:59:41 +0800 Subject: [PATCH 0884/1556] README.md --- README.md | 3 ++- src/bin/reverse-only-letters.rs | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8bddbd97..756cecce 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 485 | 201 | 259 | 25 | +| 486 | 202 | 259 | 25 | ### 题目 @@ -291,6 +291,7 @@ |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | |947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | +|953 | 仅仅反转字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-only-letters.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-only-letters/) | Easy | |967 | 下降路径最小和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-falling-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-falling-path-sum/) | Medium | |977 | 不同的子序列 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distinct-subsequences-ii.rs) | [leetcode](https://leetcode-cn.com/problems/distinct-subsequences-ii/) | Hard | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | diff --git a/src/bin/reverse-only-letters.rs b/src/bin/reverse-only-letters.rs index 5d1b8d3e..5b1580f0 100644 --- a/src/bin/reverse-only-letters.rs +++ b/src/bin/reverse-only-letters.rs @@ -6,11 +6,21 @@ struct Solution; impl Solution { pub fn reverse_only_letters(mut s: String) -> String { - let mut bytes = unsafe { s.as_bytes_mut() }; - let (mut start, mut end) = (0, s.len() - 1); + unsafe { + let (mut start, mut end) = (0, s.len() - 1); + let mut bytes = s.as_bytes_mut(); - while start < end { - if !matches(bytes[start], b'a'..=b'z', b'A'..=b'Z') {} + while start < end { + if !matches!(bytes[start], b'a'..=b'z'|b'A'..=b'Z') { + start += 1; + } else if !matches!(bytes[end], b'a'..=b'z'|b'A'..=b'Z') { + end -= 1; + } else { + bytes.swap(start, end); + start += 1; + end -= 1; + } + } } s } From f2f1e03f91acf905e95ea6acdf4f6a4628440f03 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 17 Jul 2023 20:56:46 +0800 Subject: [PATCH 0885/1556] src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs --- ...ith-the-highest-score-of-a-binary-array.rs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs diff --git a/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs b/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs new file mode 100644 index 00000000..1ecb3b96 --- /dev/null +++ b/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs @@ -0,0 +1,39 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_score_indices(nums: Vec) -> Vec { + let total_1: i32 = nums.iter().map(|x| *x).sum(); + + let mut result = vec![0]; + let (mut left_0, mut right_1) = (0, total_1); + let mut max = total_1; + + for (i, v) in nums.into_iter().enumerate() { + if v == 1 { + right_1 -= 1; + } else if v == 0 { + left_0 += 1; + } + + match (left_0 + right_1).cmp(&max) { + std::cmp::Ordering::Greater => { + max = left_0 + right_1; + result = vec![i as i32 + 1]; + } + + std::cmp::Ordering::Equal => { + result.push(i as i32 + 1); + } + _ => {} + } + } + + result + } +} From d4cb2296a4b51b8a2e33bf3806d1a1bf3051706f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 17 Jul 2023 20:56:46 +0800 Subject: [PATCH 0886/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 756cecce..298f3e37 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 486 | 202 | 259 | 25 | +| 487 | 202 | 260 | 25 | ### 题目 @@ -357,6 +357,7 @@ |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2022 | 最大子序列交替和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-alternating-subsequence-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-alternating-subsequence-sum/) | Medium | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | +|2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | From 17a5d311a507fcf6efaac4b86fa291d45f4e8544 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 18 Jul 2023 20:34:24 +0800 Subject: [PATCH 0887/1556] src/bin/distribute-coins-in-binary-tree.rs --- src/bin/distribute-coins-in-binary-tree.rs | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/distribute-coins-in-binary-tree.rs diff --git a/src/bin/distribute-coins-in-binary-tree.rs b/src/bin/distribute-coins-in-binary-tree.rs new file mode 100644 index 00000000..3c77ddef --- /dev/null +++ b/src/bin/distribute-coins-in-binary-tree.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::cell::RefCell; +use std::rc::Rc; + +impl Solution { + pub fn distribute_coins(root: Option>>) -> i32 { + let mut r = 0; + + r + } +} From 341499e05ce61cc849b48c9db6be0a178a18d787 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 18 Jul 2023 20:34:25 +0800 Subject: [PATCH 0888/1556] src/bin/find-target-indices-after-sorting-array.rs --- ...find-target-indices-after-sorting-array.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/find-target-indices-after-sorting-array.rs diff --git a/src/bin/find-target-indices-after-sorting-array.rs b/src/bin/find-target-indices-after-sorting-array.rs new file mode 100644 index 00000000..c7963102 --- /dev/null +++ b/src/bin/find-target-indices-after-sorting-array.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn target_indices(mut nums: Vec, target: i32) -> Vec { + nums.sort(); + + let mut left = -1; + let mut right = 0; + + for i in (0..nums.len()) { + if nums[i] == target { + if left == -1 { + left = i as i32; + } + + right = i as i32; + } + } + if left != -1 { + (left..=right).collect() + } else { + Default::default() + } + } +} From dbc093feede3a110074312a6b7fb495c5868a056 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 18 Jul 2023 20:34:25 +0800 Subject: [PATCH 0889/1556] README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 298f3e37..5e9155c7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 487 | 202 | 260 | 25 | +| 489 | 203 | 261 | 25 | ### 题目 @@ -302,6 +302,7 @@ |1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | Easy | |1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | |1010 | 强整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powerful-integers.rs) | [leetcode](https://leetcode-cn.com/problems/powerful-integers/) | Medium | +|1021 | 在二叉树中分配硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-coins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-coins-in-binary-tree/) | Medium | |1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | |1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | @@ -357,6 +358,7 @@ |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2022 | 最大子序列交替和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-alternating-subsequence-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-alternating-subsequence-sum/) | Medium | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | +|2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | |2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | From 0d817dc56b323250e132cf3946ca05dc337b33f1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 19 Jul 2023 20:56:55 +0800 Subject: [PATCH 0890/1556] src/bin/walking-robot-simulation.rs --- src/bin/walking-robot-simulation.rs | 85 +++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/bin/walking-robot-simulation.rs diff --git a/src/bin/walking-robot-simulation.rs b/src/bin/walking-robot-simulation.rs new file mode 100644 index 00000000..d583dbc8 --- /dev/null +++ b/src/bin/walking-robot-simulation.rs @@ -0,0 +1,85 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn robot_sim(commands: Vec, obstacles: Vec>) -> i32 { + enum Direction { + East, + South, + West, + North, + } + + let hashset: std::collections::HashSet<_> = + obstacles.into_iter().map(|x| (x[0], x[1])).collect(); + + let (mut p1, mut p2) = (0, 0); + let mut result = 0; + + let mut direction = Direction::North; + + for i in commands { + match i { + -2 => match direction { + Direction::East => direction = Direction::North, + Direction::South => direction = Direction::East, + Direction::West => direction = Direction::South, + Direction::North => direction = Direction::West, + }, + -1 => match direction { + Direction::East => direction = Direction::South, + Direction::South => direction = Direction::West, + Direction::West => direction = Direction::North, + Direction::North => direction = Direction::East, + }, + step => match direction { + Direction::East => { + for i in 0..step { + if hashset.contains(&(p1 + 1, p2)) { + break; + } + p1 += 1; + + result = result.max(p1 * p1 + p2 * p2); + } + } + Direction::South => { + for i in 0..step { + if hashset.contains(&(p1, p2 - 1)) { + break; + } + p2 -= 1; + + result = result.max(p1 * p1 + p2 * p2); + } + } + Direction::West => { + for i in 0..step { + if hashset.contains(&(p1 - 1, p2)) { + break; + } + p1 -= 1; + + result = result.max(p1 * p1 + p2 * p2); + } + } + Direction::North => { + for i in 0..step { + if hashset.contains(&(p1, p2 + 1)) { + break; + } + p2 += 1; + + result = result.max(p1 * p1 + p2 * p2); + } + } + }, + } + } + + result + } +} From 1297015629394f1975148af9b0be57144575dc11 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 19 Jul 2023 20:57:01 +0800 Subject: [PATCH 0891/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e9155c7..5b0a566e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 489 | 203 | 261 | 25 | +| 490 | 203 | 262 | 25 | ### 题目 @@ -284,6 +284,7 @@ |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | |905 | 最长的斐波那契子序列的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-longest-fibonacci-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence/) | Medium | +|906 | 模拟行走机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/walking-robot-simulation.rs) | [leetcode](https://leetcode-cn.com/problems/walking-robot-simulation/) | Medium | |917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | |921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | |924 | 公平的糖果交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | From 874862b16f64f4efa7b2b26341fc8e728705d550 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 20 Jul 2023 22:19:17 +0800 Subject: [PATCH 0892/1556] src/bin/maximum-sum-circular-subarray.rs --- src/bin/maximum-sum-circular-subarray.rs | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/bin/maximum-sum-circular-subarray.rs diff --git a/src/bin/maximum-sum-circular-subarray.rs b/src/bin/maximum-sum-circular-subarray.rs new file mode 100644 index 00000000..3af105cd --- /dev/null +++ b/src/bin/maximum-sum-circular-subarray.rs @@ -0,0 +1,48 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +impl Solution { + /// 取反,求最小和的连续子数组,则其余是最大和 + /// 两种情况:1.最大和子数组在数组中间 + /// 2.最大和子数组在数组两边,在数组两边就是最小和数组在中间 + pub fn max_subarray_sum_circular(mut nums: Vec) -> i32 { + let mut result = nums[0]; + let mut last = nums[0]; + + let mut all_positive = last < 0; // 是否全是负数, 如果全是负数的话,就不能探究第二种情况 + // 第一种情况 + for i in 1..nums.len() { + if last > 0 { + last += nums[i]; + } else { + last = nums[i]; + } + all_positive = all_positive && nums[i] < 0; + result = result.max(last); + } + + if all_positive { + return result; + } + + // 第二种情况 + let mut sum: i32 = nums.iter().map(|x| *x).sum(); + let mut last = nums[0]; + for i in 1..nums.len() { + if last > 0 { + last = nums[i]; + } else { + last += nums[i]; + } + + result = result.max(sum - last); + } + + result + } +} From 96f063eff1e8a93fcf2e8add03959d2610e7f167 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 20 Jul 2023 22:19:18 +0800 Subject: [PATCH 0893/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b0a566e..ef2cd7d4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 490 | 203 | 262 | 25 | +| 491 | 203 | 263 | 25 | ### 题目 @@ -293,6 +293,7 @@ |936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | |947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | |953 | 仅仅反转字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-only-letters.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-only-letters/) | Easy | +|954 | 环形子数组的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-circular-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-circular-subarray/) | Medium | |967 | 下降路径最小和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-falling-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-falling-path-sum/) | Medium | |977 | 不同的子序列 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distinct-subsequences-ii.rs) | [leetcode](https://leetcode-cn.com/problems/distinct-subsequences-ii/) | Hard | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | From 713a50c5bc71acc6dd255384888686f265cd84a0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 21 Jul 2023 21:15:41 +0800 Subject: [PATCH 0894/1556] src/bin/n-th-tribonacci-number.rs --- src/bin/n-th-tribonacci-number.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/n-th-tribonacci-number.rs diff --git a/src/bin/n-th-tribonacci-number.rs b/src/bin/n-th-tribonacci-number.rs new file mode 100644 index 00000000..4bb28f42 --- /dev/null +++ b/src/bin/n-th-tribonacci-number.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn tribonacci(n: i32) -> i32 { + let mut a = [0, 1, 1]; + if n <= 2 { + return a[n as usize]; + } + + for i in 3..=n { + let old = a[0]; + a[0] = a[1]; + a[1] = a[2]; + a[2] = old + a[0] + a[1]; + } + + a[2] + } +} From b8871fd7d522807d7ffc0f589ca9d8b763102c5f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 21 Jul 2023 21:15:41 +0800 Subject: [PATCH 0895/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ef2cd7d4..963e5eec 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 491 | 203 | 263 | 25 | +| 492 | 204 | 263 | 25 | ### 题目 @@ -313,6 +313,7 @@ |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | |1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | +|1236 | 第 N 个泰波那契数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-th-tribonacci-number.rs) | [leetcode](https://leetcode-cn.com/problems/n-th-tribonacci-number/) | Easy | |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | |1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | |1273 | 比较字符串最小字母出现频次 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-strings-by-frequency-of-the-smallest-character.rs) | [leetcode](https://leetcode-cn.com/problems/compare-strings-by-frequency-of-the-smallest-character/) | Medium | From 9e6111b5a68371c7830a46af6164bc858b7e422e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 22 Jul 2023 14:40:06 +0800 Subject: [PATCH 0896/1556] src/bin/lemonade-change.rs --- src/bin/lemonade-change.rs | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/bin/lemonade-change.rs diff --git a/src/bin/lemonade-change.rs b/src/bin/lemonade-change.rs new file mode 100644 index 00000000..9c9233ef --- /dev/null +++ b/src/bin/lemonade-change.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn lemonade_change(bills: Vec) -> bool { + let mut moneys = [0; 2]; // 第一个元素代表5的个数,第二个代表10的个数 + + for i in bills { + match i { + 5 => moneys[0] += 1, + 10 => { + if moneys[0] == 0 { + return false; + } + + moneys[0] -= 1; + moneys[1] += 1; + } + 20 => { + // 可以找1张5元+1张10元 + // 也可以找3张5元 + // 优先找10元 + if moneys[0] >= 1 && moneys[1] >= 1 { + moneys[0] -= 1; + moneys[1] -= 1; + } else if moneys[0] >= 3 { + moneys[0] -= 3; + } else { + return false; + } + } + _ => unreachable!(), + } + } + + true + } +} From 6e253e98907c412f9cae18312945b8f1ade3debb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 22 Jul 2023 14:40:06 +0800 Subject: [PATCH 0897/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 963e5eec..a86a45ce 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 492 | 204 | 263 | 25 | +| 493 | 205 | 263 | 25 | ### 题目 @@ -283,6 +283,7 @@ |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | +|890 | 柠檬水找零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lemonade-change.rs) | [leetcode](https://leetcode-cn.com/problems/lemonade-change/) | Easy | |905 | 最长的斐波那契子序列的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-longest-fibonacci-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence/) | Medium | |906 | 模拟行走机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/walking-robot-simulation.rs) | [leetcode](https://leetcode-cn.com/problems/walking-robot-simulation/) | Medium | |917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | From efc9c03e4e558dc1be1fff21c2e3a59801021997 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 23 Jul 2023 22:22:19 +0800 Subject: [PATCH 0898/1556] src/bin/filter-restaurants-by-vegan-friendly-price-and-distance.rs --- ...ts-by-vegan-friendly-price-and-distance.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/bin/filter-restaurants-by-vegan-friendly-price-and-distance.rs diff --git a/src/bin/filter-restaurants-by-vegan-friendly-price-and-distance.rs b/src/bin/filter-restaurants-by-vegan-friendly-price-and-distance.rs new file mode 100644 index 00000000..f066bd50 --- /dev/null +++ b/src/bin/filter-restaurants-by-vegan-friendly-price-and-distance.rs @@ -0,0 +1,34 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn filter_restaurants( + restaurants: Vec>, + vegan_friendly: i32, + max_price: i32, + max_distance: i32, + ) -> Vec { + use std::cmp::Ordering; + + let mut r = restaurants + .into_iter() + .filter(|x| vegan_friendly == 0 || x[2] == vegan_friendly) + .filter(|x| x[3] <= max_price) + .filter(|x| x[4] <= max_distance) + .map(|x| (x[0], x[1])) + .collect::>(); + + r.sort_by(|x, y| { + if x.1 == y.1 { + y.0.cmp(&x.0) + } else { + y.1.cmp(&x.1) + } + }); + + r.into_iter().map(|(x, _)| x).collect() + } +} From fda0a7e4711ceb9c1c1a59927800377430417713 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 23 Jul 2023 22:22:22 +0800 Subject: [PATCH 0899/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a86a45ce..f41ab29f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 493 | 205 | 263 | 25 | +| 494 | 205 | 264 | 25 | ### 题目 @@ -334,6 +334,7 @@ |1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Medium | |1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | Easy | |1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | +|1455 | 餐厅过滤器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/filter-restaurants-by-vegan-friendly-price-and-distance.rs) | [leetcode](https://leetcode-cn.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance/) | Medium | |1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | |1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | |1491 | 二进制字符串前缀一致的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-times-binary-string-is-prefix-aligned.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-times-binary-string-is-prefix-aligned/) | Medium | From a5b780eb97a5cc23413000d19c33c24c689a67dc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 24 Jul 2023 22:14:26 +0800 Subject: [PATCH 0900/1556] src/bin/kth-smallest-instructions.rs --- src/bin/kth-smallest-instructions.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/bin/kth-smallest-instructions.rs diff --git a/src/bin/kth-smallest-instructions.rs b/src/bin/kth-smallest-instructions.rs new file mode 100644 index 00000000..1c65397b --- /dev/null +++ b/src/bin/kth-smallest-instructions.rs @@ -0,0 +1,22 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +use serde::__private::de; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn kth_smallest_path(destination: Vec, mut k: i32) -> String { + let mut max: Vec = (0..destination[1]) + .map(|_| b'H') + .chain((0..destination[0]).map(|_| b'V')) + .collect(); + + while k > 0 {} + + unsafe { String::from_utf8_unchecked(max) } + } +} From 8060e8c23bc8c9dac3bbc82fbffb03bbde4917ee Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 24 Jul 2023 22:14:27 +0800 Subject: [PATCH 0901/1556] src/bin/WHnhjV.rs --- src/bin/WHnhjV.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/WHnhjV.rs diff --git a/src/bin/WHnhjV.rs b/src/bin/WHnhjV.rs new file mode 100644 index 00000000..71aef651 --- /dev/null +++ b/src/bin/WHnhjV.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn give_gem(mut gem: Vec, operations: Vec>) -> i32 { + for i in operations { + gem[i[1] as usize] += gem[i[0] as usize] / 2; + gem[i[0] as usize] -= gem[i[0] as usize] / 2; + } + + let (mut max, mut min) = (gem[0], gem[0]); + + for i in 1..gem.len() { + max = max.max(gem[i]); + min = min.min(gem[i]); + } + + max - min + } +} From afe6956fc580c4f39979ab4f0e30621528068634 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 24 Jul 2023 22:14:27 +0800 Subject: [PATCH 0902/1556] README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f41ab29f..15861a78 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 494 | 205 | 264 | 25 | +| 496 | 206 | 264 | 26 | ### 题目 @@ -238,6 +238,7 @@ |476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | +|489 | 第 K 条最小指令 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-instructions.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-instructions/) | Hard | |494 | 目标和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/target-sum/) | Medium | |494 | 目标和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/target-sum/) | Medium | |500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | @@ -502,3 +503,4 @@ |1000321 | 值和下标之差都在给定的范围内 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WqeDu.rs) | [leetcode](https://leetcode-cn.com/problems/7WqeDu/) | Medium | |1000333 | 山峰数组的顶部 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/B1IidL.rs) | [leetcode](https://leetcode-cn.com/problems/B1IidL/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | +|1000433 | 宝石补给 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WHnhjV.rs) | [leetcode](https://leetcode-cn.com/problems/WHnhjV/) | Easy | From 9f66b57f03e10afc5dacee78ff7a9dfb927a9fa4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 25 Jul 2023 22:24:13 +0800 Subject: [PATCH 0903/1556] src/bin/minimum-operations-to-halve-array-sum.rs --- .../minimum-operations-to-halve-array-sum.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/minimum-operations-to-halve-array-sum.rs diff --git a/src/bin/minimum-operations-to-halve-array-sum.rs b/src/bin/minimum-operations-to-halve-array-sum.rs new file mode 100644 index 00000000..92b65f71 --- /dev/null +++ b/src/bin/minimum-operations-to-halve-array-sum.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn halve_array(nums: Vec) -> i32 { + #[derive(Clone, Copy, PartialEq, PartialOrd)] + struct F64(f64); + + impl Eq for F64 {} + + impl Ord for F64 { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.partial_cmp(other).unwrap() + } + } + + use std::collections::binary_heap::BinaryHeap; + let sum = nums.iter().map(|x| *x as f64).sum::(); + let mut heap: BinaryHeap = nums.into_iter().map(|x| F64(x as f64)).collect(); + let mut s = 0f64; + let mut r = 0; + + loop { + r += 1; + let p = heap.pop().unwrap(); + if sum - s - p.0 / 2f64 <= sum / 2f64 { + return r; + } + heap.push(F64(p.0 / 2f64)); + s += p.0 / 2f64; + } + } +} From ef0a37b306b58d9d91efe6e13b7ca3b2ff83713b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 25 Jul 2023 22:24:14 +0800 Subject: [PATCH 0904/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 15861a78..e809c9c4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 496 | 206 | 264 | 26 | +| 497 | 206 | 265 | 26 | ### 题目 @@ -368,6 +368,7 @@ |2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | +|2310 | 将数组和减半的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-halve-array-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-halve-array-sum/) | Medium | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | From 5a431b0a7355b7313cab7600768eb26c91ede4a1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 26 Jul 2023 21:18:37 +0800 Subject: [PATCH 0905/1556] src/bin/design-underground-system.rs --- src/bin/design-underground-system.rs | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/bin/design-underground-system.rs diff --git a/src/bin/design-underground-system.rs b/src/bin/design-underground-system.rs new file mode 100644 index 00000000..75c97fd1 --- /dev/null +++ b/src/bin/design-underground-system.rs @@ -0,0 +1,55 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +struct UndergroundSystem { + /// 乘客进站的时间记录 + check_in: std::collections::HashMap, + + /// 记录站到站花费的总时间和总人次 + station: std::collections::HashMap<(String, String), (i32, i32)>, +} + +// /** +// * `&self` means the method takes an immutable reference. +// * If you need a mutable reference, change it to `&mut self` instead. +// */ +impl UndergroundSystem { + fn new() -> Self { + Self { + check_in: Default::default(), + station: Default::default(), + } + } + + fn check_in(&mut self, id: i32, station_name: String, t: i32) { + self.check_in.insert(id, (station_name, t)); + } + + fn check_out(&mut self, id: i32, station_name: String, t: i32) { + let (start_station, start) = self.check_in.remove(&id).unwrap(); + self.station + .entry((start_station, station_name)) + .and_modify(|x| { + x.0 += t - start; + x.1 += 1; + }) + .or_insert((t - start, 1)); + } + + fn get_average_time(&self, start_station: String, end_station: String) -> f64 { + let x = self.station.get(&(start_station, end_station)).unwrap(); + + x.0 as f64 / x.1 as f64 + } +} + +// /** +// * Your UndergroundSystem object will be instantiated and called as such: +// * let obj = UndergroundSystem::new(); +// * obj.check_in(id, stationName, t); +// * obj.check_out(id, stationName, t); +// * let ret_3: f64 = obj.get_average_time(startStation, endStation); +// */ From 4f0d19cc517a844dbfb073ed8ca6273490ac3fa1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 26 Jul 2023 21:18:37 +0800 Subject: [PATCH 0906/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e809c9c4..8e2d9118 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 497 | 206 | 265 | 26 | +| 498 | 206 | 266 | 26 | ### 题目 @@ -340,6 +340,7 @@ |1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | |1491 | 二进制字符串前缀一致的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-times-binary-string-is-prefix-aligned.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-times-binary-string-is-prefix-aligned/) | Medium | |1501 | 圆和矩形是否有重叠 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circle-and-rectangle-overlapping.rs) | [leetcode](https://leetcode-cn.com/problems/circle-and-rectangle-overlapping/) | Medium | +|1512 | 设计地铁系统 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-underground-system.rs) | [leetcode](https://leetcode-cn.com/problems/design-underground-system/) | Medium | |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | |1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | |1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | From de0372ab6ea2fabbefb6b24fa540a69814d201aa Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 27 Jul 2023 22:57:00 +0800 Subject: [PATCH 0907/1556] src/bin/delete-greatest-value-in-each-row.rs --- src/bin/delete-greatest-value-in-each-row.rs | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/delete-greatest-value-in-each-row.rs diff --git a/src/bin/delete-greatest-value-in-each-row.rs b/src/bin/delete-greatest-value-in-each-row.rs new file mode 100644 index 00000000..41665fa9 --- /dev/null +++ b/src/bin/delete-greatest-value-in-each-row.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn delete_greatest_value(mut grid: Vec>) -> i32 { + grid.iter_mut().for_each(|x| x.sort_by_key(|k| -k)); + + let mut r = 0; + + for i in 0..grid[0].len() { + let mut max = 0; + for j in 0..grid.len() { + max = max.max(grid[j][i]); + } + + r += max; + } + + r + } +} From 0c9a28b750da28a6429890a148b93bdbb40a35d3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 27 Jul 2023 22:57:01 +0800 Subject: [PATCH 0908/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e2d9118..ad352882 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 498 | 206 | 266 | 26 | +| 499 | 207 | 266 | 26 | ### 题目 @@ -377,6 +377,7 @@ |2571 | 找出中枢整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-pivot-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-pivot-integer/) | Easy | |2575 | 分割圆的最少切割次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cuts-to-divide-a-circle.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cuts-to-divide-a-circle/) | Easy | |2580 | 回环句 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circular-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/circular-sentence/) | Easy | +|2585 | 删除每行中的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-greatest-value-in-each-row.rs) | [leetcode](https://leetcode-cn.com/problems/delete-greatest-value-in-each-row/) | Easy | |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | From 10885af6620d0e87c0901567c92876205923d54a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 30 Jul 2023 23:08:58 +0800 Subject: [PATCH 0909/1556] src/bin/middle-of-the-linked-list.rs --- src/bin/middle-of-the-linked-list.rs | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/middle-of-the-linked-list.rs diff --git a/src/bin/middle-of-the-linked-list.rs b/src/bin/middle-of-the-linked-list.rs new file mode 100644 index 00000000..75a6b016 --- /dev/null +++ b/src/bin/middle-of-the-linked-list.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} + +impl Solution { + pub fn middle_node(head: Option>) -> Option> { + let (mut s1, mut s2) = (&head, &head); + + while s2.as_ref().unwrap().next.is_some() { + s1 = &s1.as_ref().unwrap().next; + s2 = &s2.as_ref().unwrap().next; + if s2.as_ref().unwrap().next.is_some() { + s2 = &s2.as_ref().unwrap().next; + } + } + + s1.clone() + } +} From e531f34743f6c177537ca37e5cb8fa5e8023b72e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 30 Jul 2023 23:08:58 +0800 Subject: [PATCH 0910/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ad352882..9cab423d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 499 | 207 | 266 | 26 | +| 500 | 208 | 266 | 26 | ### 题目 @@ -287,6 +287,7 @@ |890 | 柠檬水找零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lemonade-change.rs) | [leetcode](https://leetcode-cn.com/problems/lemonade-change/) | Easy | |905 | 最长的斐波那契子序列的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-longest-fibonacci-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence/) | Medium | |906 | 模拟行走机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/walking-robot-simulation.rs) | [leetcode](https://leetcode-cn.com/problems/walking-robot-simulation/) | Medium | +|908 | 链表的中间结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/middle-of-the-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/middle-of-the-linked-list/) | Easy | |917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | |921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | |924 | 公平的糖果交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | From 1e4371ef5086fc4ed23e2175fba1a31f35a33cbd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 31 Jul 2023 20:53:07 +0800 Subject: [PATCH 0911/1556] src/bin/reorder-list.rs --- src/bin/reorder-list.rs | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/bin/reorder-list.rs diff --git a/src/bin/reorder-list.rs b/src/bin/reorder-list.rs new file mode 100644 index 00000000..6bc18c5b --- /dev/null +++ b/src/bin/reorder-list.rs @@ -0,0 +1,45 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::vec; + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} +impl Solution { + pub fn reorder_list(mut head: &mut Option>) { + let mut stack = std::collections::VecDeque::new(); + let mut next = head.as_mut().unwrap().next.take(); + while next.is_some() { + let new = next.as_mut().unwrap().next.take(); + stack.push_back(next); + next = new; + } + let mut flag = false; // false标识从栈后面拿 + while !stack.is_empty() { + let next = if flag { + stack.pop_front().unwrap() + } else { + stack.pop_back().unwrap() + }; + + head.as_mut().unwrap().next = next; + head = &mut head.as_mut().unwrap().next; + + flag = !flag; + } + } +} From 0c63cfeefb3a4ef11de7f36f09e675e25c4fab4e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 31 Jul 2023 20:53:07 +0800 Subject: [PATCH 0912/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9cab423d..225ae08d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 500 | 208 | 266 | 26 | +| 501 | 208 | 267 | 26 | ### 题目 @@ -119,6 +119,7 @@ |136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | Easy | |137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Medium | |139 | 单词拆分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-break.rs) | [leetcode](https://leetcode-cn.com/problems/word-break/) | Medium | +|143 | 重排链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reorder-list.rs) | [leetcode](https://leetcode-cn.com/problems/reorder-list/) | Medium | |144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | Easy | |145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | Easy | |146 | LRU 缓存 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lru-cache.rs) | [leetcode](https://leetcode-cn.com/problems/lru-cache/) | Medium | From 99578b7f3695ddc997ba1fd25135f8528b7b17cf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 1 Aug 2023 21:25:02 +0800 Subject: [PATCH 0913/1556] src/bin/sum-of-matrix-after-queries.rs --- src/bin/sum-of-matrix-after-queries.rs | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/bin/sum-of-matrix-after-queries.rs diff --git a/src/bin/sum-of-matrix-after-queries.rs b/src/bin/sum-of-matrix-after-queries.rs new file mode 100644 index 00000000..cf6c8655 --- /dev/null +++ b/src/bin/sum-of-matrix-after-queries.rs @@ -0,0 +1,38 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 正难则反,倒序操作 + pub fn matrix_sum_queries(n: i32, queries: Vec>) -> i64 { + use std::collections::HashMap; + // r1行 r2列 + let (mut r1, mut r2) = (HashMap::new(), HashMap::new()); + let mut sum = 0; + for i in queries.into_iter().rev() { + match i[0] { + 0 => { + if r1.contains_key(&i[1]) { + continue; + } + + sum += (n as i64 - r2.len() as i64) * i[2] as i64; + r1.insert(i[1], ()); + } + 1 => { + if r2.contains_key(&i[1]) { + continue; + } + + sum += (n as i64 - r1.len() as i64) * i[2] as i64; + r2.insert(i[1], ()); + } + _ => unreachable!(), + } + } + + sum + } +} From 6ebc7146aa4b335b2743a4780e14f558bcc41080 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 1 Aug 2023 21:25:03 +0800 Subject: [PATCH 0914/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 225ae08d..09e87ae1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 501 | 208 | 267 | 26 | +| 502 | 208 | 268 | 26 | ### 题目 @@ -385,6 +385,7 @@ |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | +|2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | From 45cb61ccb54b1462db309acc4a6a160bdec803c6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 2 Aug 2023 21:06:56 +0800 Subject: [PATCH 0915/1556] src/bin/card-flipping-game.rs --- src/bin/card-flipping-game.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/card-flipping-game.rs diff --git a/src/bin/card-flipping-game.rs b/src/bin/card-flipping-game.rs new file mode 100644 index 00000000..2c931756 --- /dev/null +++ b/src/bin/card-flipping-game.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 将较大的放在前面,然后找出后面最小且不在前面的数 + pub fn flipgame(mut fronts: Vec, mut backs: Vec) -> i32 { + let mut set = std::collections::HashSet::new(); + + for i in 0..fronts.len() { + if fronts[i] == backs[i] { + set.insert(fronts[i]); + } + } + + let mut r = -1; + + for i in fronts.into_iter().chain(backs.into_iter()) { + if !set.contains(&i) { + if r == -1 { + r = i; + } else { + r = r.min(i); + } + } + } + + r.max(0) + } +} From fd5c0d2a9b11235c82e1ed18c7ace6aece13453a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 2 Aug 2023 21:06:57 +0800 Subject: [PATCH 0916/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 09e87ae1..ca7cf3e4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 502 | 208 | 268 | 26 | +| 503 | 208 | 269 | 26 | ### 题目 @@ -282,6 +282,7 @@ |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | +|842 | 翻转卡片游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/card-flipping-game.rs) | [leetcode](https://leetcode-cn.com/problems/card-flipping-game/) | Medium | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | From 85cd62425dd6009e4286a856d0d5b4d3e91fd5f8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 3 Aug 2023 21:29:01 +0800 Subject: [PATCH 0917/1556] src/bin/remove-comments.rs --- src/bin/remove-comments.rs | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/bin/remove-comments.rs diff --git a/src/bin/remove-comments.rs b/src/bin/remove-comments.rs new file mode 100644 index 00000000..3b6e3e36 --- /dev/null +++ b/src/bin/remove-comments.rs @@ -0,0 +1,60 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn remove_comments(source: Vec) -> Vec { + enum Type { + /// 没有注释 + NoComment, + /// 块注释 + Comment1, + /// 行注释 + Comment2, + } + + let mut s = vec![]; + + let mut new_line = Vec::new(); + let mut t = Type::NoComment; + + for old_line in source { + let mut i = 0; + while i < old_line.len() { + match t { + Type::NoComment => { + if old_line[i..].starts_with("/*") { + t = Type::Comment1; + i += 1; + } else if old_line[i..].starts_with("//") { + t = Type::Comment2; + i += 1; + } else { + new_line.push(old_line.as_bytes()[i]); + } + } + Type::Comment1 => { + if old_line[i..].starts_with("*/") { + i += 1; + t = Type::NoComment; + } + } + Type::Comment2 => { + t = Type::NoComment; + break; + } + } + i += 1; + } + + if !matches!(t, Type::Comment1) && !new_line.is_empty() { + s.push(unsafe { String::from_utf8_unchecked(new_line) }); + new_line = Vec::new(); + } + } + + s + } +} From 6a0bc77077ce0bef07fc0b633e8cae2276b1ee56 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 3 Aug 2023 21:29:02 +0800 Subject: [PATCH 0918/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ca7cf3e4..ced65db1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 503 | 208 | 269 | 26 | +| 504 | 208 | 270 | 26 | ### 题目 @@ -274,6 +274,7 @@ |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | |718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | +|722 | 删除注释 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-comments.rs) | [leetcode](https://leetcode-cn.com/problems/remove-comments/) | Medium | |739 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/daily-temperatures.rs) | [leetcode](https://leetcode-cn.com/problems/daily-temperatures/) | Medium | |742 | 转换成小写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/to-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/to-lower-case/) | Easy | |782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | From cf2e7ceeb32a53f5456d81731845fdabe26d4dce Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 4 Aug 2023 21:44:26 +0800 Subject: [PATCH 0919/1556] src/bin/predict-the-winner.rs --- src/bin/predict-the-winner.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/predict-the-winner.rs diff --git a/src/bin/predict-the-winner.rs b/src/bin/predict-the-winner.rs new file mode 100644 index 00000000..9a7559d8 --- /dev/null +++ b/src/bin/predict-the-winner.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn predict_the_winner(nums: Vec) -> bool { + let mut dp = vec![vec![0; nums.len()]; nums.len()]; + + for i in 0..nums.len() { + dp[i][i] = nums[i]; + } + + if nums.len() > 1 { + for i in (0..=nums.len() - 2).rev() { + for j in i + 1..nums.len() { + dp[i][j] = (nums[i] - dp[i + 1][j]).max(nums[j] - dp[i][j - 1]); + } + } + } + + dp[0][nums.len() - 1] >= 0 + } +} From e61aee6230cc3b986c1da05c9118d1d94e9544db Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 4 Aug 2023 21:44:27 +0800 Subject: [PATCH 0920/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ced65db1..528772b2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 504 | 208 | 270 | 26 | +| 505 | 208 | 271 | 26 | ### 题目 @@ -239,6 +239,7 @@ |476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | |485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | +|486 | 预测赢家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/predict-the-winner.rs) | [leetcode](https://leetcode-cn.com/problems/predict-the-winner/) | Medium | |489 | 第 K 条最小指令 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-instructions.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-instructions/) | Hard | |494 | 目标和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/target-sum/) | Medium | |494 | 目标和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/target-sum/) | Medium | From e7a772ae7b7d169cc0afc9c26272a478f61cd47d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 6 Aug 2023 20:24:39 +0800 Subject: [PATCH 0921/1556] src/bin/minimum-cost-to-move-chips-to-the-same-position.rs --- ...cost-to-move-chips-to-the-same-position.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/minimum-cost-to-move-chips-to-the-same-position.rs diff --git a/src/bin/minimum-cost-to-move-chips-to-the-same-position.rs b/src/bin/minimum-cost-to-move-chips-to-the-same-position.rs new file mode 100644 index 00000000..542b532f --- /dev/null +++ b/src/bin/minimum-cost-to-move-chips-to-the-same-position.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_cost_to_move_chips(position: Vec) -> i32 { + let (mut s, mut n) = (0, 0); // 奇数、偶数的个数 + + for i in position { + if i % 2 == 0 { + s += 1; + } else { + n += 1; + } + } + + s.min(n) + } +} From 0402b20d8a373961494176829ae28ab6fd662040 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 6 Aug 2023 20:24:40 +0800 Subject: [PATCH 0922/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 528772b2..fc294be4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 505 | 208 | 271 | 26 | +| 506 | 209 | 271 | 26 | ### 题目 @@ -328,6 +328,7 @@ |1293 | 存在连续三个奇数的数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/three-consecutive-odds.rs) | [leetcode](https://leetcode-cn.com/problems/three-consecutive-odds/) | Easy | |1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | |1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | +|1329 | 玩筹码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cost-to-move-chips-to-the-same-position.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position/) | Easy | |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | |1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | |1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | From efc44e5ede6888ee55f943d07d847e0b2afd9c23 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 7 Aug 2023 21:56:00 +0800 Subject: [PATCH 0923/1556] src/bin/design-twitter.rs --- src/bin/design-twitter.rs | 97 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/bin/design-twitter.rs diff --git a/src/bin/design-twitter.rs b/src/bin/design-twitter.rs new file mode 100644 index 00000000..229337aa --- /dev/null +++ b/src/bin/design-twitter.rs @@ -0,0 +1,97 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +#[derive(Default)] +struct User { + /// 关注者 + stars: std::collections::HashSet, + /// 时间与postid + posts: std::collections::LinkedList<(std::time::Instant, i32)>, +} + +struct Twitter { + users: std::collections::HashMap, +} + +/** +* `&self` means the method takes an immutable reference. +* If you need a mutable reference, change it to `&mut self` instead. + +* Your Twitter object will be instantiated and called as such: +* let obj = Twitter::new(); +* obj.post_tweet(userId, tweetId); +* let ret_2: Vec = obj.get_news_feed(userId); +* obj.follow(followerId, followeeId); +* obj.unfollow(followerId, followeeId); +*/ +impl Twitter { + fn new() -> Self { + Self { + users: std::collections::HashMap::new(), + } + } + + fn post_tweet(&mut self, user_id: i32, tweet_id: i32) { + let user = self.users.entry(user_id).or_insert_with(|| User::default()); + + if user.posts.len() == 10 { + user.posts.pop_back(); + } + + let now = std::time::Instant::now(); + + user.posts.push_front((now, tweet_id)); + } + + fn get_news_feed(&self, user_id: i32) -> Vec { + let user = if let Some(x) = self.users.get(&user_id) { + x + } else { + return vec![]; + }; + + let mut x = std::collections::BinaryHeap::new(); + + for i in user + .stars + .iter() + .map_while(|x| self.users.get(x)) + .flat_map(|x| x.posts.iter()) + .chain(user.posts.iter()) + { + x.push(std::cmp::Reverse(i.clone())); + + if x.len() == 11 { + x.pop(); + } + } + + let mut r = vec![0; x.len()]; + + while let Some(p) = x.pop() { + r[x.len()] = p.0 .1; + } + + r + } + + fn follow(&mut self, follower_id: i32, followee_id: i32) { + self.users + .entry(follower_id) + .or_insert_with(|| User::default()) + .stars + .insert(followee_id); + } + + fn unfollow(&mut self, follower_id: i32, followee_id: i32) { + self.users + .entry(follower_id) + .and_modify(|user| { + user.stars.remove(&followee_id); + }) + .or_insert_with(|| User::default()); + } +} From 38f75898168e838654bb615e4774ee734c564213 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 7 Aug 2023 21:56:01 +0800 Subject: [PATCH 0924/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc294be4..ec27fa8a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 506 | 209 | 271 | 26 | +| 507 | 209 | 272 | 26 | ### 题目 @@ -201,6 +201,7 @@ |347 | 前 K 个高频元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/top-k-frequent-elements.rs) | [leetcode](https://leetcode-cn.com/problems/top-k-frequent-elements/) | Medium | |349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | |350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | +|355 | 设计推特 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-twitter.rs) | [leetcode](https://leetcode-cn.com/problems/design-twitter/) | Medium | |357 | 统计各位数字都不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | |367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | |371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | From 17ce32f1cd46986850ac9ea00374942f1856df5f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 8 Aug 2023 21:18:17 +0800 Subject: [PATCH 0925/1556] src/bin/maximum-absolute-sum-of-any-subarray.rs --- .../maximum-absolute-sum-of-any-subarray.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/maximum-absolute-sum-of-any-subarray.rs diff --git a/src/bin/maximum-absolute-sum-of-any-subarray.rs b/src/bin/maximum-absolute-sum-of-any-subarray.rs new file mode 100644 index 00000000..7e4b98b5 --- /dev/null +++ b/src/bin/maximum-absolute-sum-of-any-subarray.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_absolute_sum(nums: Vec) -> i32 { + let mut r = 0; + let (mut max, mut min) = (0, 0); // max表示正数前缀和,min表示负数前缀和 + for i in nums { + r = r.max(max + i).max((min + i).abs()).max(i.abs()); + + if i > 0 { + max += i; + min = 0.min(i + min); + } else if i < 0 { + min += i; + max = 0.max(max + i); + } + } + + r + } +} From eaf60da293320fa0be570ee2bc0fdb90f194ab33 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 8 Aug 2023 21:18:18 +0800 Subject: [PATCH 0926/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ec27fa8a..03072be9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 507 | 209 | 272 | 26 | +| 508 | 209 | 273 | 26 | ### 题目 @@ -365,6 +365,7 @@ |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | |1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | +|1849 | 任意子数组和的绝对值的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-absolute-sum-of-any-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | |1894 | 交替合并字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-strings-alternately.rs) | [leetcode](https://leetcode-cn.com/problems/merge-strings-alternately/) | Easy | |1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | |1952 | 最少侧跳次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sideway-jumps.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sideway-jumps/) | Medium | From da39787306c1bf19a48caa0ff66764b049c123ce Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 9 Aug 2023 19:53:27 +0800 Subject: [PATCH 0927/1556] src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs --- ...product-and-sum-of-digits-of-an-integer.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs diff --git a/src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs b/src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs new file mode 100644 index 00000000..81a0388c --- /dev/null +++ b/src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn subtract_product_and_sum(mut n: i32) -> i32 { + let mut r = 1; + let mut s = 0; + + while n > 0 { + r *= (n % 10); + s += (n % 10); + n /= 10; + } + + r - s + } +} From 8941eef23a528401ee97cd32a1de69ea6ecc7579 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 9 Aug 2023 19:53:28 +0800 Subject: [PATCH 0928/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 03072be9..2efbfefa 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 508 | 209 | 273 | 26 | +| 509 | 210 | 273 | 26 | ### 题目 @@ -337,6 +337,7 @@ |1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | |1380 | 统计封闭岛屿的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-closed-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-closed-islands/) | Medium | |1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | +|1406 | 整数的各位积和之差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/) | Easy | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | |1426 | 和为零的 N 个不同整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | |1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Medium | From 656ed45e263476ec9d53a479583c9f368f068c72 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 10 Aug 2023 21:04:44 +0800 Subject: [PATCH 0929/1556] src/bin/find-the-score-of-all-prefixes-of-an-array.rs --- ...d-the-score-of-all-prefixes-of-an-array.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/find-the-score-of-all-prefixes-of-an-array.rs diff --git a/src/bin/find-the-score-of-all-prefixes-of-an-array.rs b/src/bin/find-the-score-of-all-prefixes-of-an-array.rs new file mode 100644 index 00000000..56b5a4fc --- /dev/null +++ b/src/bin/find-the-score-of-all-prefixes-of-an-array.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_prefix_score(mut nums: Vec) -> Vec { + let mut max = 0i64; + let mut sum = 0; + let mut result = vec![0; nums.len()]; + for i in 0..nums.len() { + max = max.max(nums[i] as i64); + let s = max + nums[i] as i64; + result[i] = sum + s; + sum += s; + } + + result + } +} From 70114302d7d5a90d9c0992bb5e92f217f6811da1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 10 Aug 2023 21:04:45 +0800 Subject: [PATCH 0930/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2efbfefa..a5d8f26a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 509 | 210 | 273 | 26 | +| 510 | 210 | 274 | 26 | ### 题目 @@ -389,6 +389,7 @@ |2585 | 删除每行中的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-greatest-value-in-each-row.rs) | [leetcode](https://leetcode-cn.com/problems/delete-greatest-value-in-each-row/) | Easy | |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | +|2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | From 09780599210f1c99db7c0b4ae4b98d78479a66cb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 12 Aug 2023 18:04:51 +0800 Subject: [PATCH 0931/1556] src/bin/two-out-of-three.rs --- src/bin/two-out-of-three.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bin/two-out-of-three.rs diff --git a/src/bin/two-out-of-three.rs b/src/bin/two-out-of-three.rs new file mode 100644 index 00000000..4d806c96 --- /dev/null +++ b/src/bin/two-out-of-three.rs @@ -0,0 +1,37 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::collections::HashSet; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn two_out_of_three(nums1: Vec, nums2: Vec, nums3: Vec) -> Vec { + use std::collections::HashSet; + let mut hash1: HashSet<_> = nums1.iter().collect(); + let mut hash2 = HashSet::new(); + let mut hash3 = HashSet::new(); + + let mut result = vec![]; + + for i in nums2.iter() { + if hash1.contains(i) && !hash2.contains(i) { + result.push(*i); + } + hash2.insert(*i); + } + + for i in nums3.iter() { + if ((hash1.contains(i) && !hash2.contains(i)) + || (!hash1.contains(i) && hash2.contains(i))) + && !hash3.contains(i) + { + result.push(*i); + } + hash3.insert(*i); + } + + result + } +} From 2333dfceaa26a40cc27705cffc8f6306cddeaae0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 12 Aug 2023 18:04:52 +0800 Subject: [PATCH 0932/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a5d8f26a..90635a8b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 510 | 210 | 274 | 26 | +| 511 | 211 | 274 | 26 | ### 题目 @@ -374,6 +374,7 @@ |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2022 | 最大子序列交替和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-alternating-subsequence-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-alternating-subsequence-sum/) | Medium | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | +|2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | |2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | From 0ecbdfd4fb027c9e97917d0046ffdea1316e9ebf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 14 Aug 2023 21:41:24 +0800 Subject: [PATCH 0933/1556] src/bin/increasing-decreasing-string.rs --- src/bin/increasing-decreasing-string.rs | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bin/increasing-decreasing-string.rs diff --git a/src/bin/increasing-decreasing-string.rs b/src/bin/increasing-decreasing-string.rs new file mode 100644 index 00000000..2893451b --- /dev/null +++ b/src/bin/increasing-decreasing-string.rs @@ -0,0 +1,40 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn sort_string(mut s: String) -> String { + let mut count = [0; 26]; + for &i in s.as_bytes() { + count[(i - b'a') as usize] += 1; + } + let mut slice = unsafe { s.as_bytes_mut() }; + let mut start = 0; + let mut flag = false; // true为选最大,false为选最小 + while start < slice.len() { + if !flag { + for i in 0..26 { + if count[i] > 0 { + slice[start] = i as u8 + b'a'; + count[i] -= 1; + start += 1; + } + } + } else { + for i in (0..26).rev() { + if count[i] > 0 { + slice[start] = i as u8 + b'a'; + count[i] -= 1; + start += 1; + } + } + } + + flag = !flag; + } + + s + } +} From efae9346ea33d214f0f6c876968800c1fbb2b9f2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 14 Aug 2023 21:41:24 +0800 Subject: [PATCH 0934/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 90635a8b..0fed7c06 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 511 | 211 | 274 | 26 | +| 512 | 212 | 274 | 26 | ### 题目 @@ -345,6 +345,7 @@ |1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | |1455 | 餐厅过滤器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/filter-restaurants-by-vegan-friendly-price-and-distance.rs) | [leetcode](https://leetcode-cn.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance/) | Medium | |1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | +|1472 | 上升下降字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increasing-decreasing-string.rs) | [leetcode](https://leetcode-cn.com/problems/increasing-decreasing-string/) | Easy | |1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | |1491 | 二进制字符串前缀一致的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-times-binary-string-is-prefix-aligned.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-times-binary-string-is-prefix-aligned/) | Medium | |1501 | 圆和矩形是否有重叠 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circle-and-rectangle-overlapping.rs) | [leetcode](https://leetcode-cn.com/problems/circle-and-rectangle-overlapping/) | Medium | From 9f76d5889928bedee33c01c7671a80aa1d71ccd0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 15 Aug 2023 20:36:52 +0800 Subject: [PATCH 0935/1556] src/bin/find-and-replace-in-string.rs --- src/bin/find-and-replace-in-string.rs | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bin/find-and-replace-in-string.rs diff --git a/src/bin/find-and-replace-in-string.rs b/src/bin/find-and-replace-in-string.rs new file mode 100644 index 00000000..fe93ea65 --- /dev/null +++ b/src/bin/find-and-replace-in-string.rs @@ -0,0 +1,40 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_replace_string( + s: String, + indices: Vec, + sources: Vec, + targets: Vec, + ) -> String { + let mut map1: std::collections::HashMap<_, _> = std::collections::HashMap::new(); + let mut map2: std::collections::HashMap<_, _> = std::collections::HashMap::new(); + + for i in 0..indices.len() { + map1.insert(indices[i] as usize, &sources[i]); + map2.insert(indices[i] as usize, i); + } + + let mut result = Vec::new(); + let mut i = 0; + + while i < s.len() { + if let Some(x) = map1.get(&i) { + if s[i..].starts_with(x.as_str()) { + result.extend_from_slice(targets[*map2.get(&i).unwrap()].as_bytes()); + i += x.len(); + continue; + } + } + + result.push(s.as_bytes()[i]); + i += 1; + } + + unsafe { String::from_utf8_unchecked(result) } + } +} From 8e911d4d60b051aa9818e4f1f6111de05e0df931 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 15 Aug 2023 20:36:53 +0800 Subject: [PATCH 0936/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fed7c06..2e3a8763 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 512 | 212 | 274 | 26 | +| 513 | 212 | 275 | 26 | ### 题目 @@ -288,6 +288,7 @@ |842 | 翻转卡片游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/card-flipping-game.rs) | [leetcode](https://leetcode-cn.com/problems/card-flipping-game/) | Medium | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | +|862 | 字符串中的查找与替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-and-replace-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-and-replace-in-string/) | Medium | |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | |890 | 柠檬水找零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lemonade-change.rs) | [leetcode](https://leetcode-cn.com/problems/lemonade-change/) | Easy | |905 | 最长的斐波那契子序列的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-longest-fibonacci-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence/) | Medium | From db53a26bbac4c6c3412c6304baead222a047502b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 16 Aug 2023 20:52:26 +0800 Subject: [PATCH 0937/1556] src/bin/find-the-losers-of-the-circular-game.rs --- .../find-the-losers-of-the-circular-game.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/find-the-losers-of-the-circular-game.rs diff --git a/src/bin/find-the-losers-of-the-circular-game.rs b/src/bin/find-the-losers-of-the-circular-game.rs new file mode 100644 index 00000000..34c0aaae --- /dev/null +++ b/src/bin/find-the-losers-of-the-circular-game.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn circular_game_losers(n: i32, k: i32) -> Vec { + let mut set = std::collections::HashSet::new(); + let mut current = 1; + for i in 1.. { + set.insert(current); + current = if (i * k + current) <= n { + i * k + current + } else if (i * k + current) % n == 0 { + n + } else { + (i * k + current) % n + }; + + if set.contains(¤t) { + break; + } + } + + (1..=n).filter(|i| !set.contains(i)).collect() + } +} From ecab8187ffbfb7f3b8a61cc402fa9853a93aaa63 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 16 Aug 2023 20:52:26 +0800 Subject: [PATCH 0938/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e3a8763..1626da09 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 513 | 212 | 275 | 26 | +| 514 | 213 | 275 | 26 | ### 题目 @@ -396,6 +396,7 @@ |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | +|2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | From 73f83daa4bdbc7b755b62e72170a5c51c0d72296 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 17 Aug 2023 20:51:58 +0800 Subject: [PATCH 0939/1556] src/bin/the-employee-that-worked-on-the-longest-task.rs --- ...mployee-that-worked-on-the-longest-task.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/bin/the-employee-that-worked-on-the-longest-task.rs diff --git a/src/bin/the-employee-that-worked-on-the-longest-task.rs b/src/bin/the-employee-that-worked-on-the-longest-task.rs new file mode 100644 index 00000000..2ddf58c9 --- /dev/null +++ b/src/bin/the-employee-that-worked-on-the-longest-task.rs @@ -0,0 +1,26 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn hardest_worker(n: i32, logs: Vec>) -> i32 { + let mut t = 0; + let mut r = 0; + + for i in 0..logs.len() { + if i == 0 { + t = logs[i][0]; + r = logs[i][1]; + } else if logs[i][1] - logs[i - 1][1] > r { + t = logs[i][0]; + r = logs[i][1] - logs[i - 1][1]; + } else if logs[i][1] - logs[i - 1][1] == r { + t = t.min(logs[i][0]); + } + } + + t + } +} From 2a02540eca398d69c36447f469d43c23920ad214 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 17 Aug 2023 20:51:58 +0800 Subject: [PATCH 0940/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1626da09..ffacd5c0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 514 | 213 | 275 | 26 | +| 515 | 214 | 275 | 26 | ### 题目 @@ -384,6 +384,7 @@ |2310 | 将数组和减半的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-halve-array-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-halve-array-sum/) | Medium | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | +|2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | |2571 | 找出中枢整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-pivot-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-pivot-integer/) | Easy | From 1e3b2edcbbb059bb8c2c1acea2ca6fa16549f5e7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 20 Aug 2023 23:49:39 +0800 Subject: [PATCH 0941/1556] src/bin/root-equals-sum-of-children.rs --- src/bin/root-equals-sum-of-children.rs | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/root-equals-sum-of-children.rs diff --git a/src/bin/root-equals-sum-of-children.rs b/src/bin/root-equals-sum-of-children.rs new file mode 100644 index 00000000..5f75fb15 --- /dev/null +++ b/src/bin/root-equals-sum-of-children.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn check_tree(root: Option>>) -> bool { + let root = root.unwrap(); + let root_val = root.borrow().val; + let left_val = root.borrow_mut().left.take().unwrap().borrow().val; + let right_val = root.borrow_mut().right.take().unwrap().borrow().val; + + left_val + right_val == root_val + } +} From c1b344f871bff20867f61fefbb806bfbabb4c2bd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 20 Aug 2023 23:49:39 +0800 Subject: [PATCH 0942/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ffacd5c0..b0dae428 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 515 | 214 | 275 | 26 | +| 516 | 215 | 275 | 26 | ### 题目 @@ -383,6 +383,7 @@ |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | |2310 | 将数组和减半的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-halve-array-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-halve-array-sum/) | Medium | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | +|2384 | 判断根结点是否等于子结点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/root-equals-sum-of-children.rs) | [leetcode](https://leetcode-cn.com/problems/root-equals-sum-of-children/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | From 9c891c15bcb9c23d352bc6760a5ab2db3802cad6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 21 Aug 2023 21:37:51 +0800 Subject: [PATCH 0943/1556] src/bin/move-pieces-to-obtain-a-string.rs --- src/bin/move-pieces-to-obtain-a-string.rs | 55 +++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/bin/move-pieces-to-obtain-a-string.rs diff --git a/src/bin/move-pieces-to-obtain-a-string.rs b/src/bin/move-pieces-to-obtain-a-string.rs new file mode 100644 index 00000000..b7901070 --- /dev/null +++ b/src/bin/move-pieces-to-obtain-a-string.rs @@ -0,0 +1,55 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn can_change(start: String, target: String) -> bool { + let (start, target) = (start.as_bytes(), target.as_bytes()); + let (mut i, mut j) = (0, 0); + + while i < start.len() && j < target.len() { + while i < start.len() && start[i] == b'_' { + i += 1; + } + + while j < target.len() && target[j] == b'_' { + j += 1; + } + + if i >= start.len() || j >= target.len() { + break; + } + + if start[i] != target[j] { + return false; + } + + match start[i] { + b'L' if i < j => return false, + b'R' if i > j => return false, + _ => { + i += 1; + j += 1; + } + } + } + + while i < start.len() { + if start[i] != b'_' { + return false; + } + i += 1; + } + + while j < target.len() { + if target[j] != b'_' { + return false; + } + j += 1; + } + + true + } +} From 81590c907e2603ac1e1b260b478d2b81bb092f5c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 21 Aug 2023 21:37:52 +0800 Subject: [PATCH 0944/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b0dae428..7d36def2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 516 | 215 | 275 | 26 | +| 517 | 215 | 276 | 26 | ### 题目 @@ -385,6 +385,7 @@ |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |2384 | 判断根结点是否等于子结点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/root-equals-sum-of-children.rs) | [leetcode](https://leetcode-cn.com/problems/root-equals-sum-of-children/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | +|2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | |2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | From 62d0b55b9f2755d215fd400383037da8660368b4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 22 Aug 2023 21:03:33 +0800 Subject: [PATCH 0945/1556] src/bin/maximize-distance-to-closest-person.rs --- .../maximize-distance-to-closest-person.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/maximize-distance-to-closest-person.rs diff --git a/src/bin/maximize-distance-to-closest-person.rs b/src/bin/maximize-distance-to-closest-person.rs new file mode 100644 index 00000000..f379d510 --- /dev/null +++ b/src/bin/maximize-distance-to-closest-person.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_dist_to_closest(seats: Vec) -> i32 { + let mut s = 0; + let mut last = -1; + + for i in 0..seats.len() { + if seats[i] == 1 { + if last == -1 { + s = s.max(i as i32); + } else { + s = s.max((i as i32 - last) / 2); + } + last = i as i32; + } + } + + if seats[seats.len() - 1] == 0 { + s = s.max(seats.len() as i32 - 1 - last); + } + + s + } +} From d210abdfd898f9e7e3ce0cf56e277de57d6985b3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 22 Aug 2023 21:03:34 +0800 Subject: [PATCH 0946/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d36def2..4cb40666 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 517 | 215 | 276 | 26 | +| 518 | 215 | 277 | 26 | ### 题目 @@ -290,6 +290,7 @@ |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | |862 | 字符串中的查找与替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-and-replace-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-and-replace-in-string/) | Medium | |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | +|879 | 到最近的人的最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximize-distance-to-closest-person.rs) | [leetcode](https://leetcode-cn.com/problems/maximize-distance-to-closest-person/) | Medium | |890 | 柠檬水找零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lemonade-change.rs) | [leetcode](https://leetcode-cn.com/problems/lemonade-change/) | Easy | |905 | 最长的斐波那契子序列的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-longest-fibonacci-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence/) | Medium | |906 | 模拟行走机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/walking-robot-simulation.rs) | [leetcode](https://leetcode-cn.com/problems/walking-robot-simulation/) | Medium | From 3f8901cc0b73bea3341f5b8eba5629d81db0db59 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 23 Aug 2023 20:31:16 +0800 Subject: [PATCH 0947/1556] src/bin/check-if-a-string-is-an-acronym-of-words.rs --- ...heck-if-a-string-is-an-acronym-of-words.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/check-if-a-string-is-an-acronym-of-words.rs diff --git a/src/bin/check-if-a-string-is-an-acronym-of-words.rs b/src/bin/check-if-a-string-is-an-acronym-of-words.rs new file mode 100644 index 00000000..28503c00 --- /dev/null +++ b/src/bin/check-if-a-string-is-an-acronym-of-words.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn is_acronym(words: Vec, s: String) -> bool { + if words.len() != s.len() { + return false; + } + + for i in 0..s.len() { + if words[i].as_bytes()[0] != s.as_bytes()[i] { + return false; + } + } + + true + } +} From ea2b457584d00f6b4bfa32b530068388278d4209 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 23 Aug 2023 20:31:16 +0800 Subject: [PATCH 0948/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cb40666..592c8df3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 518 | 215 | 277 | 26 | +| 519 | 216 | 277 | 26 | ### 题目 @@ -402,6 +402,7 @@ |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | +|2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | From cd6309349c392d048e16d4d7e462d4cf8ed5dd65 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 24 Aug 2023 21:05:09 +0800 Subject: [PATCH 0949/1556] src/bin/count-servers-that-communicate.rs --- src/bin/count-servers-that-communicate.rs | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/bin/count-servers-that-communicate.rs diff --git a/src/bin/count-servers-that-communicate.rs b/src/bin/count-servers-that-communicate.rs new file mode 100644 index 00000000..1d7954ca --- /dev/null +++ b/src/bin/count-servers-that-communicate.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_servers(grid: Vec>) -> i32 { + let (mut row, mut col) = ( + std::collections::HashMap::new(), + std::collections::HashMap::new(), + ); + + let mut result = 0; + + for i in 0..grid.len() { + for j in 0..grid[0].len() { + if grid[i][j] == 1 { + row.entry(i).and_modify(|x| *x += 1).or_insert(1); + col.entry(j).and_modify(|x| *x += 1).or_insert(1); + } + } + } + + println!("{row:?}"); + println!("{col:?}"); + + for i in 0..grid.len() { + for j in 0..grid[0].len() { + if grid[i][j] == 1 { + match (row.get(&i), col.get(&j)) { + (Some(&x), Some(&y)) if x > 1 || y > 1 => result += 1, + _ => {} + } + } + } + } + + result + } +} From 1496168ca7c0a193497a92b2fa6d41b3704a0c79 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 24 Aug 2023 21:05:10 +0800 Subject: [PATCH 0950/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 592c8df3..2f88186a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 519 | 216 | 277 | 26 | +| 520 | 216 | 278 | 26 | ### 题目 @@ -339,6 +339,7 @@ |1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | |1380 | 统计封闭岛屿的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-closed-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-closed-islands/) | Medium | |1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | +|1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | |1406 | 整数的各位积和之差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/) | Easy | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | |1426 | 和为零的 N 个不同整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | From 77c72996f59d56772267ae292acbc8e5997dec2e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 24 Aug 2023 21:05:16 +0800 Subject: [PATCH 0951/1556] src/bin/count-servers-that-communicate.rs --- src/bin/count-servers-that-communicate.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/bin/count-servers-that-communicate.rs b/src/bin/count-servers-that-communicate.rs index 1d7954ca..5ea29be7 100644 --- a/src/bin/count-servers-that-communicate.rs +++ b/src/bin/count-servers-that-communicate.rs @@ -22,9 +22,6 @@ impl Solution { } } - println!("{row:?}"); - println!("{col:?}"); - for i in 0..grid.len() { for j in 0..grid[0].len() { if grid[i][j] == 1 { From 5bd8546852693df458753e7151a0d69ca6f1c3d9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 24 Aug 2023 21:05:17 +0800 Subject: [PATCH 0952/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2f88186a..c29a8768 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 520 | 216 | 278 | 26 | +| 521 | 216 | 279 | 26 | ### 题目 @@ -340,6 +340,7 @@ |1380 | 统计封闭岛屿的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-closed-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-closed-islands/) | Medium | |1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | |1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | +|1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | |1406 | 整数的各位积和之差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/) | Easy | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | |1426 | 和为零的 N 个不同整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | From 2e811837d56952c4f906c1304b56941618804ee9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 27 Aug 2023 21:52:16 +0800 Subject: [PATCH 0953/1556] src/bin/largest-3-same-digit-number-in-string.rs --- .../largest-3-same-digit-number-in-string.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/bin/largest-3-same-digit-number-in-string.rs diff --git a/src/bin/largest-3-same-digit-number-in-string.rs b/src/bin/largest-3-same-digit-number-in-string.rs new file mode 100644 index 00000000..736c4b5e --- /dev/null +++ b/src/bin/largest-3-same-digit-number-in-string.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn largest_good_integer(num: String) -> String { + let mut current = b' '; + let mut count = 0; + let mut result = String::new(); + for i in 0..num.len() { + if num.as_bytes()[i] == current { + count += 1; + if count == 3 { + if result < num[i - 2..=i].to_owned() { + result = num[i - 2..=i].to_owned(); + } + current = b' '; + count = 0; + } + } else { + current = num.as_bytes()[i]; + count = 1; + } + } + + result + } +} From 21e721a8fad7ad39d0cc4b77ca607b051b0d610c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 27 Aug 2023 21:52:17 +0800 Subject: [PATCH 0954/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c29a8768..6baa701b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 521 | 216 | 279 | 26 | +| 522 | 217 | 279 | 26 | ### 题目 @@ -386,6 +386,7 @@ |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | |2310 | 将数组和减半的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-halve-array-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-halve-array-sum/) | Medium | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | +|2346 | 字符串中最大的 3 位相同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-3-same-digit-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-3-same-digit-number-in-string/) | Easy | |2384 | 判断根结点是否等于子结点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/root-equals-sum-of-children.rs) | [leetcode](https://leetcode-cn.com/problems/root-equals-sum-of-children/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | From f4d890b21abcf205c5e9c3cff2ed89189851c940 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 28 Aug 2023 21:15:39 +0800 Subject: [PATCH 0955/1556] src/bin/increasing-triplet-subsequence.rs --- src/bin/increasing-triplet-subsequence.rs | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/increasing-triplet-subsequence.rs diff --git a/src/bin/increasing-triplet-subsequence.rs b/src/bin/increasing-triplet-subsequence.rs new file mode 100644 index 00000000..44ee4b1b --- /dev/null +++ b/src/bin/increasing-triplet-subsequence.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn increasing_triplet(nums: Vec) -> bool { + if nums.len() < 3 { + return false; + } + + let (mut first, mut second) = (nums[0], i32::MAX); + + for &i in nums[1..].into_iter() { + if i > second { + return true; + } else if i > first { + second = i; + } else { + first = i; + } + } + + false + } +} From 3787fd299134d3ebc183813607a7bd0273e7bf83 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 28 Aug 2023 21:15:40 +0800 Subject: [PATCH 0956/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6baa701b..858c1800 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 522 | 217 | 279 | 26 | +| 523 | 217 | 280 | 26 | ### 题目 @@ -194,6 +194,7 @@ |319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | |322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | |326 | 3 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | +|334 | 递增的三元子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increasing-triplet-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/increasing-triplet-subsequence/) | Medium | |337 | 打家劫舍 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-iii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-iii/) | Medium | |338 | 比特位计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-bits.rs) | [leetcode](https://leetcode-cn.com/problems/counting-bits/) | Easy | |344 | 反转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string/) | Easy | From 1f88745a86b8a981c880324210908d6e2c2de6f0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 30 Aug 2023 21:39:58 +0800 Subject: [PATCH 0957/1556] src/bin/ambiguous-coordinates.rs --- src/bin/ambiguous-coordinates.rs | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/bin/ambiguous-coordinates.rs diff --git a/src/bin/ambiguous-coordinates.rs b/src/bin/ambiguous-coordinates.rs new file mode 100644 index 00000000..7d14334f --- /dev/null +++ b/src/bin/ambiguous-coordinates.rs @@ -0,0 +1,71 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn ambiguous_coordinates(s: String) -> Vec { + let s = &s[1..s.len() - 1]; + let mut result = vec![]; + for i in 0..s.len() { + let s1 = Self::get_num(&s[..i]); + let s2 = Self::get_num(&s[i..]); + + for j in s1.iter() { + for k in s2.iter() { + result.push(format!("({j}, {k})")); + } + } + } + + result + } + + fn get_num(s: &str) -> Vec { + let mut r = vec![]; + if s.is_empty() { + return r; + } + + if s.as_bytes()[0] != b'0' || s.len() == 1 { + r.push(String::from(s)); + } + + for i in 1..s.len() { + if Self::is_valid_1(&s[..i]) && Self::is_valid_2(&s[i..]) { + r.push(format!("{}.{}", &s[..i], &s[i..])) + } + } + + r + } + + fn is_valid_1(s: &str) -> bool { + if s.is_empty() { + return false; + } + + if s.len() == 1 { + return true; + } + + if s.as_bytes()[0] == b'0' { + return false; + } + + true + } + + fn is_valid_2(s: &str) -> bool { + if s.is_empty() { + return false; + } + + if s.as_bytes()[s.len() - 1] == b'0' { + return false; + } + + true + } +} From bc60ef44d5cd179401573d73a33b7c84b65327ca Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 30 Aug 2023 21:39:59 +0800 Subject: [PATCH 0958/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 858c1800..eee5915a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 523 | 217 | 280 | 26 | +| 524 | 217 | 281 | 26 | ### 题目 @@ -286,6 +286,7 @@ |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | +|834 | 模糊坐标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ambiguous-coordinates.rs) | [leetcode](https://leetcode-cn.com/problems/ambiguous-coordinates/) | Medium | |842 | 翻转卡片游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/card-flipping-game.rs) | [leetcode](https://leetcode-cn.com/problems/card-flipping-game/) | Medium | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | From 4f18c1fb16dc41796d37013281b08957794e9f82 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 31 Aug 2023 23:02:38 +0800 Subject: [PATCH 0959/1556] src/bin/count-good-nodes-in-binary-tree.rs --- src/bin/count-good-nodes-in-binary-tree.rs | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/bin/count-good-nodes-in-binary-tree.rs diff --git a/src/bin/count-good-nodes-in-binary-tree.rs b/src/bin/count-good-nodes-in-binary-tree.rs new file mode 100644 index 00000000..c8c599f2 --- /dev/null +++ b/src/bin/count-good-nodes-in-binary-tree.rs @@ -0,0 +1,55 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn good_nodes(root: Option>>) -> i32 { + if root.is_none() { + return 0; + } + + let left = root.as_ref().unwrap().borrow_mut().left.take(); + let right = root.as_ref().unwrap().borrow_mut().right.take(); + let value = root.as_ref().unwrap().borrow().val; + + 1 + Self::f(value, left) + Self::f(value, right) + } + + fn f(max: i32, root: Option>>) -> i32 { + if root.is_none() { + return 0; + } + + let left = root.as_ref().unwrap().borrow_mut().left.take(); + let right = root.as_ref().unwrap().borrow_mut().right.take(); + let value = root.as_ref().unwrap().borrow().val; + + if value >= max { + 1 + Self::f(value, left) + Self::f(value, right) + } else { + Self::f(max, left) + Self::f(max, right) + } + } +} From bab3f543a8aedd9ae09eac1e7f183d7cd391332a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 31 Aug 2023 23:02:39 +0800 Subject: [PATCH 0960/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eee5915a..a9212941 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 524 | 217 | 281 | 26 | +| 525 | 217 | 282 | 26 | ### 题目 @@ -358,6 +358,7 @@ |1512 | 设计地铁系统 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-underground-system.rs) | [leetcode](https://leetcode-cn.com/problems/design-underground-system/) | Medium | |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | |1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | +|1544 | 统计二叉树中好节点的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-nodes-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-nodes-in-binary-tree/) | Medium | |1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | |1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | |1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Medium | From ca5f593bd10dae6ad29bd67629d280bd3e4c7cee Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 1 Sep 2023 21:41:24 +0800 Subject: [PATCH 0961/1556] src/bin/number-of-ways-to-buy-pens-and-pencils.rs --- .../number-of-ways-to-buy-pens-and-pencils.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/number-of-ways-to-buy-pens-and-pencils.rs diff --git a/src/bin/number-of-ways-to-buy-pens-and-pencils.rs b/src/bin/number-of-ways-to-buy-pens-and-pencils.rs new file mode 100644 index 00000000..58e160ed --- /dev/null +++ b/src/bin/number-of-ways-to-buy-pens-and-pencils.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn ways_to_buy_pens_pencils(total: i32, cost1: i32, cost2: i32) -> i64 { + let (max, min) = if cost1 > cost2 { + (cost1 as i64, cost2 as i64) + } else { + (cost2 as i64, cost1 as i64) + }; + + let mut r = 0; + let mut i = 0; + + while i * max <= total as i64 { + r += (total as i64 - max * i) / min + 1; + i += 1; + } + + r + } +} From 50cefa721a03ba99c75d2ed9fef541210856daa0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 1 Sep 2023 21:41:25 +0800 Subject: [PATCH 0962/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a9212941..361e27af 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 525 | 217 | 282 | 26 | +| 526 | 217 | 283 | 26 | ### 题目 @@ -390,6 +390,7 @@ |2310 | 将数组和减半的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-halve-array-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-halve-array-sum/) | Medium | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |2346 | 字符串中最大的 3 位相同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-3-same-digit-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-3-same-digit-number-in-string/) | Easy | +|2351 | 买钢笔和铅笔的方案数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-ways-to-buy-pens-and-pencils.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-ways-to-buy-pens-and-pencils/) | Medium | |2384 | 判断根结点是否等于子结点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/root-equals-sum-of-children.rs) | [leetcode](https://leetcode-cn.com/problems/root-equals-sum-of-children/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | From 20408767782aee5cd3055e12c397e8faa27900a7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 2 Sep 2023 11:33:18 +0800 Subject: [PATCH 0963/1556] src/bin/maximum-enemy-forts-that-can-be-captured.rs --- ...aximum-enemy-forts-that-can-be-captured.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/maximum-enemy-forts-that-can-be-captured.rs diff --git a/src/bin/maximum-enemy-forts-that-can-be-captured.rs b/src/bin/maximum-enemy-forts-that-can-be-captured.rs new file mode 100644 index 00000000..bf78ae33 --- /dev/null +++ b/src/bin/maximum-enemy-forts-that-can-be-captured.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn capture_forts(forts: Vec) -> i32 { + let mut r = 0; + let mut x = 0; + let mut m = forts[0]; + for i in 1..forts.len() { + if forts[i] == 0 { + if m != 0 { + x += 1; + } + } else { + if m != forts[i] { + r = r.max(x); + } + x = 0; + m = forts[i]; + } + } + + r + } +} From ed67a3bb88f4b01eebf28d6b7490ef52d16e3d68 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 2 Sep 2023 11:33:19 +0800 Subject: [PATCH 0964/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 361e27af..530a900f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 526 | 217 | 283 | 26 | +| 527 | 218 | 283 | 26 | ### 题目 @@ -402,6 +402,7 @@ |2580 | 回环句 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circular-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/circular-sentence/) | Easy | |2585 | 删除每行中的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-greatest-value-in-each-row.rs) | [leetcode](https://leetcode-cn.com/problems/delete-greatest-value-in-each-row/) | Easy | |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | +|2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | From 733c5db1a751eb43ace8680838cfe66684d37268 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 3 Sep 2023 11:20:08 +0800 Subject: [PATCH 0965/1556] src/bin/eliminate-maximum-number-of-monsters.rs --- .../eliminate-maximum-number-of-monsters.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/eliminate-maximum-number-of-monsters.rs diff --git a/src/bin/eliminate-maximum-number-of-monsters.rs b/src/bin/eliminate-maximum-number-of-monsters.rs new file mode 100644 index 00000000..2038564e --- /dev/null +++ b/src/bin/eliminate-maximum-number-of-monsters.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn eliminate_maximum(dist: Vec, speed: Vec) -> i32 { + let mut s: Vec<_> = dist + .into_iter() + .zip(speed) + .map(|(x, y)| if x % y == 0 { x / y } else { x / y + 1 }) + .collect(); + + s.sort(); + + let mut r = 1; + + for i in 0..s.len() - 1 { + if i as i32 + 1 >= s[i] && s[i] == s[i + 1] { + break; + } + + r += 1; + } + + r + } +} From 06718ebad39c5df1ed52297f3c5047ad89994488 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 3 Sep 2023 11:20:09 +0800 Subject: [PATCH 0966/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 530a900f..971fe92b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 527 | 218 | 283 | 26 | +| 528 | 218 | 284 | 26 | ### 题目 @@ -381,6 +381,7 @@ |1971 | 增长的内存泄露 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/incremental-memory-leak.rs) | [leetcode](https://leetcode-cn.com/problems/incremental-memory-leak/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2022 | 最大子序列交替和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-alternating-subsequence-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-alternating-subsequence-sum/) | Medium | +|2049 | 消灭怪物的最大数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/eliminate-maximum-number-of-monsters.rs) | [leetcode](https://leetcode-cn.com/problems/eliminate-maximum-number-of-monsters/) | Medium | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | From df356674d5ccc6555d2077acf9d804c398547dbd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 4 Sep 2023 21:41:55 +0800 Subject: [PATCH 0967/1556] src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs --- ...ximum-value-at-a-given-index-in-a-bounded-array.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs diff --git a/src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs b/src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs new file mode 100644 index 00000000..e0aecfda --- /dev/null +++ b/src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs @@ -0,0 +1,11 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_value(n: i32, index: i32, max_sum: i32) -> i32 { + (2 * max_sum - (n - index).pow(2) + n * index) / (4 - 2 * index) + } +} From 11a88d24d0a80d4aa48cd902b93434c423fbace7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 4 Sep 2023 21:41:55 +0800 Subject: [PATCH 0968/1556] src/bin/unique-number-of-occurrences.rs --- src/bin/unique-number-of-occurrences.rs | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/unique-number-of-occurrences.rs diff --git a/src/bin/unique-number-of-occurrences.rs b/src/bin/unique-number-of-occurrences.rs new file mode 100644 index 00000000..5f1c107b --- /dev/null +++ b/src/bin/unique-number-of-occurrences.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn unique_occurrences(arr: Vec) -> bool { + let mut s: std::collections::HashMap = Default::default(); + + for i in arr { + s.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + + let mut s1 = std::collections::HashSet::new(); + + for (_, v) in s.into_iter() { + if s1.contains(&v) { + return false; + } + + s1.insert(v); + } + + true + } +} From d5bea2063b5515ee1e3d1a4ce8cc8a31a57f9914 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 4 Sep 2023 21:41:56 +0800 Subject: [PATCH 0969/1556] README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 971fe92b..5ba4e39c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 528 | 218 | 284 | 26 | +| 530 | 219 | 285 | 26 | ### 题目 @@ -332,6 +332,7 @@ |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | |1293 | 存在连续三个奇数的数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/three-consecutive-odds.rs) | [leetcode](https://leetcode-cn.com/problems/three-consecutive-odds/) | Easy | |1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | +|1319 | 独一无二的出现次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-number-of-occurrences.rs) | [leetcode](https://leetcode-cn.com/problems/unique-number-of-occurrences/) | Easy | |1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | |1329 | 玩筹码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cost-to-move-chips-to-the-same-position.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position/) | Easy | |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | @@ -376,6 +377,7 @@ |1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | |1849 | 任意子数组和的绝对值的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-absolute-sum-of-any-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | |1894 | 交替合并字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-strings-alternately.rs) | [leetcode](https://leetcode-cn.com/problems/merge-strings-alternately/) | Easy | +|1929 | 有界数组中指定下标处的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-at-a-given-index-in-a-bounded-array/) | Medium | |1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | |1952 | 最少侧跳次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sideway-jumps.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sideway-jumps/) | Medium | |1971 | 增长的内存泄露 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/incremental-memory-leak.rs) | [leetcode](https://leetcode-cn.com/problems/incremental-memory-leak/) | Medium | From aad7b9ebd9d45225a66ee881c66c9c2200af89f8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 5 Sep 2023 20:27:07 +0800 Subject: [PATCH 0970/1556] src/bin/form-smallest-number-from-two-digit-arrays.rs --- ...m-smallest-number-from-two-digit-arrays.rs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/bin/form-smallest-number-from-two-digit-arrays.rs diff --git a/src/bin/form-smallest-number-from-two-digit-arrays.rs b/src/bin/form-smallest-number-from-two-digit-arrays.rs new file mode 100644 index 00000000..9126b9ad --- /dev/null +++ b/src/bin/form-smallest-number-from-two-digit-arrays.rs @@ -0,0 +1,44 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_number(nums1: Vec, nums2: Vec) -> i32 { + let mut r = i32::MAX; + + for i in 0..nums1.len() { + for j in 0..nums2.len() { + if nums1[i] == nums2[j] { + r = r.min(nums1[i]); + } else if nums1[i] < nums2[j] { + r = r.min(nums1[i] * 10 + nums2[j]); + } else { + r = r.min(nums1[i] + nums2[j] * 10); + } + } + } + + r + } + + pub fn min_number1(nums1: Vec, nums2: Vec) -> i32 { + let (mut x, mut y) = (0i32, 0i32); + + for i in nums1 { + x |= 1 << i; + } + + for i in nums2 { + y |= 1 << i; + } + + if x & y != 0 { + (x & y).trailing_zeros() as i32 + } else { + (x.trailing_ones() * 10 + y.trailing_ones()) + .min(y.trailing_ones() * 10 + x.trailing_ones()) as i32 + } + } +} From fa540842394772109812ca0808257632eabcb9f5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 5 Sep 2023 20:27:08 +0800 Subject: [PATCH 0971/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ba4e39c..fc19c534 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 530 | 219 | 285 | 26 | +| 531 | 220 | 285 | 26 | ### 题目 @@ -407,6 +407,7 @@ |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | |2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | +|2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | |2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | From ffcd3d442bdef0516f5a3a2608bb7651a8ce575d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 5 Sep 2023 21:15:02 +0800 Subject: [PATCH 0972/1556] src/bin/form-smallest-number-from-two-digit-arrays.rs --- src/bin/form-smallest-number-from-two-digit-arrays.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/form-smallest-number-from-two-digit-arrays.rs b/src/bin/form-smallest-number-from-two-digit-arrays.rs index 9126b9ad..ddfd5641 100644 --- a/src/bin/form-smallest-number-from-two-digit-arrays.rs +++ b/src/bin/form-smallest-number-from-two-digit-arrays.rs @@ -37,8 +37,8 @@ impl Solution { if x & y != 0 { (x & y).trailing_zeros() as i32 } else { - (x.trailing_ones() * 10 + y.trailing_ones()) - .min(y.trailing_ones() * 10 + x.trailing_ones()) as i32 + (x.trailing_zeros() * 10 + y.trailing_zeros()) + .min(y.trailing_zeros() * 10 + x.trailing_zeros()) as i32 } } } From 140c7466cd6ea322c04fdfbccddc5cc9a71dd3b3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 5 Sep 2023 21:15:02 +0800 Subject: [PATCH 0973/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc19c534..8b1a21d7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 531 | 220 | 285 | 26 | +| 532 | 221 | 285 | 26 | ### 题目 @@ -408,6 +408,7 @@ |2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | +|2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | |2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | From f997ff77878872146167a96ab885cb5fde52ecf6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 6 Sep 2023 21:23:43 +0800 Subject: [PATCH 0974/1556] src/bin/lowest-common-ancestor-of-deepest-leaves.rs --- ...owest-common-ancestor-of-deepest-leaves.rs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/bin/lowest-common-ancestor-of-deepest-leaves.rs diff --git a/src/bin/lowest-common-ancestor-of-deepest-leaves.rs b/src/bin/lowest-common-ancestor-of-deepest-leaves.rs new file mode 100644 index 00000000..50ea2fe7 --- /dev/null +++ b/src/bin/lowest-common-ancestor-of-deepest-leaves.rs @@ -0,0 +1,50 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn lca_deepest_leaves( + root: Option>>, + ) -> Option>> { + let (s, _) = Self::f(root); + s + } + + pub fn f(r: Option>>) -> (Option>>, i32) { + if r.is_none() { + return (r, 0); + } + let (s1, h1) = Self::f(r.as_ref().unwrap().borrow().left.clone()); + let (s2, h2) = Self::f(r.as_ref().unwrap().borrow().right.clone()); + + if h1 == h2 { + (r, h1 + 1) + } else if h1 < h2 { + (s2, h2 + 1) + } else { + (s1, h1 + 1) + } + } +} From ee9b1e6e190075da5617226332922dd5cd583b7b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 6 Sep 2023 21:23:44 +0800 Subject: [PATCH 0975/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b1a21d7..914657b5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 532 | 221 | 285 | 26 | +| 533 | 221 | 286 | 26 | ### 题目 @@ -325,6 +325,7 @@ |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | |1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | +|1218 | 最深叶节点的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-deepest-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves/) | Medium | |1236 | 第 N 个泰波那契数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-th-tribonacci-number.rs) | [leetcode](https://leetcode-cn.com/problems/n-th-tribonacci-number/) | Easy | |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | |1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | From c1274c4051fabe4d9ce33b9c5e450e13462ae544 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 8 Sep 2023 21:58:25 +0800 Subject: [PATCH 0976/1556] src/bin/calculate-delayed-arrival-time.rs --- src/bin/calculate-delayed-arrival-time.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/bin/calculate-delayed-arrival-time.rs diff --git a/src/bin/calculate-delayed-arrival-time.rs b/src/bin/calculate-delayed-arrival-time.rs new file mode 100644 index 00000000..611b2e5f --- /dev/null +++ b/src/bin/calculate-delayed-arrival-time.rs @@ -0,0 +1,11 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_delayed_arrival_time(arrival_time: i32, delayed_time: i32) -> i32 { + (arrival_time + delayed_time) % 24 + } +} From 35c6842a10105a373a1dda51970c8f7875466af1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 8 Sep 2023 21:58:27 +0800 Subject: [PATCH 0977/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 914657b5..dd0866f1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 533 | 221 | 286 | 26 | +| 534 | 222 | 286 | 26 | ### 题目 @@ -414,6 +414,7 @@ |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | +|2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | From 29a190709e00ee73b13e66d1eedb1c3e86851d46 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 9 Sep 2023 09:20:52 +0800 Subject: [PATCH 0978/1556] src/bin/find-the-maximum-divisibility-score.rs --- .../find-the-maximum-divisibility-score.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/find-the-maximum-divisibility-score.rs diff --git a/src/bin/find-the-maximum-divisibility-score.rs b/src/bin/find-the-maximum-divisibility-score.rs new file mode 100644 index 00000000..7f7e4211 --- /dev/null +++ b/src/bin/find-the-maximum-divisibility-score.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_div_score(nums: Vec, divisors: Vec) -> i32 { + let mut r = i32::MAX; + let mut max = 0; + for i in divisors { + let mut n = 0; + for &j in nums.iter() { + if j % i == 0 { + n += 1; + } + } + + if n > max { + r = i as i32; + max = n; + } else if n == max { + r = r.min(i as i32); + } + } + + r + } +} From 0c2ae3f008b46702c93efed921adae24d9fa460f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 9 Sep 2023 09:20:53 +0800 Subject: [PATCH 0979/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dd0866f1..5d08fd8f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 534 | 222 | 286 | 26 | +| 535 | 223 | 286 | 26 | ### 题目 @@ -412,6 +412,7 @@ |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | |2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | +|2694 | 找出可整除性得分最大的整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-divisibility-score.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-divisibility-score/) | Easy | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | |2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | From bb4d3a23519953d4468c8b2eda9d4a6ec50cd3ee Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Sep 2023 21:50:19 +0800 Subject: [PATCH 0980/1556] src/bin/IDBivT.rs --- src/bin/IDBivT.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/IDBivT.rs diff --git a/src/bin/IDBivT.rs b/src/bin/IDBivT.rs new file mode 100644 index 00000000..69b47e7d --- /dev/null +++ b/src/bin/IDBivT.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn generate_parenthesis(n: i32) -> Vec { + if n == 1 { + return vec!["()".to_string()]; + } else if n == 0 { + return vec!["".to_string()]; + } + let mut ans = vec![]; + for i in 0..n { + let mut mid = vec![]; + for sub_string1 in Self::generate_parenthesis(i) { + mid.push(format!("({sub_string1})")); + } + for m in mid { + for sub_string2 in Self::generate_parenthesis(n - 1 - i) { + ans.push(format!("{m}{sub_string2}")); + } + } + } + ans + } +} From c7acee96a320b8aefffa087551a0ebe3c2e3cd68 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Sep 2023 21:50:19 +0800 Subject: [PATCH 0981/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d08fd8f..3b535d3b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 535 | 223 | 286 | 26 | +| 536 | 223 | 287 | 26 | ### 题目 @@ -506,6 +506,7 @@ |1000233 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WGki4K.rs) | [leetcode](https://leetcode-cn.com/problems/WGki4K/) | Medium | |1000236 | 单词长度的最大乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aseY1I.rs) | [leetcode](https://leetcode-cn.com/problems/aseY1I/) | Medium | |1000237 | 排序数组中两个数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kLl5u1.rs) | [leetcode](https://leetcode-cn.com/problems/kLl5u1/) | Easy | +|1000238 | 括号生成 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/IDBivT.rs) | [leetcode](https://leetcode-cn.com/problems/IDBivT/) | Medium | |1000242 | 和大于等于 target 的最短子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2VG8Kg.rs) | [leetcode](https://leetcode-cn.com/problems/2VG8Kg/) | Medium | |1000244 | 乘积小于 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ZVAVXX.rs) | [leetcode](https://leetcode-cn.com/problems/ZVAVXX/) | Medium | |1000246 | 和为 k 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/QTMn0o.rs) | [leetcode](https://leetcode-cn.com/problems/QTMn0o/) | Medium | From 449816dcb6589326ce137d130831a0fd99eeaa7b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 12 Sep 2023 20:19:09 +0800 Subject: [PATCH 0982/1556] src/bin/number-of-substrings-with-only-1s.rs --- src/bin/number-of-substrings-with-only-1s.rs | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/bin/number-of-substrings-with-only-1s.rs diff --git a/src/bin/number-of-substrings-with-only-1s.rs b/src/bin/number-of-substrings-with-only-1s.rs new file mode 100644 index 00000000..801702c5 --- /dev/null +++ b/src/bin/number-of-substrings-with-only-1s.rs @@ -0,0 +1,26 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn num_sub(s: String) -> i32 { + let mut n = 0i64; + let mut r = 0i64; + for &i in s.as_bytes() { + match i { + b'0' => { + r += (1 + n) * n / 2 % (1000000000 + 7); + n = 0; + } + b'1' => n += 1, + _ => unreachable!(), + } + } + + r += (1 + n) * n / 2 % (1000000000 + 7); + + r as i32 + } +} From 8ee360d9b0724cdc0b1875f788058f7dad370814 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 12 Sep 2023 20:19:10 +0800 Subject: [PATCH 0983/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b535d3b..651121cf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 536 | 223 | 287 | 26 | +| 537 | 223 | 288 | 26 | ### 题目 @@ -367,6 +367,7 @@ |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | |1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | |1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | +|1636 | 仅含 1 的子串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-substrings-with-only-1s.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-substrings-with-only-1s/) | Medium | |1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | Easy | |1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | Easy | |1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | From bcbf8666033c695e48e82cbb4d6c48b2432307c4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 13 Sep 2023 21:03:15 +0800 Subject: [PATCH 0984/1556] src/bin/check-knight-tour-configuration.rs --- src/bin/check-knight-tour-configuration.rs | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/bin/check-knight-tour-configuration.rs diff --git a/src/bin/check-knight-tour-configuration.rs b/src/bin/check-knight-tour-configuration.rs new file mode 100644 index 00000000..f2c3a7b3 --- /dev/null +++ b/src/bin/check-knight-tour-configuration.rs @@ -0,0 +1,87 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn check_valid_grid(grid: Vec>) -> bool { + if grid[0][0] != 0 { + return false; + } + + let (mut x, mut y) = (0, 0); + let mut result = false; + for i in 1..grid.len() * grid.len() { + let (r1, x1, y1) = Self::check(&grid[..], x, y, i as i32); + if !r1 { + return false; + } + + x = x1; + y = y1; + } + + true + } + + pub fn check(grid: &[Vec], x: usize, y: usize, expect: i32) -> (bool, usize, usize) { + if x > 1 { + if y > 0 { + if grid[x - 2][y - 1] == expect { + return (true, x - 2, y - 1); + } + } + + if y < grid.len() - 1 { + if grid[x - 2][y + 1] == expect { + return (true, x - 2, y + 1); + } + } + } + + if x < grid.len() - 2 { + if y > 0 { + if grid[x + 2][y - 1] == expect { + return (true, x + 2, y - 1); + } + } + + if y < grid.len() - 1 { + if grid[x + 2][y + 1] == expect { + return (true, x + 2, y + 1); + } + } + } + + if y > 1 { + if x > 0 { + if grid[x - 1][y - 2] == expect { + return (true, x - 1, y - 2); + } + } + + if x < grid.len() - 1 { + if grid[x + 1][y - 2] == expect { + return (true, x + 1, y - 2); + } + } + } + + if y < grid.len() - 2 { + if x > 0 { + if grid[x - 1][y + 2] == expect { + return (true, x - 1, y + 2); + } + } + + if x < grid.len() - 1 { + if grid[x + 1][y + 2] == expect { + return (true, x + 1, y + 2); + } + } + } + + (false, 0, 0) + } +} From 7d03bd7b844eb23ca87e7a299702ef7cebe63598 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 13 Sep 2023 21:03:16 +0800 Subject: [PATCH 0985/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 651121cf..1ee9fc1b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 537 | 223 | 288 | 26 | +| 538 | 223 | 289 | 26 | ### 题目 @@ -409,6 +409,7 @@ |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | |2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | +|2662 | 检查骑士巡视方案 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-knight-tour-configuration.rs) | [leetcode](https://leetcode-cn.com/problems/check-knight-tour-configuration/) | Medium | |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | |2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | From f7568fac75c689187ba8358314e7a130cd5fadab Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 14 Sep 2023 20:14:02 +0800 Subject: [PATCH 0986/1556] format ode --- sort/src/quick.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sort/src/quick.rs b/sort/src/quick.rs index 9f0e9081..0ee0e711 100644 --- a/sort/src/quick.rs +++ b/sort/src/quick.rs @@ -1,13 +1,13 @@ /// 原地排序的快速排序实现 /// 步骤: -/// 1.指定一个基准值p(p为s[begin]), begin为0,end为len(s)-1 -/// 2.首先从后往前遍历,如果遍历的元素大于基准值,则继续往前遍历, end = end-1 -/// 3.如果从后往前遍历时的值小于基准值,begin的值赋值为s[end], begin = begin + 1 -/// 4.然后从前往后遍历,遍历值小于或者等于基准值时,继续向后遍历,begin = begin + 1 -/// 5.当遍历值大于或者等于基准值时,s[end] = s[begin] -/// 6.再次重复2-5步,直到begin == end为止 -/// 7.最后s[begin] = p -/// 8.递归快速排序以begin为分界线的两部分序列 +/// 1.指定一个基准值p(p为s[begin]), begin为0,end为len(s)-1 +/// 2.首先从后往前遍历,如果遍历的元素大于基准值,则继续往前遍历, end = end-1 +/// 3.如果从后往前遍历时的值小于基准值,begin的值赋值为s[end], begin = begin + 1 +/// 4.然后从前往后遍历,遍历值小于或者等于基准值时,继续向后遍历,begin = begin + 1 +/// 5.当遍历值大于或者等于基准值时,s[end] = s[begin] +/// 6.再次重复2-5步,直到begin == end为止 +/// 7.最后s[begin] = p +/// 8.递归快速排序以begin为分界线的两部分序列 pub fn sort(target: &mut [T]) { if target.len() < 2 { return; @@ -32,7 +32,7 @@ pub fn sort(target: &mut [T]) { std::cmp::Ordering::Less => { target[end] = target[begin].clone(); end -= 1; - break; + break; } _ => begin += 1, } From 12649e80ef36e70ab7a59c4642f7bf2ad6912ba3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 14 Sep 2023 21:00:22 +0800 Subject: [PATCH 0987/1556] src/bin/queens-that-can-attack-the-king.rs --- src/bin/queens-that-can-attack-the-king.rs | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/bin/queens-that-can-attack-the-king.rs diff --git a/src/bin/queens-that-can-attack-the-king.rs b/src/bin/queens-that-can-attack-the-king.rs new file mode 100644 index 00000000..a9c92153 --- /dev/null +++ b/src/bin/queens-that-can-attack-the-king.rs @@ -0,0 +1,100 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::collections::HashSet; + +use serde::de::Unexpected::Option; +use tera::Filter; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn queens_attackthe_king(queens: Vec>, king: Vec) -> Vec> { + use std::collections::HashSet; + let hash: HashSet<_> = queens.into_iter().collect(); + + // 枚举8个方向,遇到的第一个就行 + let mut result = vec![]; + let mut s = king[0]; + while s >= 1 { + if hash.contains(&vec![s - 1, king[1]]) { + result.push(vec![s - 1, king[1]]); + break; + } + s -= 1; + } + + let mut s = king[0]; + while s <= 6 { + if hash.contains(&vec![s + 1, king[1]]) { + result.push(vec![s + 1, king[1]]); + break; + } + s += 1; + } + + + let mut s = king[1]; + while s >= 1 { + if hash.contains(&vec![king[0], s - 1]) { + result.push(vec![king[0], s - 1]); + break; + } + s -= 1; + } + + let mut s = king[1]; + while s <= 6 { + if hash.contains(&vec![king[0], s + 1]) { + result.push(vec![king[0], s + 1]); + break; + } + s += 1; + } + + let (mut s1, mut s2) = (king[0], king[1]); + while s1 >= 1 && s2 >= 1 { + if hash.contains(&vec![s1 - 1, s2 - 1]) { + result.push(vec![s1 - 1, s2 - 1]); + break; + } + s1 -= 1; + s2 -= 1; + } + + + let (mut s1, mut s2) = (king[0], king[1]); + while s1 <= 6 && s2 <= 6 { + if hash.contains(&vec![s1 + 1, s2 + 1]) { + result.push(vec![s1 + 1, s2 + 1]); + break; + } + s1 += 1; + s2 += 1; + } + + let (mut s1, mut s2) = (king[0], king[1]); + while s1 >= 0 && s2 <= 6 { + if hash.contains(&vec![s1 - 1, s2 + 1]) { + result.push(vec![s1 - 1, s2 + 1]); + break; + } + s1 -= 1; + s2 += 1; + } + + + let (mut s1, mut s2) = (king[0], king[1]); + while s1 <= 6 && s2 >= 0 { + if hash.contains(&vec![s1 + 1, s2 - 1]) { + result.push(vec![s1 + 1, s2 - 1]); + break; + } + s1 += 1; + s2 -= 1; + } + + result + } +} From 025267f9cd16792974130bc8a1c949ecd61493b0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 14 Sep 2023 21:00:22 +0800 Subject: [PATCH 0988/1556] README.md --- README.md | 3 ++- src/http.rs | 58 ++++++++++++++++++++++++++--------------------------- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 1ee9fc1b..2d888936 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 538 | 223 | 289 | 26 | +| 539 | 223 | 290 | 26 | ### 题目 @@ -337,6 +337,7 @@ |1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | |1329 | 玩筹码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cost-to-move-chips-to-the-same-position.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position/) | Easy | |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | +|1342 | 可以攻击国王的皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/queens-that-can-attack-the-king.rs) | [leetcode](https://leetcode-cn.com/problems/queens-that-can-attack-the-king/) | Medium | |1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | |1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | |1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | diff --git a/src/http.rs b/src/http.rs index 06184190..f7aaa113 100644 --- a/src/http.rs +++ b/src/http.rs @@ -1,10 +1,10 @@ +use std::fmt; + use lazy_static::lazy_static; use regex::Regex; use reqwest::blocking::Client; -use serde::de::{Error, Visitor}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; - -use std::fmt; +use serde::de::{Error, Visitor}; lazy_static! { static ref RE: Regex = Regex::new(r".*?/problems/(.*?)/").unwrap(); @@ -32,8 +32,8 @@ impl Difficulty { impl Serialize for Difficulty { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, + where + S: Serializer, { match self { Self::Easy => serializer.serialize_str("Easy"), @@ -43,33 +43,33 @@ impl Serialize for Difficulty { } } -struct DifficultyVisitor; - -impl<'de> Visitor<'de> for DifficultyVisitor { - type Value = Difficulty; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - write!(formatter, "") - } - - fn visit_str(self, v: &str) -> Result - where - E: Error, - { - match v { - "Easy" => Ok(Self::Value::Easy), - "Medium" => Ok(Self::Value::Medium), - "Hard" => Ok(Self::Value::Hard), - _ => Err(Error::unknown_variant(v, &["Easy", "Medium", "Hard"])), - } - } -} - impl<'de> Deserialize<'de> for Difficulty { fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, + where + D: Deserializer<'de>, { + struct DifficultyVisitor; + + impl<'de> Visitor<'de> for DifficultyVisitor { + type Value = Difficulty; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + write!(formatter, "") + } + + fn visit_str(self, v: &str) -> Result + where + E: Error, + { + match v { + "Easy" => Ok(Self::Value::Easy), + "Medium" => Ok(Self::Value::Medium), + "Hard" => Ok(Self::Value::Hard), + _ => Err(Error::unknown_variant(v, &["Easy", "Medium", "Hard"])), + } + } + } + deserializer.deserialize_str(DifficultyVisitor) } } From d399e88e6dfe9babb90889cae57192ce54314427 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 16 Sep 2023 10:49:29 +0800 Subject: [PATCH 0989/1556] src/bin/number-of-smooth-descent-periods-of-a-stock.rs --- ...er-of-smooth-descent-periods-of-a-stock.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/number-of-smooth-descent-periods-of-a-stock.rs diff --git a/src/bin/number-of-smooth-descent-periods-of-a-stock.rs b/src/bin/number-of-smooth-descent-periods-of-a-stock.rs new file mode 100644 index 00000000..2844d5b0 --- /dev/null +++ b/src/bin/number-of-smooth-descent-periods-of-a-stock.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn get_descent_periods(prices: Vec) -> i64 { + let mut r = 0; + let mut current = prices[0]; + let mut current_num = 1; + + for i in 1..prices.len() { + if current - 1 == prices[i] { + current_num += 1; + } else { + r += (current_num + 1) * current_num / 2; + current_num = 1; + } + current = prices[i]; + } + r += (current_num + 1) * current_num / 2; + r + } +} From e6982662522fad9b242371ff77f62f7e7d845799 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 16 Sep 2023 10:49:29 +0800 Subject: [PATCH 0990/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d888936..a07c9489 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 539 | 223 | 290 | 26 | +| 540 | 223 | 291 | 26 | ### 题目 @@ -390,6 +390,7 @@ |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | +|2233 | 股票平滑下跌阶段的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-smooth-descent-periods-of-a-stock.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-smooth-descent-periods-of-a-stock/) | Medium | |2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | From 829eb0d2b453a06fe34e72a40e323ae27d78b66c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 17 Sep 2023 10:18:24 +0800 Subject: [PATCH 0991/1556] src/bin/remove-duplicate-node-lcci.rs --- src/bin/remove-duplicate-node-lcci.rs | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/bin/remove-duplicate-node-lcci.rs diff --git a/src/bin/remove-duplicate-node-lcci.rs b/src/bin/remove-duplicate-node-lcci.rs new file mode 100644 index 00000000..b79efa66 --- /dev/null +++ b/src/bin/remove-duplicate-node-lcci.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} + +impl Solution { + pub fn remove_duplicate_nodes(mut head: Option>) -> Option> { + let mut set: std::collections::HashSet = Default::default(); + let mut tmp = Some(Box::new(ListNode { next: None, val: 0 })); + let mut current = &mut tmp.as_mut().unwrap().next; + while head.is_some() { + let mut h = head.unwrap(); + let next = h.next.take(); + let v = h.val; + if !set.contains(&v) { + current.insert(h); + current = &mut current.as_mut().unwrap().next; + set.insert(v); + } + + head = next; + } + + tmp.unwrap().next.take() + } +} From b63faf57e2a4312e03d5c8a3a2954341ce78078d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 17 Sep 2023 10:18:25 +0800 Subject: [PATCH 0992/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a07c9489..596972e6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 540 | 223 | 291 | 26 | +| 541 | 224 | 291 | 26 | ### 题目 @@ -424,6 +424,7 @@ |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | +|100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | From 920f581d2bb1d7d5654117ee873a8bec4b418295 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 18 Sep 2023 20:42:43 +0800 Subject: [PATCH 0993/1556] src/bin/count-distinct-numbers-on-board.rs --- src/bin/count-distinct-numbers-on-board.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/bin/count-distinct-numbers-on-board.rs diff --git a/src/bin/count-distinct-numbers-on-board.rs b/src/bin/count-distinct-numbers-on-board.rs new file mode 100644 index 00000000..708a43ac --- /dev/null +++ b/src/bin/count-distinct-numbers-on-board.rs @@ -0,0 +1,15 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn distinct_integers(n: i32) -> i32 { + if n > 1 { + n - 1 + } else { + 1 + } + } +} From 3fb98b86b816a6777ec65a54195858533105a442 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 18 Sep 2023 20:42:44 +0800 Subject: [PATCH 0994/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 596972e6..eeae65a1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 541 | 224 | 291 | 26 | +| 542 | 225 | 291 | 26 | ### 题目 @@ -415,6 +415,7 @@ |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | |2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | +|2679 | 统计桌面上的不同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-distinct-numbers-on-board.rs) | [leetcode](https://leetcode-cn.com/problems/count-distinct-numbers-on-board/) | Easy | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | |2694 | 找出可整除性得分最大的整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-divisibility-score.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-divisibility-score/) | Easy | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | From b1b34c522611f49773cf4ece3fce2e71fcbde162 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 19 Sep 2023 21:30:11 +0800 Subject: [PATCH 0995/1556] src/bin/min-max-game.rs --- src/bin/min-max-game.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/min-max-game.rs diff --git a/src/bin/min-max-game.rs b/src/bin/min-max-game.rs new file mode 100644 index 00000000..01ac77fb --- /dev/null +++ b/src/bin/min-max-game.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_max_game(mut nums: Vec) -> i32 { + while nums.len() != 1 { + let mut new_nums = Vec::with_capacity(nums.len() / 2); + for i in 0..nums.len() / 2 { + if i % 2 == 0 { + new_nums.push(nums[2 * i].min(nums[2 * i + 1])); + } else { + new_nums.push(nums[2 * i].max(nums[2 * i + 1])); + } + } + + nums = new_nums; + } + nums[0] + } +} From 7b92c190911112d91049c01af39cba941e5ca8a4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 19 Sep 2023 21:30:11 +0800 Subject: [PATCH 0996/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eeae65a1..d849b9b3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 542 | 225 | 291 | 26 | +| 543 | 226 | 291 | 26 | ### 题目 @@ -399,6 +399,7 @@ |2346 | 字符串中最大的 3 位相同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-3-same-digit-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-3-same-digit-number-in-string/) | Easy | |2351 | 买钢笔和铅笔的方案数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-ways-to-buy-pens-and-pencils.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-ways-to-buy-pens-and-pencils/) | Medium | |2384 | 判断根结点是否等于子结点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/root-equals-sum-of-children.rs) | [leetcode](https://leetcode-cn.com/problems/root-equals-sum-of-children/) | Easy | +|2386 | 极大极小游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-max-game.rs) | [leetcode](https://leetcode-cn.com/problems/min-max-game/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | |2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | From 1e8e50c45ea87e66473edae7bf7b2c010cda73b8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 20 Sep 2023 20:29:19 +0800 Subject: [PATCH 0997/1556] src/bin/delete-leaves-with-a-given-value.rs --- src/bin/delete-leaves-with-a-given-value.rs | 58 +++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/bin/delete-leaves-with-a-given-value.rs diff --git a/src/bin/delete-leaves-with-a-given-value.rs b/src/bin/delete-leaves-with-a-given-value.rs new file mode 100644 index 00000000..92ed445b --- /dev/null +++ b/src/bin/delete-leaves-with-a-given-value.rs @@ -0,0 +1,58 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +impl Solution { + pub fn remove_leaf_nodes( + root: Option>>, + target: i32, + ) -> Option>> { + if root.is_none() { + return None; + } + + let left = Self::remove_leaf_nodes( + root.as_ref() + .map_or_else(|| None, |x| x.borrow_mut().left.take()), + target, + ); + let right = Self::remove_leaf_nodes( + root.as_ref() + .map_or_else(|| None, |x| x.borrow_mut().right.take()), + target, + ); + + if left.is_none() && right.is_none() && root.as_ref().unwrap().borrow().val == target { + return None; + } + + root.as_ref().unwrap().borrow_mut().left = left; + root.as_ref().unwrap().borrow_mut().right = right; + + root + } +} From dd73d1be4f1a56aa641b5a8d40ee2111fe1da8ef Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 20 Sep 2023 20:29:20 +0800 Subject: [PATCH 0998/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d849b9b3..8aa6218b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 543 | 226 | 291 | 26 | +| 544 | 226 | 292 | 26 | ### 题目 @@ -352,6 +352,7 @@ |1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Medium | |1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | Easy | |1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | +|1450 | 删除给定值的叶子节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-leaves-with-a-given-value.rs) | [leetcode](https://leetcode-cn.com/problems/delete-leaves-with-a-given-value/) | Medium | |1455 | 餐厅过滤器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/filter-restaurants-by-vegan-friendly-price-and-distance.rs) | [leetcode](https://leetcode-cn.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance/) | Medium | |1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | |1472 | 上升下降字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increasing-decreasing-string.rs) | [leetcode](https://leetcode-cn.com/problems/increasing-decreasing-string/) | Easy | From 10de83cf6ea67e1797d19effcce657b13fd02d92 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 21 Sep 2023 20:51:01 +0800 Subject: [PATCH 0999/1556] src/bin/find-the-maximum-achievable-number.rs --- src/bin/find-the-maximum-achievable-number.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/bin/find-the-maximum-achievable-number.rs diff --git a/src/bin/find-the-maximum-achievable-number.rs b/src/bin/find-the-maximum-achievable-number.rs new file mode 100644 index 00000000..05442eda --- /dev/null +++ b/src/bin/find-the-maximum-achievable-number.rs @@ -0,0 +1,11 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn the_maximum_achievable_x(num: i32, t: i32) -> i32 { + num + t * 2 + } +} From a15435f2564db3e735b71264ea209d9cdcd67082 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 21 Sep 2023 20:51:01 +0800 Subject: [PATCH 1000/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8aa6218b..26e888c7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 544 | 226 | 292 | 26 | +| 545 | 227 | 292 | 26 | ### 题目 @@ -424,6 +424,7 @@ |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | |2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | +|2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | From 9156cc236bd5ca4fb3d5c4f0ba39d3f1c84d3a67 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 22 Sep 2023 21:05:50 +0800 Subject: [PATCH 1001/1556] src/bin/distribute-money-to-maximum-children.rs --- .../distribute-money-to-maximum-children.rs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/bin/distribute-money-to-maximum-children.rs diff --git a/src/bin/distribute-money-to-maximum-children.rs b/src/bin/distribute-money-to-maximum-children.rs new file mode 100644 index 00000000..59fa4a41 --- /dev/null +++ b/src/bin/distribute-money-to-maximum-children.rs @@ -0,0 +1,33 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn dist_money(money: i32, children: i32) -> i32 { + if money < children { + return -1; + } + let money = money - children; // 先给个孩子都分一块钱 + let s = children * 7; + + if s == money { + // 剩下的钱刚好每人7块 + children + } else if s < money { + // 剩下的钱大于每人7块,那有个孩子获得每人7块后余下的钱 + children - 1 + } else { + let mut cnt = children.min(money / 7); + let money = money - cnt * 7; + let children = children - cnt; + + if (children == 0 && money > 0) || (children == 1 && money == 3) { + cnt -= 1; + } + + cnt + } + } +} From 7627444d22f322e3e457ef6b27b8b34e4a57e51f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 22 Sep 2023 21:05:50 +0800 Subject: [PATCH 1002/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 26e888c7..d6f892dc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 545 | 227 | 292 | 26 | +| 546 | 228 | 292 | 26 | ### 题目 @@ -414,6 +414,7 @@ |2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2662 | 检查骑士巡视方案 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-knight-tour-configuration.rs) | [leetcode](https://leetcode-cn.com/problems/check-knight-tour-configuration/) | Medium | +|2663 | 将钱分给最多的儿童 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-money-to-maximum-children.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-money-to-maximum-children/) | Easy | |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | |2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | From 00250d5d32a410469d79b0e8b7d0fcdb663888e5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Sep 2023 22:09:27 +0800 Subject: [PATCH 1003/1556] src/bin/operations-on-tree.rs --- src/bin/operations-on-tree.rs | 107 ++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/bin/operations-on-tree.rs diff --git a/src/bin/operations-on-tree.rs b/src/bin/operations-on-tree.rs new file mode 100644 index 00000000..9db63991 --- /dev/null +++ b/src/bin/operations-on-tree.rs @@ -0,0 +1,107 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +struct LockingTree { + children: std::collections::HashMap>, + parents: std::collections::HashMap, + /// node: user_id + locked: std::collections::HashMap, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ + +/** + * Your LockingTree object will be instantiated and called as such: + * let obj = LockingTree::new(parent); + * let ret_1: bool = obj.lock(num, user); + * let ret_2: bool = obj.unlock(num, user); + * let ret_3: bool = obj.upgrade(num, user); + */ + +impl LockingTree { + fn new(parent: Vec) -> Self { + let mut children = std::collections::HashMap::>::new(); + let mut parents = std::collections::HashMap::new(); + for i in 0..parent.len() { + children + .entry(parent[i]) + .and_modify(|x| x.push(i as _)) + .or_insert(vec![i as _]); + + parents.insert(i as _, parent[i]); + } + + Self { + children, + parents, + locked: std::collections::HashMap::new(), + } + } + + fn lock(&mut self, num: i32, user: i32) -> bool { + if self.locked.contains_key(&num) { + return false; + } + + self.locked.insert(num, user); + true + } + + fn unlock(&mut self, num: i32, user: i32) -> bool { + match self.locked.get(&num) { + Some(&x) if x == user => {} + _ => return false, + } + + self.locked.remove(&num); + true + } + + fn upgrade(&mut self, num: i32, user: i32) -> bool { + if self.locked.contains_key(&num) { + return false; + } + + if self.check_parent(num) { + return false; + } + + if !self.unlock_sons(num) { + return false; + } + + self.locked.insert(num, user); + true + } + + /// 解锁子孙。如果有一个子孙已加锁,返回true。 + fn unlock_sons(&mut self, num: i32) -> bool { + let len = if let Some(x) = self.children.get(&num) { + x.len() + } else { + return false; + }; + + let mut result = false; + for i in 0..len { + result |= self.locked.remove(&self.children[&num][i]).is_some(); + result |= self.unlock_sons(self.children[&num][i]); + } + + result + } + + /// 检查父节点,如果都是未加锁,返回true + fn check_parent(&self, num: i32) -> bool { + match self.parents.get(&num) { + Some(&x) => self.locked.contains_key(&x) || self.check_parent(x), + None => false, + } + } +} From 92c6eb91df4afd4884abbe7f7ae8dc9fb9a30140 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Sep 2023 22:09:28 +0800 Subject: [PATCH 1004/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6f892dc..72e9998a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 546 | 228 | 292 | 26 | +| 547 | 228 | 293 | 26 | ### 题目 @@ -388,6 +388,7 @@ |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2022 | 最大子序列交替和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-alternating-subsequence-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-alternating-subsequence-sum/) | Medium | |2049 | 消灭怪物的最大数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/eliminate-maximum-number-of-monsters.rs) | [leetcode](https://leetcode-cn.com/problems/eliminate-maximum-number-of-monsters/) | Medium | +|2104 | 树上的操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/operations-on-tree.rs) | [leetcode](https://leetcode-cn.com/problems/operations-on-tree/) | Medium | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | From 0e83bad2ad5105cb49e373c1a31d413f023f9934 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 24 Sep 2023 10:54:26 +0800 Subject: [PATCH 1005/1556] src/bin/minimum-operations-to-make-the-array-increasing.rs --- ...operations-to-make-the-array-increasing.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/minimum-operations-to-make-the-array-increasing.rs diff --git a/src/bin/minimum-operations-to-make-the-array-increasing.rs b/src/bin/minimum-operations-to-make-the-array-increasing.rs new file mode 100644 index 00000000..fe71ae70 --- /dev/null +++ b/src/bin/minimum-operations-to-make-the-array-increasing.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_operations(mut nums: Vec) -> i32 { + let mut r = 0; + + for i in 1..nums.len() { + if nums[i] <= nums[i - 1] { + r += nums[i - 1] + 1 - nums[i]; + nums[i] = nums[i - 1] + 1; + } + } + + r + } +} From 7f93c4f52c66186473df835efc112b2b9ec85a89 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 24 Sep 2023 10:54:26 +0800 Subject: [PATCH 1006/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 72e9998a..edaa187e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 547 | 228 | 293 | 26 | +| 548 | 229 | 293 | 26 | ### 题目 @@ -382,6 +382,7 @@ |1849 | 任意子数组和的绝对值的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-absolute-sum-of-any-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | |1894 | 交替合并字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-strings-alternately.rs) | [leetcode](https://leetcode-cn.com/problems/merge-strings-alternately/) | Easy | |1929 | 有界数组中指定下标处的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-at-a-given-index-in-a-bounded-array/) | Medium | +|1938 | 最少操作使数组递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-make-the-array-increasing.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-increasing/) | Easy | |1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | |1952 | 最少侧跳次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sideway-jumps.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sideway-jumps/) | Medium | |1971 | 增长的内存泄露 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/incremental-memory-leak.rs) | [leetcode](https://leetcode-cn.com/problems/incremental-memory-leak/) | Medium | From fa4d7e5a9099962210adec5210fe2fa17dd72d71 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 25 Sep 2023 23:45:10 +0800 Subject: [PATCH 1007/1556] src/bin/lfu-cache.rs --- src/bin/lfu-cache.rs | 230 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 src/bin/lfu-cache.rs diff --git a/src/bin/lfu-cache.rs b/src/bin/lfu-cache.rs new file mode 100644 index 00000000..00939d11 --- /dev/null +++ b/src/bin/lfu-cache.rs @@ -0,0 +1,230 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +struct LinkList { + head: Option>>, + tail: Option>>, +} + +struct Node { + next: Option>>, + prev: Option>>, + key: i32, + val: i32, +} + +impl LinkList { + fn new() -> Self { + Self { + head: None, + tail: None, + } + } + + fn push_front(&mut self, key: i32, val: i32) -> std::rc::Rc> { + use std::cell::RefCell; + use std::rc::Rc; + + let node = Rc::new(RefCell::new(Node { + prev: None, + next: None, + key, + val, + })); + + if self.head.is_none() { + self.head = Some(Rc::clone(&node)); + self.tail = Some(Rc::clone(&node)); + } else { + let mut head = self.head.take(); + head.as_ref() + .map(|x| x.borrow_mut().prev = Some(Rc::downgrade(&node))); + node.borrow_mut().next = head.clone(); + self.head = Some(Rc::clone(&node)); + } + + node + } + + fn remove(&mut self, val: std::rc::Rc>) { + use std::cell::RefCell; + use std::rc::Rc; + + let prev = val.borrow_mut().prev.take().and_then(|x| x.upgrade()); + let next = val.borrow_mut().next.take(); + + prev.as_ref().map(|x| x.borrow_mut().next = None); + next.as_ref().map(|x| x.borrow_mut().prev = None); + + prev.as_ref().map(|x| x.borrow_mut().next = next.clone()); + next.as_ref() + .map(|x| x.borrow_mut().prev = prev.clone().map(|x| Rc::downgrade(&x))); + + // 移除节点的前继节点为空,说明此节点为头节点,移除next节点成为新的头部节点 + if prev.is_none() { + self.head = next.clone(); + } + + if next.is_none() { + self.tail = prev.clone(); + } + } + + fn is_empty(&self) -> bool { + self.head.is_none() + } + + fn pop(&mut self) -> Option { + let tail = self.tail.clone(); + if tail.is_none() { + return None; + } + self.remove(tail.clone().unwrap()); + tail.clone().map(|x| x.borrow().key) + } +} + +struct LFUCache { + /// 容量 + capacity: usize, + length: usize, + /// 存放数据的集合, 题目不需要delete,data:(frequency, Node) + data: std::collections::HashMap>)>, + /// 存放节点的频率 + frequencies: std::collections::HashMap, + /// 当前最小的频率 + min_frequency: i32, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ + +/** + * Your LFUCache object will be instantiated and called as such: + * let obj = LFUCache::new(capacity); + * let ret_1: i32 = obj.get(key); + * obj.put(key, value); + */ +impl LFUCache { + fn new(capacity: i32) -> Self { + use std::collections::HashMap; + Self { + capacity: capacity as _, + length: 0, + data: HashMap::new(), + frequencies: HashMap::new(), + min_frequency: 0, + } + } + + fn get(&mut self, key: i32) -> i32 { + if !self.data.contains_key(&key) { + return -1; + } + + self.increment(key, None) + } + + fn put(&mut self, key: i32, value: i32) { + if self.data.contains_key(&key) { + self.increment(key, Some(value)); + } else { + // 如果长度==容量,先要移除最小频率的值 + if self.length == self.capacity { + let k = self + .frequencies + .get_mut(&self.min_frequency) + .and_then(|x| x.pop()); + + k.map(|x| self.data.remove(&x)); + self.length -= 1; + + if self + .frequencies + .get(&self.min_frequency) + .map(|x| x.is_empty()) + .unwrap_or(true) + { + self.frequencies.remove(&self.min_frequency); + } + {} + } + self.length += 1; + self.min_frequency = 1; + + if self.frequencies.get(&1).is_none() { + let mut l = LinkList::new(); + self.data.insert(key, (1, l.push_front(key, value))); + self.frequencies.insert(1, l); + return; + } + + let a = if let Some(x) = self.frequencies.get_mut(&1) { + x.push_front(key, value) + } else { + return; + }; + self.data.insert(key, (1, a)); + } + } + + /// 增加key的频率,当new_val为Some时,替换key的值,返回旧值 + fn increment(&mut self, key: i32, new_val: Option) -> i32 { + let r = self.data.get(&key).unwrap(); + if let Some(val) = new_val { + r.1.borrow_mut().val = val; + } + + let val = r.1.borrow().val; + let fre = r.0; + + self.frequencies + .get_mut(&fre) + .map(|x| x.remove(r.1.clone())); + + if self.frequencies[&fre].is_empty() { + self.frequencies.remove(&fre); + + if fre == self.min_frequency { + self.min_frequency = fre + 1; + } + } + + if self.frequencies.get(&(fre + 1)).is_none() { + let mut l = LinkList::new(); + self.data.insert(key, (fre + 1, l.push_front(key, val))); + self.frequencies.insert(fre + 1, l); + return val; + } + + let a = if let Some(x) = self.frequencies.get_mut(&(fre + 1)) { + x.push_front(key, val) + } else { + return val; + }; + self.data.insert(key, (fre + 1, a)); + val + } +} + +impl std::fmt::Debug for LFUCache { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_map() + .entries(self.data.iter().map(|x| (*x.0, x.1 .0))) + .finish()?; + + f.debug_list() + .entries(self.frequencies.iter().map(|x| *x.0)) + .finish()?; + + f.debug_map() + .key(&"min") + .value(&self.min_frequency) + .finish() + } +} From d3d226e7e673831476d8c98f822d8854b4faadff Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 25 Sep 2023 23:45:11 +0800 Subject: [PATCH 1008/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index edaa187e..a62e5864 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 548 | 229 | 293 | 26 | +| 549 | 229 | 293 | 27 | ### 题目 @@ -237,6 +237,7 @@ |445 | 两数相加 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers-ii.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers-ii/) | Medium | |448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | |449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | +|460 | LFU 缓存 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lfu-cache.rs) | [leetcode](https://leetcode-cn.com/problems/lfu-cache/) | Hard | |461 | 汉明距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/hamming-distance.rs) | [leetcode](https://leetcode-cn.com/problems/hamming-distance/) | Easy | |476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | |481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | From 3d084c5b39a31eff3af14a0f1de434b11eeb2e20 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 26 Sep 2023 08:32:26 +0800 Subject: [PATCH 1009/1556] src/bin/pass-the-pillow.rs --- src/bin/pass-the-pillow.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/bin/pass-the-pillow.rs diff --git a/src/bin/pass-the-pillow.rs b/src/bin/pass-the-pillow.rs new file mode 100644 index 00000000..b663e327 --- /dev/null +++ b/src/bin/pass-the-pillow.rs @@ -0,0 +1,16 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn pass_the_pillow(n: i32, time: i32) -> i32 { + let time = time % ((n - 1) * 2); + if time < n { + time + 1 + } else { + n * 2 - time - 1 + } + } +} From cc4d960cfe23bb834d637b4c4b9215803f685d45 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 26 Sep 2023 08:32:26 +0800 Subject: [PATCH 1010/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a62e5864..d0338500 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 549 | 229 | 293 | 27 | +| 550 | 230 | 293 | 27 | ### 题目 @@ -416,6 +416,7 @@ |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | |2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | +|2645 | 递枕头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pass-the-pillow.rs) | [leetcode](https://leetcode-cn.com/problems/pass-the-pillow/) | Easy | |2662 | 检查骑士巡视方案 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-knight-tour-configuration.rs) | [leetcode](https://leetcode-cn.com/problems/check-knight-tour-configuration/) | Medium | |2663 | 将钱分给最多的儿童 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-money-to-maximum-children.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-money-to-maximum-children/) | Easy | |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | From 2e437844ea7ba06c79754306ca57fd3cab85942d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 27 Sep 2023 20:43:20 +0800 Subject: [PATCH 1011/1556] src/bin/smallest-string-with-a-given-numeric-value.rs --- ...llest-string-with-a-given-numeric-value.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/smallest-string-with-a-given-numeric-value.rs diff --git a/src/bin/smallest-string-with-a-given-numeric-value.rs b/src/bin/smallest-string-with-a-given-numeric-value.rs new file mode 100644 index 00000000..1cd7c539 --- /dev/null +++ b/src/bin/smallest-string-with-a-given-numeric-value.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn get_smallest_string(n: i32, k: i32) -> String { + const A: i32 = (b'z' - b'a') as _; + let mut result = vec![b'z'; n as _]; + let mut total = (A + 1) * n; + for i in 0..n as _ { + if total - k >= A { + result[i] -= A as u8; + total -= A; + } else { + result[i] -= (total - k) as u8; + break; + } + } + + String::from_utf8(result).unwrap() + } +} From c54bfd461a664d293fcab5f0fcbec19ba6dd76a6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 27 Sep 2023 20:43:21 +0800 Subject: [PATCH 1012/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d0338500..0feafad4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 550 | 230 | 293 | 27 | +| 551 | 230 | 294 | 27 | ### 题目 @@ -376,6 +376,7 @@ |1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | |1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | |1677 | 矩阵对角线元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/matrix-diagonal-sum.rs) | [leetcode](https://leetcode-cn.com/problems/matrix-diagonal-sum/) | Easy | +|1782 | 具有给定数值的最小字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-string-with-a-given-numeric-value.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-string-with-a-given-numeric-value/) | Medium | |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | From 08bb762ff5285e5d04b5aa8841f61bf043196aee Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 28 Sep 2023 19:30:54 +0800 Subject: [PATCH 1013/1556] src/bin/leaf-similar-trees.rs --- src/bin/leaf-similar-trees.rs | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/bin/leaf-similar-trees.rs diff --git a/src/bin/leaf-similar-trees.rs b/src/bin/leaf-similar-trees.rs new file mode 100644 index 00000000..099e7649 --- /dev/null +++ b/src/bin/leaf-similar-trees.rs @@ -0,0 +1,57 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +impl Solution { + pub fn leaf_similar( + root1: Option>>, + root2: Option>>, + ) -> bool { + let mut v1 = vec![]; + let mut v2 = vec![]; + Self::get(root1, &mut v1); + Self::get(root2, &mut v2); + + v1 == v2 + } + + fn get(root: Option>>, v: &mut Vec) { + if root.is_none() { + return; + } + + let root = root.unwrap(); + let left = root.borrow_mut().left.take(); + let right = root.borrow_mut().right.take(); + if left.is_none() && right.is_none() { + v.push(root.borrow().val); + } + + Self::get(left, v); + Self::get(right, v); + } +} From e605257111cc336226bf962e0df9b2161dfc6ac0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 28 Sep 2023 19:30:54 +0800 Subject: [PATCH 1014/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0feafad4..b2b5b30e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 551 | 230 | 294 | 27 | +| 552 | 231 | 294 | 27 | ### 题目 @@ -295,6 +295,7 @@ |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | |879 | 到最近的人的最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximize-distance-to-closest-person.rs) | [leetcode](https://leetcode-cn.com/problems/maximize-distance-to-closest-person/) | Medium | |890 | 柠檬水找零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lemonade-change.rs) | [leetcode](https://leetcode-cn.com/problems/lemonade-change/) | Easy | +|904 | 叶子相似的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/leaf-similar-trees.rs) | [leetcode](https://leetcode-cn.com/problems/leaf-similar-trees/) | Easy | |905 | 最长的斐波那契子序列的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-longest-fibonacci-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence/) | Medium | |906 | 模拟行走机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/walking-robot-simulation.rs) | [leetcode](https://leetcode-cn.com/problems/walking-robot-simulation/) | Medium | |908 | 链表的中间结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/middle-of-the-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/middle-of-the-linked-list/) | Easy | From 17fd9fc446c823f7bcba263985345ec43c4ca136 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 6 Oct 2023 23:36:42 +0800 Subject: [PATCH 1015/1556] src/bin/latest-time-by-replacing-hidden-digits.rs --- .../latest-time-by-replacing-hidden-digits.rs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/bin/latest-time-by-replacing-hidden-digits.rs diff --git a/src/bin/latest-time-by-replacing-hidden-digits.rs b/src/bin/latest-time-by-replacing-hidden-digits.rs new file mode 100644 index 00000000..06ee03b8 --- /dev/null +++ b/src/bin/latest-time-by-replacing-hidden-digits.rs @@ -0,0 +1,42 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_time(mut time: String) -> String { + let mut f = false; + unsafe { + let mut s = time.as_bytes_mut(); + for i in 0..s.len() { + if s[i] == b'?' { + match i { + 0 => { + if s[1] == b'?' || (s[1] >= b'0' && s[1] <= b'3') { + s[0] = b'2'; + } else { + s[0] = b'1'; + } + } + 1 => { + if f { + s[1] = b'3'; + } else { + s[1] = b'9'; + } + } + + 3 => s[3] = b'5', + 4 => s[4] = b'9', + _ => {} + } + } + + f = s[0] == b'2'; + } + } + + time + } +} From 262290a876bdbdda7255e9437d31a311dc94c1f3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 6 Oct 2023 23:36:43 +0800 Subject: [PATCH 1016/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b2b5b30e..1e23c011 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 552 | 231 | 294 | 27 | +| 553 | 232 | 294 | 27 | ### 题目 @@ -383,6 +383,7 @@ |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | |1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | |1849 | 任意子数组和的绝对值的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-absolute-sum-of-any-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | +|1858 | 替换隐藏数字得到的最晚时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/latest-time-by-replacing-hidden-digits.rs) | [leetcode](https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits/) | Easy | |1894 | 交替合并字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-strings-alternately.rs) | [leetcode](https://leetcode-cn.com/problems/merge-strings-alternately/) | Easy | |1929 | 有界数组中指定下标处的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-at-a-given-index-in-a-bounded-array/) | Medium | |1938 | 最少操作使数组递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-make-the-array-increasing.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-increasing/) | Easy | From 05477971d2e573c72da0dd765472191aa3ed8641 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 7 Oct 2023 20:47:01 +0800 Subject: [PATCH 1017/1556] src/bin/online-stock-span.rs --- src/bin/online-stock-span.rs | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bin/online-stock-span.rs diff --git a/src/bin/online-stock-span.rs b/src/bin/online-stock-span.rs new file mode 100644 index 00000000..4ec3ea74 --- /dev/null +++ b/src/bin/online-stock-span.rs @@ -0,0 +1,40 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +struct StockSpanner { + n: i32, + stack: Vec<(i32, i32)>, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +/** + * Your StockSpanner object will be instantiated and called as such: + * let obj = StockSpanner::new(); + * let ret_1: i32 = obj.next(price); + */ +impl StockSpanner { + fn new() -> Self { + Self { + n: -1, + stack: vec![(-1, i32::MAX)], + } + } + + fn next(&mut self, price: i32) -> i32 { + self.n += 1; + + while !self.stack.is_empty() && price >= self.stack[self.stack.len() - 1].1 { + self.stack.pop(); + } + + self.stack.push((self.n, price)); + + self.n - self.stack[self.stack.len() - 2].0 + } +} From 94ccde5185b70025712950a3367270856ed92c29 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 7 Oct 2023 20:47:01 +0800 Subject: [PATCH 1018/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e23c011..e11aa43c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 553 | 232 | 294 | 27 | +| 554 | 232 | 295 | 27 | ### 题目 @@ -305,6 +305,7 @@ |925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | +|937 | 股票价格跨度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-stock-span.rs) | [leetcode](https://leetcode-cn.com/problems/online-stock-span/) | Medium | |947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | |953 | 仅仅反转字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-only-letters.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-only-letters/) | Easy | |954 | 环形子数组的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-circular-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-circular-subarray/) | Medium | From 8a91b4bdab11d37694bd1006a5d2f100103afc13 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 8 Oct 2023 20:36:31 +0800 Subject: [PATCH 1019/1556] src/bin/stock-price-fluctuation.rs --- src/bin/stock-price-fluctuation.rs | 64 ++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/bin/stock-price-fluctuation.rs diff --git a/src/bin/stock-price-fluctuation.rs b/src/bin/stock-price-fluctuation.rs new file mode 100644 index 00000000..8764d992 --- /dev/null +++ b/src/bin/stock-price-fluctuation.rs @@ -0,0 +1,64 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +struct StockPrice { + current: i32, + + /// timestamp: price + time_map: std::collections::HashMap, + /// price: 次数 + price_count: std::collections::BTreeMap, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +/** + * Your StockPrice object will be instantiated and called as such: + * let obj = StockPrice::new(); + * obj.update(timestamp, price); + * let ret_2: i32 = obj.current(); + * let ret_3: i32 = obj.maximum(); + * let ret_4: i32 = obj.minimum(); + */ + +impl StockPrice { + fn new() -> Self { + StockPrice { + current: 0, + time_map: Default::default(), + price_count: Default::default(), + } + } + + fn update(&mut self, timestamp: i32, price: i32) { + self.current = self.current.max(timestamp); + if let Some(x) = self.time_map.insert(timestamp, price) { + *self.price_count.get_mut(&x).unwrap() -= 1; + if self.price_count[&x] == 0 { + self.price_count.remove(&x); + } + } + + self.price_count + .entry(price) + .and_modify(|x| *x += 1) + .or_insert(1); + } + + fn current(&self) -> i32 { + self.time_map[&self.current] + } + + fn maximum(&self) -> i32 { + *self.price_count.iter().rev().next().unwrap().0 + } + + fn minimum(&self) -> i32 { + *self.price_count.iter().next().unwrap().0 + } +} From 48e278896d41decfb4489fe9a23610ae3cb3f5ce Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 8 Oct 2023 20:36:31 +0800 Subject: [PATCH 1020/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e11aa43c..f7fc26e4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 554 | 232 | 295 | 27 | +| 555 | 232 | 296 | 27 | ### 题目 @@ -397,6 +397,7 @@ |2104 | 树上的操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/operations-on-tree.rs) | [leetcode](https://leetcode-cn.com/problems/operations-on-tree/) | Medium | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | +|2161 | 股票价格波动 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/stock-price-fluctuation.rs) | [leetcode](https://leetcode-cn.com/problems/stock-price-fluctuation/) | Medium | |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | |2233 | 股票平滑下跌阶段的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-smooth-descent-periods-of-a-stock.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-smooth-descent-periods-of-a-stock/) | Medium | |2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | From 5751baf8607f96f7b006bbb8a54ff551e0103ecc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 9 Oct 2023 20:54:14 +0800 Subject: [PATCH 1021/1556] src/bin/split-with-minimum-sum.rs --- src/bin/split-with-minimum-sum.rs | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/bin/split-with-minimum-sum.rs diff --git a/src/bin/split-with-minimum-sum.rs b/src/bin/split-with-minimum-sum.rs new file mode 100644 index 00000000..7eb77ac7 --- /dev/null +++ b/src/bin/split-with-minimum-sum.rs @@ -0,0 +1,34 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn split_num(num: i32) -> i32 { + let mut num = num; + let mut v = [0; 10]; + while num > 0 { + v[(num % 10) as usize] += 1; + num /= 10; + } + let (mut l, mut r) = (0, 0); + let mut i = 1; + let mut f = false; + while i < v.len() { + if v[i] > 0 { + if f { + l = l * 10 + i as i32; + } else { + r = r * 10 + i as i32; + } + v[i] -= 1; + f = !f; + } else { + i += 1; + } + } + + l + r + } +} From 7ba38ab1ab2521812e1133ee6843f0e6ec083888 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 9 Oct 2023 20:54:15 +0800 Subject: [PATCH 1022/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f7fc26e4..ec47c756 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 555 | 232 | 296 | 27 | +| 556 | 233 | 296 | 27 | ### 题目 @@ -422,6 +422,7 @@ |2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2645 | 递枕头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pass-the-pillow.rs) | [leetcode](https://leetcode-cn.com/problems/pass-the-pillow/) | Easy | +|2650 | 最小和分割 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-with-minimum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/split-with-minimum-sum/) | Easy | |2662 | 检查骑士巡视方案 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-knight-tour-configuration.rs) | [leetcode](https://leetcode-cn.com/problems/check-knight-tour-configuration/) | Medium | |2663 | 将钱分给最多的儿童 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-money-to-maximum-children.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-money-to-maximum-children/) | Easy | |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | From e482cc8123b6585b551ce69936fc7304801ed1b3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 10 Oct 2023 21:27:36 +0800 Subject: [PATCH 1023/1556] src/bin/movement-of-robots.rs --- src/bin/movement-of-robots.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/movement-of-robots.rs diff --git a/src/bin/movement-of-robots.rs b/src/bin/movement-of-robots.rs new file mode 100644 index 00000000..c0f76afc --- /dev/null +++ b/src/bin/movement-of-robots.rs @@ -0,0 +1,31 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn sum_distance(nums: Vec, s: String, d: i32) -> i32 { + let mut nums = nums; + let s = s.as_bytes(); + + for i in 0..s.len() { + if s[i] == b'R' { + nums[i] += d; + } else { + nums[i] -= d; + } + } + + nums.sort(); + let mut result = 0i64; + const MOD: i64 = 10i64.pow(9) + 7; + let mut sum = 0i64; + for i in 0..s.len() { + result = (result + nums[i] as i64 * i as i64 - sum) % MOD; + sum = (sum + nums[i] as i64) % MOD; + } + + result as i32 + } +} From 0da471b81afd3f8a29d52860caacff2b76867515 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 10 Oct 2023 21:27:36 +0800 Subject: [PATCH 1024/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ec47c756..a9687ce6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 556 | 233 | 296 | 27 | +| 557 | 233 | 297 | 27 | ### 题目 @@ -434,6 +434,7 @@ |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | |2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | +|2787 | 移动机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/movement-of-robots.rs) | [leetcode](https://leetcode-cn.com/problems/movement-of-robots/) | Medium | |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | |2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | From 9944bff5061870f0d36424c19775412f8e6e67a0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 11 Oct 2023 20:13:27 +0800 Subject: [PATCH 1025/1556] src/bin/reward-top-k-students.rs --- src/bin/reward-top-k-students.rs | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/bin/reward-top-k-students.rs diff --git a/src/bin/reward-top-k-students.rs b/src/bin/reward-top-k-students.rs new file mode 100644 index 00000000..ba98200e --- /dev/null +++ b/src/bin/reward-top-k-students.rs @@ -0,0 +1,47 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn top_students( + positive_feedback: Vec, + negative_feedback: Vec, + report: Vec, + student_id: Vec, + k: i32, + ) -> Vec { + let positive_feedback: std::collections::HashSet<_> = + positive_feedback.iter().map(|x| x.as_str()).collect(); + + let negative_feedback: std::collections::HashSet<_> = + negative_feedback.iter().map(|x| x.as_str()).collect(); + + let mut s = (0..student_id.len()) + .map(|x| { + let mut score = 0; + for i in report[x].split(' ').into_iter() { + if positive_feedback.contains(i) { + score += 3; + } + if negative_feedback.contains(i) { + score -= 1; + } + } + + (score, student_id[x]) + }) + .collect::>(); + + s.sort_unstable_by(|x, y| { + if x.0 != y.0 { + y.0.cmp(&x.0) + } else { + x.1.cmp(&y.1) + } + }); + + s.into_iter().take(k as usize).map(|x| x.1).collect() + } +} From d2819f4966eb2187523f2fe5c15c5941befcca63 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 11 Oct 2023 20:13:28 +0800 Subject: [PATCH 1026/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a9687ce6..4ac87685 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 557 | 233 | 297 | 27 | +| 558 | 233 | 298 | 27 | ### 题目 @@ -420,6 +420,7 @@ |2585 | 删除每行中的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-greatest-value-in-each-row.rs) | [leetcode](https://leetcode-cn.com/problems/delete-greatest-value-in-each-row/) | Easy | |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | |2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | +|2603 | 奖励最顶尖的 K 名学生 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reward-top-k-students.rs) | [leetcode](https://leetcode-cn.com/problems/reward-top-k-students/) | Medium | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2645 | 递枕头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pass-the-pillow.rs) | [leetcode](https://leetcode-cn.com/problems/pass-the-pillow/) | Easy | |2650 | 最小和分割 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-with-minimum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/split-with-minimum-sum/) | Easy | From aa677b297b09ca62816d2a911b1b75af0d5c0b1f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 12 Oct 2023 20:53:30 +0800 Subject: [PATCH 1027/1556] src/bin/find-the-array-concatenation-value.rs --- src/bin/find-the-array-concatenation-value.rs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/find-the-array-concatenation-value.rs diff --git a/src/bin/find-the-array-concatenation-value.rs b/src/bin/find-the-array-concatenation-value.rs new file mode 100644 index 00000000..af746e86 --- /dev/null +++ b/src/bin/find-the-array-concatenation-value.rs @@ -0,0 +1,31 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_the_array_conc_val(nums: Vec) -> i64 { + let (mut start, mut end) = (0, nums.len() - 1); + let mut r = 0; + while start <= end { + if start == end { + r += nums[start] as i64; + break; + } else { + let x = nums[start] as i64; + let mut y = nums[end] as i64; + let mut m = 1; + while m <= y { + m *= 10; + } + r += (x * m) + y; + } + + start += 1; + end -= 1; + } + + r + } +} From 596418e7aec633dd3b678efdd9de94e5f77e2bff Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 12 Oct 2023 20:53:30 +0800 Subject: [PATCH 1028/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ac87685..a3096fa4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 558 | 233 | 298 | 27 | +| 559 | 234 | 298 | 27 | ### 题目 @@ -432,6 +432,7 @@ |2679 | 统计桌面上的不同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-distinct-numbers-on-board.rs) | [leetcode](https://leetcode-cn.com/problems/count-distinct-numbers-on-board/) | Easy | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | |2694 | 找出可整除性得分最大的整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-divisibility-score.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-divisibility-score/) | Easy | +|2698 | 找出数组的串联值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-array-concatenation-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-array-concatenation-value/) | Easy | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | |2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | From dbeaf6f58e7af05075d47712cdba441555ffae33 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 15 Oct 2023 22:03:00 +0800 Subject: [PATCH 1029/1556] src/bin/create-target-array-in-the-given-order.rs --- .../create-target-array-in-the-given-order.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/bin/create-target-array-in-the-given-order.rs diff --git a/src/bin/create-target-array-in-the-given-order.rs b/src/bin/create-target-array-in-the-given-order.rs new file mode 100644 index 00000000..60b76ed7 --- /dev/null +++ b/src/bin/create-target-array-in-the-given-order.rs @@ -0,0 +1,17 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn create_target_array(nums: Vec, index: Vec) -> Vec { + let mut s = Vec::new(); + + for i in 0..nums.len() { + s.insert(index[i] as usize, nums[i]); + } + + s + } +} From cfa89f45e9b4586f0491271f17b0f8dae0b68c6a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 15 Oct 2023 22:03:01 +0800 Subject: [PATCH 1030/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a3096fa4..1e06f716 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 559 | 234 | 298 | 27 | +| 560 | 235 | 298 | 27 | ### 题目 @@ -362,6 +362,7 @@ |1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | |1491 | 二进制字符串前缀一致的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-times-binary-string-is-prefix-aligned.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-times-binary-string-is-prefix-aligned/) | Medium | |1501 | 圆和矩形是否有重叠 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circle-and-rectangle-overlapping.rs) | [leetcode](https://leetcode-cn.com/problems/circle-and-rectangle-overlapping/) | Medium | +|1505 | 按既定顺序创建目标数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/create-target-array-in-the-given-order.rs) | [leetcode](https://leetcode-cn.com/problems/create-target-array-in-the-given-order/) | Easy | |1512 | 设计地铁系统 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-underground-system.rs) | [leetcode](https://leetcode-cn.com/problems/design-underground-system/) | Medium | |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | |1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | From 9424aefc63bd48c7aeb5f05b5c7b15144402c333 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 16 Oct 2023 20:26:19 +0800 Subject: [PATCH 1031/1556] src/bin/single-number-iii.rs --- src/bin/single-number-iii.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/bin/single-number-iii.rs diff --git a/src/bin/single-number-iii.rs b/src/bin/single-number-iii.rs new file mode 100644 index 00000000..05eb33c6 --- /dev/null +++ b/src/bin/single-number-iii.rs @@ -0,0 +1,22 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn single_number(nums: Vec) -> Vec { + let x = nums.iter().fold(0, |x, y| x ^ y); + let y = x & -x; + let (mut type1, mut type2) = (0, 0); + for i in nums { + if i & y > 0 { + type1 ^= i; + } else { + type2 ^= i; + } + } + + vec![type1, type2] + } +} From 18135d2e4c2c29e4bf93f9d16df32d9a83b64888 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 16 Oct 2023 20:26:19 +0800 Subject: [PATCH 1032/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e06f716..4fb8fbde 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 560 | 235 | 298 | 27 | +| 561 | 235 | 299 | 27 | ### 题目 @@ -177,6 +177,7 @@ |242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | Easy | |257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | Easy | |258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits/) | Easy | +|260 | 只出现一次的数字 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-iii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-iii/) | Medium | |263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | Easy | |268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | Easy | |274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Medium | From e76a94fe8a07f126fa78d472450d4e516f62e9f4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 17 Oct 2023 20:59:25 +0800 Subject: [PATCH 1033/1556] src/bin/sum-multiples.rs --- src/bin/sum-multiples.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/bin/sum-multiples.rs diff --git a/src/bin/sum-multiples.rs b/src/bin/sum-multiples.rs new file mode 100644 index 00000000..c732f6f4 --- /dev/null +++ b/src/bin/sum-multiples.rs @@ -0,0 +1,12 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn sum_of_multiples(n: i32) -> i32 { + let f = |y: i32| -> i32 { (y + (n / y) * y) * (n / y) / 2 }; + f(3) + f(5) + f(7) - f(3 * 5) - f(3 * 7) - f(5 * 7) + f(3 * 5 * 7) + } +} From 936f20cecdbbab3a6c8b358058b9230129cdf996 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 17 Oct 2023 20:59:26 +0800 Subject: [PATCH 1034/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4fb8fbde..612fa70f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 561 | 235 | 299 | 27 | +| 562 | 236 | 299 | 27 | ### 题目 @@ -438,6 +438,7 @@ |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | |2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | +|2752 | 倍数求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-multiples.rs) | [leetcode](https://leetcode-cn.com/problems/sum-multiples/) | Easy | |2787 | 移动机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/movement-of-robots.rs) | [leetcode](https://leetcode-cn.com/problems/movement-of-robots/) | Medium | |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | |2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | From 98cfd8c371313225c7bdc7f186f180d8f64bb7ce Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 18 Oct 2023 20:08:59 +0800 Subject: [PATCH 1035/1556] src/bin/maximal-score-after-applying-k-operations.rs --- ...ximal-score-after-applying-k-operations.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/maximal-score-after-applying-k-operations.rs diff --git a/src/bin/maximal-score-after-applying-k-operations.rs b/src/bin/maximal-score-after-applying-k-operations.rs new file mode 100644 index 00000000..133770da --- /dev/null +++ b/src/bin/maximal-score-after-applying-k-operations.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::collections::BinaryHeap; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_kelements(nums: Vec, k: i32) -> i64 { + use std::collections::BinaryHeap; + let mut heap: BinaryHeap = nums.into_iter().collect(); + + let mut r = 0; + for i in 0..k { + let x = heap.pop().unwrap(); + r += x as i64; + heap.push({ + if (x / 3) * 3 == x { + x / 3 + } else { + x / 3 + 1 + } + }); + } + + r + } +} From 9284966d59b01ae0a57959c421510e7bdf0e3e2e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 18 Oct 2023 20:09:00 +0800 Subject: [PATCH 1036/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 612fa70f..c3f24a27 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 562 | 236 | 299 | 27 | +| 563 | 236 | 300 | 27 | ### 题目 @@ -423,6 +423,7 @@ |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | |2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | |2603 | 奖励最顶尖的 K 名学生 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reward-top-k-students.rs) | [leetcode](https://leetcode-cn.com/problems/reward-top-k-students/) | Medium | +|2616 | 执行 K 次操作后的最大分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-score-after-applying-k-operations.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-score-after-applying-k-operations/) | Medium | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2645 | 递枕头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pass-the-pillow.rs) | [leetcode](https://leetcode-cn.com/problems/pass-the-pillow/) | Easy | |2650 | 最小和分割 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-with-minimum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/split-with-minimum-sum/) | Easy | From 5a2a1841de362d47f96ef3aa9f493482662b0e69 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 19 Oct 2023 22:49:40 +0800 Subject: [PATCH 1037/1556] src/bin/tuple-with-same-product.rs --- src/bin/tuple-with-same-product.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/tuple-with-same-product.rs diff --git a/src/bin/tuple-with-same-product.rs b/src/bin/tuple-with-same-product.rs new file mode 100644 index 00000000..39a585ec --- /dev/null +++ b/src/bin/tuple-with-same-product.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn tuple_same_product(nums: Vec) -> i32 { + let mut s = std::collections::HashMap::new(); + let mut r = 0; + for i in 0..nums.len() { + for j in i + 1..nums.len() { + if let Some(x) = s.get_mut(&(nums[i] * nums[j])) { + r += (*x * 8); + *x += 1; + continue; + } + + s.insert(nums[i] * nums[j], 1); + } + } + + r + } +} From d4bc41cdcc3e2b3f1009bfebd653905c4caa1927 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 19 Oct 2023 22:49:40 +0800 Subject: [PATCH 1038/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c3f24a27..e2f0a66c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 563 | 236 | 300 | 27 | +| 564 | 236 | 301 | 27 | ### 题目 @@ -343,6 +343,7 @@ |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | |1342 | 可以攻击国王的皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/queens-that-can-attack-the-king.rs) | [leetcode](https://leetcode-cn.com/problems/queens-that-can-attack-the-king/) | Medium | |1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | +|1364 | 同积元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tuple-with-same-product.rs) | [leetcode](https://leetcode-cn.com/problems/tuple-with-same-product/) | Medium | |1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | |1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | |1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | From 3fd31ef9ff813afebcc6d75eaa0e67db443ca9e2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 21 Oct 2023 16:37:19 +0800 Subject: [PATCH 1039/1556] src/bin/categorize-box-according-to-criteria.rs --- .../categorize-box-according-to-criteria.rs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/categorize-box-according-to-criteria.rs diff --git a/src/bin/categorize-box-according-to-criteria.rs b/src/bin/categorize-box-according-to-criteria.rs new file mode 100644 index 00000000..74f92599 --- /dev/null +++ b/src/bin/categorize-box-according-to-criteria.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn categorize_box(length: i32, width: i32, height: i32, mass: i32) -> String { + const A: i32 = 10i32.pow(4); + const B: i64 = 10i64.pow(9); + let is_bulky = length >= A + || width >= A + || height >= A + || (length as i64 * width as i64 * height as i64) >= B; + let is_heavy = mass >= 100; + + if is_bulky && is_heavy { + "Both" + } else if is_bulky { + "Bulky" + } else if is_heavy { + "Heavy" + } else { + "Neither" + } + .into() + } +} From 1a8969316829dd5f539f0699a9b502c55a2a9d7d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 21 Oct 2023 16:37:20 +0800 Subject: [PATCH 1040/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e2f0a66c..f02c6473 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 564 | 236 | 301 | 27 | +| 565 | 237 | 301 | 27 | ### 题目 @@ -425,6 +425,7 @@ |2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | |2603 | 奖励最顶尖的 K 名学生 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reward-top-k-students.rs) | [leetcode](https://leetcode-cn.com/problems/reward-top-k-students/) | Medium | |2616 | 执行 K 次操作后的最大分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-score-after-applying-k-operations.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-score-after-applying-k-operations/) | Medium | +|2619 | 根据规则将箱子分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/categorize-box-according-to-criteria.rs) | [leetcode](https://leetcode-cn.com/problems/categorize-box-according-to-criteria/) | Easy | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2645 | 递枕头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pass-the-pillow.rs) | [leetcode](https://leetcode-cn.com/problems/pass-the-pillow/) | Easy | |2650 | 最小和分割 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-with-minimum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/split-with-minimum-sum/) | Easy | From 20978a36afb3574f18a4aec6a7e93aff20311fe8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 22 Oct 2023 11:04:13 +0800 Subject: [PATCH 1041/1556] src/bin/reducing-dishes.rs --- src/bin/reducing-dishes.rs | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/bin/reducing-dishes.rs diff --git a/src/bin/reducing-dishes.rs b/src/bin/reducing-dishes.rs new file mode 100644 index 00000000..c447b7e2 --- /dev/null +++ b/src/bin/reducing-dishes.rs @@ -0,0 +1,47 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_satisfaction(mut satisfaction: Vec) -> i32 { + satisfaction.sort_unstable(); + let mut hash = std::collections::HashMap::new(); + Self::f(&satisfaction[..], &mut hash, 0, 1) + } + + fn f( + satisfaction: &[i32], + hash: &mut std::collections::HashMap<(usize, i32), i32>, + start_index: usize, + current_time: i32, + ) -> i32 { + if start_index == satisfaction.len() { + return 0; + } + + let x = if let Some(x) = hash.get(&(start_index + 1, current_time + 1)) { + *x + } else { + let v = Self::f(satisfaction, hash, start_index + 1, current_time + 1); + hash.insert((start_index + 1, current_time + 1), v); + v + }; + + let x = x + satisfaction[start_index] * current_time; + + let y = if let Some(x) = hash.get(&(start_index + 1, current_time)) { + *x + } else { + let v = Self::f(satisfaction, hash, start_index + 1, current_time); + hash.insert((start_index + 1, current_time), v); + v + }; + + let max = x.max(y); + hash.insert((start_index, current_time), max); + + max + } +} From 68f98cca4715f3133e1a8eb2c9235bd350064dba Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 22 Oct 2023 11:04:14 +0800 Subject: [PATCH 1042/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f02c6473..b7ae65a5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 565 | 237 | 301 | 27 | +| 566 | 237 | 301 | 28 | ### 题目 @@ -364,6 +364,7 @@ |1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | |1491 | 二进制字符串前缀一致的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-times-binary-string-is-prefix-aligned.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-times-binary-string-is-prefix-aligned/) | Medium | |1501 | 圆和矩形是否有重叠 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circle-and-rectangle-overlapping.rs) | [leetcode](https://leetcode-cn.com/problems/circle-and-rectangle-overlapping/) | Medium | +|1503 | 做菜顺序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reducing-dishes.rs) | [leetcode](https://leetcode-cn.com/problems/reducing-dishes/) | Hard | |1505 | 按既定顺序创建目标数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/create-target-array-in-the-given-order.rs) | [leetcode](https://leetcode-cn.com/problems/create-target-array-in-the-given-order/) | Easy | |1512 | 设计地铁系统 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-underground-system.rs) | [leetcode](https://leetcode-cn.com/problems/design-underground-system/) | Medium | |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | From 406fbc548299efb1f5b8f105c8caab9bd88875ed Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 23 Oct 2023 19:36:07 +0800 Subject: [PATCH 1043/1556] src/bin/number-of-senior-citizens.rs --- src/bin/number-of-senior-citizens.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/bin/number-of-senior-citizens.rs diff --git a/src/bin/number-of-senior-citizens.rs b/src/bin/number-of-senior-citizens.rs new file mode 100644 index 00000000..a205e640 --- /dev/null +++ b/src/bin/number-of-senior-citizens.rs @@ -0,0 +1,14 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_seniors(details: Vec) -> i32 { + details + .iter() + .filter(|x| &x.as_str()[11..=12] > "60") + .count() as i32 + } +} From 399d56d8fb4f659794e9499927e8acc256f0307f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 23 Oct 2023 19:36:08 +0800 Subject: [PATCH 1044/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b7ae65a5..748480a9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 566 | 237 | 301 | 28 | +| 567 | 238 | 301 | 28 | ### 题目 @@ -440,6 +440,7 @@ |2694 | 找出可整除性得分最大的整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-divisibility-score.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-divisibility-score/) | Easy | |2698 | 找出数组的串联值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-array-concatenation-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-array-concatenation-value/) | Easy | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | +|2727 | 老人的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-senior-citizens.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-senior-citizens/) | Easy | |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | |2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | |2752 | 倍数求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-multiples.rs) | [leetcode](https://leetcode-cn.com/problems/sum-multiples/) | Easy | From 95e4d90610d6abd725eb7ea609aea3fb1f9b475b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 24 Oct 2023 20:58:50 +0800 Subject: [PATCH 1045/1556] src/bin/number-of-dice-rolls-with-target-sum.rs --- .../number-of-dice-rolls-with-target-sum.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/bin/number-of-dice-rolls-with-target-sum.rs diff --git a/src/bin/number-of-dice-rolls-with-target-sum.rs b/src/bin/number-of-dice-rolls-with-target-sum.rs new file mode 100644 index 00000000..fd52cf58 --- /dev/null +++ b/src/bin/number-of-dice-rolls-with-target-sum.rs @@ -0,0 +1,26 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn num_rolls_to_target(n: i32, k: i32, target: i32) -> i32 { + if target < n || target > n * k { + return 0; // 无法组成 target + } + const MOD: i32 = 1_000_000_007; + let (n, k, target) = (n as usize, k as usize, target as usize); + let mut f = vec![vec![0; target - n + 1]; n + 1]; + f[0][0] = 1; + for i in 1..=n { + for j in 0..=target - n { + for x in 0..k.min(j + 1) { + // 掷出了 x + f[i][j] = (f[i][j] + f[i - 1][j - x]) % MOD; + } + } + } + f[n][target - n] + } +} From 5dd63b4fcc17e94b60b5d79a7748b45b0352a5d0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 24 Oct 2023 20:58:50 +0800 Subject: [PATCH 1046/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 748480a9..ae61e36e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 567 | 238 | 301 | 28 | +| 568 | 238 | 302 | 28 | ### 题目 @@ -333,6 +333,7 @@ |1236 | 第 N 个泰波那契数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-th-tribonacci-number.rs) | [leetcode](https://leetcode-cn.com/problems/n-th-tribonacci-number/) | Easy | |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | |1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | +|1263 | 掷骰子等于目标和的方法数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-dice-rolls-with-target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-dice-rolls-with-target-sum/) | Medium | |1273 | 比较字符串最小字母出现频次 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-strings-by-frequency-of-the-smallest-character.rs) | [leetcode](https://leetcode-cn.com/problems/compare-strings-by-frequency-of-the-smallest-character/) | Medium | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | |1293 | 存在连续三个奇数的数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/three-consecutive-odds.rs) | [leetcode](https://leetcode-cn.com/problems/three-consecutive-odds/) | Easy | From 762955840cecb5022bcdfed0d6ddd9ec7de94be1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 25 Oct 2023 20:26:28 +0800 Subject: [PATCH 1047/1556] src/bin/find-the-punishment-number-of-an-integer.rs --- ...ind-the-punishment-number-of-an-integer.rs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/find-the-punishment-number-of-an-integer.rs diff --git a/src/bin/find-the-punishment-number-of-an-integer.rs b/src/bin/find-the-punishment-number-of-an-integer.rs new file mode 100644 index 00000000..3e84f891 --- /dev/null +++ b/src/bin/find-the-punishment-number-of-an-integer.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn punishment_number(n: i32) -> i32 { + (1..=n).into_iter().filter(Self::is).map(|x| x * x).sum() + } + + pub fn is(n: &i32) -> bool { + fn s(mut num: i32, except: i32) -> bool { + if num == except { + return true; + } + + if num == 0 { + return false; + } + let mut flag = 10; + while num % flag != num { + if s(num / flag, except - (num % flag)) { + return true; + } + + flag *= 10; + } + + false + } + + s(n * n, *n) + } +} From a105c6f30b5259175c50332919ef6ecaca061209 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 25 Oct 2023 20:26:29 +0800 Subject: [PATCH 1048/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ae61e36e..f6d59638 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 568 | 238 | 302 | 28 | +| 569 | 238 | 303 | 28 | ### 题目 @@ -447,6 +447,7 @@ |2752 | 倍数求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-multiples.rs) | [leetcode](https://leetcode-cn.com/problems/sum-multiples/) | Easy | |2787 | 移动机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/movement-of-robots.rs) | [leetcode](https://leetcode-cn.com/problems/movement-of-robots/) | Medium | |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | +|2802 | 求一个整数的惩罚数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-punishment-number-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-punishment-number-of-an-integer/) | Medium | |2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | From 15ccb5d8ca9c7ede29e43619ca4a8dcadd8ee77a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 26 Oct 2023 08:21:49 +0800 Subject: [PATCH 1049/1556] src/bin/count-the-digits-that-divide-a-number.rs --- .../count-the-digits-that-divide-a-number.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/count-the-digits-that-divide-a-number.rs diff --git a/src/bin/count-the-digits-that-divide-a-number.rs b/src/bin/count-the-digits-that-divide-a-number.rs new file mode 100644 index 00000000..f0fa0ebd --- /dev/null +++ b/src/bin/count-the-digits-that-divide-a-number.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_digits(num: i32) -> i32 { + let mut n = num; + let mut r = 0; + while n > 0 { + if num % (n % 10) == 0 { + r += 1; + } + + n /= 10; + } + + r + } +} From 3561ff21b0155e61a3b9cfc752e3f260fdb289c5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 26 Oct 2023 08:21:50 +0800 Subject: [PATCH 1050/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f6d59638..d8678727 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 569 | 238 | 303 | 28 | +| 570 | 239 | 303 | 28 | ### 题目 @@ -426,6 +426,7 @@ |2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | |2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | |2603 | 奖励最顶尖的 K 名学生 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reward-top-k-students.rs) | [leetcode](https://leetcode-cn.com/problems/reward-top-k-students/) | Medium | +|2608 | 统计能整除数字的位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-the-digits-that-divide-a-number.rs) | [leetcode](https://leetcode-cn.com/problems/count-the-digits-that-divide-a-number/) | Easy | |2616 | 执行 K 次操作后的最大分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-score-after-applying-k-operations.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-score-after-applying-k-operations/) | Medium | |2619 | 根据规则将箱子分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/categorize-box-according-to-criteria.rs) | [leetcode](https://leetcode-cn.com/problems/categorize-box-according-to-criteria/) | Easy | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | From 2c31fb300a7825bf5ce7b66092252e1027452490 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 27 Oct 2023 08:43:15 +0800 Subject: [PATCH 1051/1556] src/bin/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.rs --- ...cake-after-horizontal-and-vertical-cuts.rs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.rs diff --git a/src/bin/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.rs b/src/bin/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.rs new file mode 100644 index 00000000..b0794323 --- /dev/null +++ b/src/bin/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_area( + h: i32, + w: i32, + mut horizontal_cuts: Vec, + mut vertical_cuts: Vec, + ) -> i32 { + horizontal_cuts.sort_unstable(); + vertical_cuts.sort_unstable(); + let mut r = 0; + + let horizontal_max = Self::get_max(h, horizontal_cuts); + let vertical_max = Self::get_max(w, vertical_cuts); + + ((horizontal_max as i64) * (vertical_max as i64) % (10i64.pow(9) + 7)) as i32 + } + + fn get_max(s: i32, cuts: Vec) -> i32 { + let mut max = cuts[0].max(s - cuts[cuts.len() - 1]); + + if cuts.len() > 1 { + for i in 1..cuts.len() { + max = max.max(cuts[i] - cuts[i - 1]); + } + } + + max + } +} From 445a7ec8713ac485afeceb2b7fe1e089ffbcf93b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 27 Oct 2023 08:43:16 +0800 Subject: [PATCH 1052/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d8678727..382109a2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 570 | 239 | 303 | 28 | +| 571 | 239 | 304 | 28 | ### 题目 @@ -374,6 +374,7 @@ |1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | |1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | |1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Medium | +|1575 | 切割后面积最大的蛋糕 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/) | Medium | |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | |1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | |1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | From 4e7ab63d369b2dfe26f1887784dde0bc931b274f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 28 Oct 2023 21:45:55 +0800 Subject: [PATCH 1053/1556] src/bin/take-gifts-from-the-richest-pile.rs --- src/bin/take-gifts-from-the-richest-pile.rs | 25 +++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/take-gifts-from-the-richest-pile.rs diff --git a/src/bin/take-gifts-from-the-richest-pile.rs b/src/bin/take-gifts-from-the-richest-pile.rs new file mode 100644 index 00000000..286de01b --- /dev/null +++ b/src/bin/take-gifts-from-the-richest-pile.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +extern crate core; + +use core::f64; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn pick_gifts(gifts: Vec, k: i32) -> i64 { + let mut iter = gifts.into_iter().fuse(); + let mut sum = iter.clone().map(|x| x as i64).sum(); + let mut set = iter.collect::>(); + + for i in 0..k { + let m = set.pop().unwrap(); + sum -= m as i64 - (f64::sqrt(m as f64) as i64); + set.push(f64::sqrt(m as f64) as i32); + } + + sum + } +} From 1d8a280096ed4c525a18bbe9fa0772298931f247 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 28 Oct 2023 21:45:55 +0800 Subject: [PATCH 1054/1556] README.md --- README.md | 4 +++- src/bin/take-gifts-from-the-richest-pile.rs | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 382109a2..101c1fc1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 571 | 239 | 304 | 28 | +| 573 | 241 | 304 | 28 | ### 题目 @@ -440,6 +440,8 @@ |2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | |2679 | 统计桌面上的不同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-distinct-numbers-on-board.rs) | [leetcode](https://leetcode-cn.com/problems/count-distinct-numbers-on-board/) | Easy | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | +|2692 | 从数量最多的堆取走礼物 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/take-gifts-from-the-richest-pile.rs) | [leetcode](https://leetcode-cn.com/problems/take-gifts-from-the-richest-pile/) | Easy | +|2692 | 从数量最多的堆取走礼物 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/take-gifts-from-the-richest-pile.rs) | [leetcode](https://leetcode-cn.com/problems/take-gifts-from-the-richest-pile/) | Easy | |2694 | 找出可整除性得分最大的整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-divisibility-score.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-divisibility-score/) | Easy | |2698 | 找出数组的串联值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-array-concatenation-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-array-concatenation-value/) | Easy | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | diff --git a/src/bin/take-gifts-from-the-richest-pile.rs b/src/bin/take-gifts-from-the-richest-pile.rs index 286de01b..c79840c8 100644 --- a/src/bin/take-gifts-from-the-richest-pile.rs +++ b/src/bin/take-gifts-from-the-richest-pile.rs @@ -1,9 +1,5 @@ #![allow(dead_code, unused, unused_variables, non_snake_case)] -extern crate core; - -use core::f64; - fn main() {} struct Solution; From fbbe3d246325840f41ba91436cf1e0ff295bb11c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 29 Oct 2023 22:17:20 +0800 Subject: [PATCH 1055/1556] src/bin/find-pivot-index.rs --- src/bin/find-pivot-index.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/bin/find-pivot-index.rs diff --git a/src/bin/find-pivot-index.rs b/src/bin/find-pivot-index.rs new file mode 100644 index 00000000..7c74927e --- /dev/null +++ b/src/bin/find-pivot-index.rs @@ -0,0 +1,22 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn pivot_index(nums: Vec) -> i32 { + let sum: i32 = nums.iter().sum(); + let mut s = 0; + + for i in 0..nums.len() { + if sum - nums[i] - s == s { + return i as i32; + } + + s += nums[i]; + } + + -1 + } +} From c1b1d95f959f1076d64637d0e85a2bff89cfd6af Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 29 Oct 2023 22:17:20 +0800 Subject: [PATCH 1056/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 101c1fc1..7e067519 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 573 | 241 | 304 | 28 | +| 574 | 242 | 304 | 28 | ### 题目 @@ -280,6 +280,7 @@ |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | |718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | |722 | 删除注释 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-comments.rs) | [leetcode](https://leetcode-cn.com/problems/remove-comments/) | Medium | +|724 | 寻找数组的中心下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-pivot-index.rs) | [leetcode](https://leetcode-cn.com/problems/find-pivot-index/) | Easy | |739 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/daily-temperatures.rs) | [leetcode](https://leetcode-cn.com/problems/daily-temperatures/) | Medium | |742 | 转换成小写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/to-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/to-lower-case/) | Easy | |782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | From 2ccdbfe5bb968341796b55676a6874b92af2afd9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 30 Oct 2023 21:47:54 +0800 Subject: [PATCH 1057/1556] src/bin/h-index-ii.rs --- src/bin/h-index-ii.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/h-index-ii.rs diff --git a/src/bin/h-index-ii.rs b/src/bin/h-index-ii.rs new file mode 100644 index 00000000..b5e5ea79 --- /dev/null +++ b/src/bin/h-index-ii.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn h_index(citations: Vec) -> i32 { + // 在区间 (left, right] 内询问 + let n = citations.len(); + let mut left = 0; + let mut right = n; + while left < right { + // 区间不为空 + // 循环不变量: + // left 的回答一定为「是」 + // right+1 的回答一定为「否」 + let mid = (left + right + 1) / 2; // 保证 mid 在二分区间内 + // 引用次数最多的 mid 篇论文,引用次数均 >= mid + if citations[n - mid] >= mid as i32 { + left = mid; // 询问范围缩小到 (mid, right] + } else { + right = mid - 1; // 询问范围缩小到 (left, mid-1] + } + } + // 根据循环不变量,left 现在是最大的回答为「是」的数 + left as i32 + } +} From 3686726ded83dd35e18273a2d1e5a14911692d5f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 30 Oct 2023 21:47:54 +0800 Subject: [PATCH 1058/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e067519..64f981f2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 574 | 242 | 304 | 28 | +| 575 | 242 | 305 | 28 | ### 题目 @@ -181,6 +181,7 @@ |263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | Easy | |268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | Easy | |274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Medium | +|275 | H 指数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index-ii.rs) | [leetcode](https://leetcode-cn.com/problems/h-index-ii/) | Medium | |278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | |279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | |283 | 移动零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/move-zeroes/) | Easy | From a0efdb693fec88a920427aa4e683fb05848c8410 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 31 Oct 2023 21:23:42 +0800 Subject: [PATCH 1059/1556] src/bin/reverse-string-ii.rs --- src/bin/reverse-string-ii.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/reverse-string-ii.rs diff --git a/src/bin/reverse-string-ii.rs b/src/bin/reverse-string-ii.rs new file mode 100644 index 00000000..25ab887b --- /dev/null +++ b/src/bin/reverse-string-ii.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn reverse_str(s: String, k: i32) -> String { + let mut s = s; + let mut start = 0; + unsafe { + let mut d = s.as_bytes_mut(); + while start < d.len() { + let mut b = (start + k as usize - 1).min(d.len() - 1); + let mut a = start; + d[a..=b].reverse(); + + start += 2 * k as usize; + } + } + + s + } +} From 81d94a2f720d59a2b5617d276b3d6e45f8cf65bc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 31 Oct 2023 21:23:43 +0800 Subject: [PATCH 1060/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 64f981f2..44532306 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 575 | 242 | 305 | 28 | +| 576 | 243 | 305 | 28 | ### 题目 @@ -259,6 +259,7 @@ |530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | |535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | |538 | 把二叉搜索树转换为累加树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-bst-to-greater-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-bst-to-greater-tree/) | Medium | +|541 | 反转字符串 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string-ii/) | Easy | |543 | 二叉树的直径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diameter-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/diameter-of-binary-tree/) | Easy | |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |560 | 和为 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | From 647398a620bd6c0f33295d0ca40a2e3043799c9f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Nov 2023 20:46:29 +0800 Subject: [PATCH 1061/1556] src/bin/greatest-english-letter-in-upper-and-lower-case.rs --- ...-english-letter-in-upper-and-lower-case.rs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/bin/greatest-english-letter-in-upper-and-lower-case.rs diff --git a/src/bin/greatest-english-letter-in-upper-and-lower-case.rs b/src/bin/greatest-english-letter-in-upper-and-lower-case.rs new file mode 100644 index 00000000..987edb90 --- /dev/null +++ b/src/bin/greatest-english-letter-in-upper-and-lower-case.rs @@ -0,0 +1,39 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cmp::max; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn greatest_letter(s: String) -> String { + let mut r = "".to_owned(); + let mut v = vec![0u8; 26]; // 0代表没有,1代表小写,2代表大写 + + for i in 0..s.as_bytes().len() { + let m = s.as_bytes()[i]; + match m { + b'A'..=b'Z' => { + if v[(m - b'A') as usize] == 1 { + r = r.max(s.as_str()[i..i + 1].to_string()); + v[(m - b'A') as usize] = 3; + } else { + v[(m - b'A') as usize] = 2; + } + } + b'a'..=b'z' => { + if v[(m - b'a') as usize] == 2 { + r = r.max(s.as_str()[i..i + 1].to_string().to_uppercase()); + v[(m - b'a') as usize] = 3; + } else { + v[(m - b'a') as usize] = 1; + } + } + _ => unreachable!(), + } + } + + r + } +} From 25913137e83f4b4d71c72da01decbf124c7b8502 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 1 Nov 2023 20:46:30 +0800 Subject: [PATCH 1062/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 44532306..a62b6770 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 576 | 243 | 305 | 28 | +| 577 | 244 | 305 | 28 | ### 题目 @@ -347,6 +347,7 @@ |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | |1342 | 可以攻击国王的皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/queens-that-can-attack-the-king.rs) | [leetcode](https://leetcode-cn.com/problems/queens-that-can-attack-the-king/) | Medium | |1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | +|1363 | 兼具大小写的最好英文字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/greatest-english-letter-in-upper-and-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/greatest-english-letter-in-upper-and-lower-case/) | Easy | |1364 | 同积元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tuple-with-same-product.rs) | [leetcode](https://leetcode-cn.com/problems/tuple-with-same-product/) | Medium | |1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | |1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | From a17c6d05f40acd38046e15e354d5eea098b61992 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 2 Nov 2023 19:59:50 +0800 Subject: [PATCH 1063/1556] src/bin/rings-and-rods.rs --- src/bin/rings-and-rods.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/rings-and-rods.rs diff --git a/src/bin/rings-and-rods.rs b/src/bin/rings-and-rods.rs new file mode 100644 index 00000000..b371d1d5 --- /dev/null +++ b/src/bin/rings-and-rods.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_points(rings: String) -> i32 { + let mut v = vec![0; 10]; + + for i in (0..rings.len()).filter(|x| x % 2 == 1) { + let x: u8 = match rings.as_bytes()[i - 1] { + b'R' => 0b001, + b'G' => 0b010, + b'B' => 0b100, + _ => unreachable!(), + }; + + v[(rings.as_bytes()[i] - b'0') as usize] |= x; + } + + v.into_iter().filter(|x| *x & 0b111u8 == 0b111u8).count() as i32 + } +} From e9b11544cdb911d7a412269f4327e35d88ae3f01 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 2 Nov 2023 19:59:51 +0800 Subject: [PATCH 1064/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a62b6770..66e37946 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 577 | 244 | 305 | 28 | +| 578 | 245 | 305 | 28 | ### 题目 @@ -409,6 +409,7 @@ |2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | |2161 | 股票价格波动 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/stock-price-fluctuation.rs) | [leetcode](https://leetcode-cn.com/problems/stock-price-fluctuation/) | Medium | |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | +|2226 | 环和杆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rings-and-rods.rs) | [leetcode](https://leetcode-cn.com/problems/rings-and-rods/) | Easy | |2233 | 股票平滑下跌阶段的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-smooth-descent-periods-of-a-stock.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-smooth-descent-periods-of-a-stock/) | Medium | |2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | From 22e311fecd2f51a9f2d9f19831b912c1d5fcd344 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 4 Nov 2023 16:23:04 +0800 Subject: [PATCH 1065/1556] refactor(leetcode): use async --- Cargo.lock | 935 +++++++++++++++++++++++++++++++--------------------- Cargo.toml | 7 +- src/all.rs | 17 +- src/file.rs | 52 +-- src/git.rs | 12 +- src/http.rs | 30 +- src/lib.rs | 16 +- src/main.rs | 5 +- src/new.rs | 6 +- 9 files changed, 638 insertions(+), 442 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eca4603f..fb0eb65a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,22 +2,52 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aho-corasick" -version = "0.7.18" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" dependencies = [ "memchr", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] @@ -28,11 +58,26 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base64" -version = "0.13.0" +version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" [[package]] name = "bitflags" @@ -41,66 +86,50 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "block-buffer" -version = "0.7.3" +name = "bitflags" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" -dependencies = [ - "block-padding", - "byte-tools", - "byteorder", - "generic-array", -] +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] -name = "block-padding" -version = "0.1.5" +name = "block-buffer" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ - "byte-tools", + "generic-array", ] [[package]] name = "bstr" -version = "0.2.17" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +checksum = "c79ad7fb2dd38f3dabd76b09c6a5a20c038fc0213ef1e9afd30eb777f120f019" dependencies = [ "memchr", + "serde", ] [[package]] name = "bumpalo" -version = "3.10.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" - -[[package]] -name = "byte-tools" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" - -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" [[package]] name = "bytes" -version = "1.1.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" [[package]] name = "cc" -version = "1.0.73" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ "jobserver", + "libc", ] [[package]] @@ -111,21 +140,21 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.19" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ - "libc", - "num-integer", + "android-tzdata", + "iana-time-zone", "num-traits", - "winapi", + "windows-targets", ] [[package]] name = "chrono-tz" -version = "0.6.1" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58549f1842da3080ce63002102d5bc954c7bc843d4f47818e642abdc36253552" +checksum = "e23185c0e21df6ed832a12e2bda87c7d1def6842881fb634a8511ced741b0d76" dependencies = [ "chrono", "chrono-tz-build", @@ -134,9 +163,9 @@ dependencies = [ [[package]] name = "chrono-tz-build" -version = "0.0.2" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db058d493fb2f65f41861bfed7e3fe6335264a9f0f92710cab5bdf01fef09069" +checksum = "433e39f13c9a060046954e0592a8d0a4bcb1040125cbf91cb8ee58964cfb350f" dependencies = [ "parse-zoneinfo", "phf", @@ -145,12 +174,12 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.8" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", - "bitflags", + "bitflags 1.3.2", "clap_lex", "indexmap", "strsim", @@ -179,58 +208,78 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] -name = "crossbeam-utils" -version = "0.8.10" +name = "cpufeatures" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83" +checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" dependencies = [ - "cfg-if", - "once_cell", + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", ] [[package]] name = "deunicode" -version = "0.4.3" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71dbf1bf89c23e9cd1baf5e654f622872655f195b36588dc9dc38f7eda30758c" +dependencies = [ + "deunicode 1.4.1", +] + +[[package]] +name = "deunicode" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690" +checksum = "6a1abaf4d861455be59f64fd2b55606cb151fce304ede7165f410243ce96bde6" [[package]] name = "digest" -version = "0.8.1" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "generic-array", + "block-buffer", + "crypto-common", ] [[package]] name = "encoding_rs" -version = "0.8.31" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" dependencies = [ "cfg-if", ] [[package]] -name = "fake-simd" -version = "0.1.2" +name = "errno" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" +dependencies = [ + "libc", + "windows-sys", +] [[package]] name = "fastrand" -version = "1.7.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" -dependencies = [ - "instant", -] +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "fnv" @@ -255,89 +304,86 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.0.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" dependencies = [ - "matches", "percent-encoding", ] [[package]] name = "futures-channel" -version = "0.3.21" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" - -[[package]] -name = "futures-io" -version = "0.3.21" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" +checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" [[package]] name = "futures-sink" -version = "0.3.21" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" +checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" [[package]] name = "futures-task" -version = "0.3.21" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" +checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" [[package]] name = "futures-util" -version = "0.3.21" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" dependencies = [ "futures-core", - "futures-io", "futures-task", - "memchr", "pin-project-lite", "pin-utils", - "slab", ] [[package]] name = "generic-array" -version = "0.12.4" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", + "version_check", ] [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", "libc", "wasi", ] +[[package]] +name = "gimli" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" + [[package]] name = "git2" version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0155506aab710a86160ddb504a480d2964d7ab5b9e62419be69e0032bc5931c" dependencies = [ - "bitflags", + "bitflags 1.3.2", "libc", "libgit2-sys", "log", @@ -348,9 +394,9 @@ dependencies = [ [[package]] name = "globset" -version = "0.4.9" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a" +checksum = "759c97c1e17c55525b57192c06a267cda0ac5210b222d6b82189a2338fa1c13d" dependencies = [ "aho-corasick", "bstr", @@ -365,16 +411,16 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc" dependencies = [ - "bitflags", + "bitflags 1.3.2", "ignore", "walkdir", ] [[package]] name = "h2" -version = "0.3.14" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" +checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" dependencies = [ "bytes", "fnv", @@ -391,9 +437,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "607c8a29735385251a339424dd462993c0fed8fa09d378f259377df08c126022" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hermit-abi" @@ -404,11 +450,17 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" + [[package]] name = "http" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" dependencies = [ "bytes", "fnv", @@ -428,27 +480,30 @@ dependencies = [ [[package]] name = "httparse" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "humansize" -version = "1.1.1" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02296996cb8796d7c6e3bc2d9211b7802812d36999a51bb754123ead7d37d026" +checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" +dependencies = [ + "libm", +] [[package]] name = "hyper" -version = "0.14.20" +version = "0.14.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" +checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" dependencies = [ "bytes", "futures-channel", @@ -461,7 +516,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.10", "tokio", "tower-service", "tracing", @@ -481,24 +536,45 @@ dependencies = [ "tokio-native-tls", ] +[[package]] +name = "iana-time-zone" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" -version = "0.2.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" dependencies = [ - "matches", "unicode-bidi", "unicode-normalization", ] [[package]] name = "ignore" -version = "0.4.18" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713f1b139373f96a2e0ce3ac931cd01ee973c3c5dd7c40c0c2efe96ad2b6751d" +checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492" dependencies = [ - "crossbeam-utils", "globset", "lazy_static", "log", @@ -512,49 +588,40 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.1" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown", ] -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - [[package]] name = "ipnet" -version = "2.5.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "jobserver" -version = "0.1.24" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af25a77299a7f711a01975c35a6a424eb6862092cc2d6c72c4ed6cbc56dfc1fa" +checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.58" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" +checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" dependencies = [ "wasm-bindgen", ] @@ -578,19 +645,21 @@ dependencies = [ "serde", "serde_json", "tera", + "tokio", + "tokio-stream", ] [[package]] name = "libc" -version = "0.2.126" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libgit2-sys" -version = "0.13.4+1.4.2" +version = "0.13.5+1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0fa6563431ede25f5cc7f6d803c6afbc1c5d3ad3d4925d12c882bf2b526f5d1" +checksum = "51e5ea06c26926f1002dd553fded6cfcdc9784c1f60feeb58368b4d9b07b6dba" dependencies = [ "cc", "libc", @@ -600,6 +669,12 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + [[package]] name = "libssh2-sys" version = "0.2.23" @@ -616,9 +691,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.8" +version = "1.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" +checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b" dependencies = [ "cc", "libc", @@ -627,55 +702,54 @@ dependencies = [ ] [[package]] -name = "log" -version = "0.4.17" +name = "linux-raw-sys" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" [[package]] -name = "maplit" -version = "1.0.2" +name = "log" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] -name = "matches" -version = "0.1.9" +name = "memchr" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] -name = "memchr" -version = "2.5.0" +name = "mime" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] -name = "mime" -version = "0.3.16" +name = "miniz_oxide" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] [[package]] name = "mio" -version = "0.8.4" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" +checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" dependencies = [ "libc", - "log", "wasi", "windows-sys", ] [[package]] name = "native-tls" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" dependencies = [ "lazy_static", "libc", @@ -689,54 +763,47 @@ dependencies = [ "tempfile", ] -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] [[package]] name = "num_cpus" -version = "1.13.1" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi", + "hermit-abi 0.3.3", "libc", ] [[package]] -name = "once_cell" -version = "1.13.0" +name = "object" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +dependencies = [ + "memchr", +] [[package]] -name = "opaque-debug" -version = "0.2.3" +name = "once_cell" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "openssl" -version = "0.10.41" +version = "0.10.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" +checksum = "7a257ad03cd8fb16ad4172fedf8094451e1af1c4b70097636ef2eac9a5f0cc33" dependencies = [ - "bitflags", + "bitflags 2.4.1", "cfg-if", "foreign-types", "libc", @@ -747,9 +814,9 @@ dependencies = [ [[package]] name = "openssl-macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", @@ -764,11 +831,10 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.75" +version = "0.9.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" +checksum = "40a4130519a360279579c2053038317e40eff64d13fd3f004f9e1b72b8a6aaf9" dependencies = [ - "autocfg", "cc", "libc", "pkg-config", @@ -777,9 +843,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.1.0" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "parse-zoneinfo" @@ -792,24 +858,26 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.1.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pest" -version = "2.1.3" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +checksum = "ae9cee2a55a544be8b89dc6848072af97a20f2422603c10865be2a42b580fff5" dependencies = [ + "memchr", + "thiserror", "ucd-trie", ] [[package]] name = "pest_derive" -version = "2.1.0" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" +checksum = "81d78524685f5ef2a3b3bd1cafbc9fcabb036253d9b1463e726a91cd16e2dfc2" dependencies = [ "pest", "pest_generator", @@ -817,9 +885,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.1.3" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" +checksum = "68bd1206e71118b5356dae5ddc61c8b11e28b09ef6a31acbd15ea48a28e0c227" dependencies = [ "pest", "pest_meta", @@ -830,29 +898,29 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.1.3" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" +checksum = "7c747191d4ad9e4a4ab9c8798f1e82a39affe7ef9648390b7e5548d18e099de6" dependencies = [ - "maplit", + "once_cell", "pest", - "sha-1", + "sha2", ] [[package]] name = "phf" -version = "0.10.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ "phf_shared", ] [[package]] name = "phf_codegen" -version = "0.10.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" dependencies = [ "phf_generator", "phf_shared", @@ -860,9 +928,9 @@ dependencies = [ [[package]] name = "phf_generator" -version = "0.10.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" dependencies = [ "phf_shared", "rand", @@ -870,19 +938,18 @@ dependencies = [ [[package]] name = "phf_shared" -version = "0.10.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +checksum = "90fcb95eef784c2ac79119d1dd819e162b5da872ce6f3c3abe1e8ca1c082f72b" dependencies = [ "siphasher", - "uncased", ] [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -892,30 +959,30 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.25" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "ppv-lite86" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.40" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.20" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -943,53 +1010,56 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] [[package]] name = "redox_syscall" -version = "0.2.13" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] name = "regex" -version = "1.6.0" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", + "regex-automata", "regex-syntax", ] [[package]] -name = "regex-syntax" -version = "0.6.27" +name = "regex-automata" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] [[package]] -name = "remove_dir_all" -version = "0.5.3" +name = "regex-syntax" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.11" +version = "0.11.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" +checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ "base64", "bytes", @@ -1003,15 +1073,16 @@ dependencies = [ "hyper-tls", "ipnet", "js-sys", - "lazy_static", "log", "mime", "native-tls", + "once_cell", "percent-encoding", "pin-project-lite", "serde", "serde_json", "serde_urlencoded", + "system-configuration", "tokio", "tokio-native-tls", "tower-service", @@ -1022,11 +1093,30 @@ dependencies = [ "winreg", ] +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "rustix" +version = "0.38.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" +dependencies = [ + "bitflags 2.4.1", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" -version = "1.0.10" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "same-file" @@ -1039,21 +1129,20 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.20" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "lazy_static", "windows-sys", ] [[package]] name = "security-framework" -version = "2.6.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -1062,9 +1151,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.6.1" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" dependencies = [ "core-foundation-sys", "libc", @@ -1072,18 +1161,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.139" +version = "1.0.190" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0171ebb889e45aa68b44aee0859b3eede84c6f5f5c228e6f140c0b2a0a46cad6" +checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.139" +version = "1.0.190" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1d3230c1de7932af58ad8ffbe1d784bd55efd5a9d84ac24f69c72d83543dfb" +checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" dependencies = [ "proc-macro2", "quote", @@ -1092,9 +1181,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.82" +version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" dependencies = [ "itoa", "ryu", @@ -1114,28 +1203,30 @@ dependencies = [ ] [[package]] -name = "sha-1" -version = "0.8.2" +name = "sha2" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ - "block-buffer", + "cfg-if", + "cpufeatures", "digest", - "fake-simd", - "opaque-debug", ] [[package]] name = "siphasher" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" [[package]] name = "slab" -version = "0.4.6" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] [[package]] name = "slug" @@ -1143,19 +1234,29 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373" dependencies = [ - "deunicode", + "deunicode 0.4.5", ] [[package]] name = "socket2" -version = "0.4.4" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" dependencies = [ "libc", "winapi", ] +[[package]] +name = "socket2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "sort" version = "0.1.0" @@ -1168,34 +1269,54 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.98" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "tempfile" -version = "3.3.0" +version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" dependencies = [ "cfg-if", "fastrand", - "libc", "redox_syscall", - "remove_dir_all", - "winapi", + "rustix", + "windows-sys", ] [[package]] name = "tera" -version = "1.16.0" +version = "1.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c9783d6ff395ae80cf17ed9a25360e7ba37742a79fa8fddabb073c5c7c8856d" +checksum = "970dff17c11e884a4a09bc76e3a17ef71e01bb13447a11e85226e254fe6d10b8" dependencies = [ "chrono", "chrono-tz", @@ -1215,25 +1336,46 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.3" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" dependencies = [ "winapi-util", ] [[package]] name = "textwrap" -version = "0.15.0" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + +[[package]] +name = "thiserror" +version = "1.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] [[package]] name = "thread_local" -version = "1.1.4" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" dependencies = [ + "cfg-if", "once_cell", ] @@ -1248,43 +1390,64 @@ dependencies = [ [[package]] name = "tinyvec_macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.20.1" +version = "1.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" dependencies = [ - "autocfg", + "backtrace", "bytes", "libc", - "memchr", "mio", "num_cpus", - "once_cell", "pin-project-lite", - "socket2", - "winapi", + "socket2 0.5.5", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] name = "tokio-native-tls" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" dependencies = [ "native-tls", "tokio", ] +[[package]] +name = "tokio-stream" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "tokio-util" -version = "0.7.3" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", @@ -1302,50 +1465,40 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.35" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if", "pin-project-lite", "tracing-core", ] [[package]] name = "tracing-core" -version = "0.1.28" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", ] [[package]] name = "try-lock" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "typenum" -version = "1.15.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ucd-trie" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89570599c4fe5585de2b388aab47e99f7fa4e9238a1399f707a02e356058141c" - -[[package]] -name = "uncased" -version = "0.9.7" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09b01702b0fd0b3fadcf98e098780badda8742d4f4a7676615cad90e8ac73622" -dependencies = [ - "version_check", -] +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] name = "unic-char-property" @@ -1399,34 +1552,33 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.1" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] [[package]] name = "url" -version = "2.2.2" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", "idna", - "matches", "percent-encoding", ] @@ -1444,22 +1596,20 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "walkdir" -version = "2.3.2" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" dependencies = [ "same-file", - "winapi", "winapi-util", ] [[package]] name = "want" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ - "log", "try-lock", ] @@ -1471,9 +1621,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.81" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" +checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1481,13 +1631,13 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.81" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" +checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" dependencies = [ "bumpalo", - "lazy_static", "log", + "once_cell", "proc-macro2", "quote", "syn", @@ -1496,9 +1646,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.31" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f" +checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" dependencies = [ "cfg-if", "js-sys", @@ -1508,9 +1658,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.81" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" +checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1518,9 +1668,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.81" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" +checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" dependencies = [ "proc-macro2", "quote", @@ -1531,15 +1681,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.81" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" +checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" [[package]] name = "web-sys" -version = "0.3.58" +version = "0.3.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" +checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" dependencies = [ "js-sys", "wasm-bindgen", @@ -1563,9 +1713,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi", ] @@ -1576,54 +1726,87 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.51.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" -version = "0.36.1" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ + "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_msvc", "windows_x86_64_gnu", + "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_msvc" -version = "0.36.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.36.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.36.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.36.1" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.36.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winreg" -version = "0.10.1" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "winapi", + "cfg-if", + "windows-sys", ] diff --git a/Cargo.toml b/Cargo.toml index 74020d0f..234b6fa5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ members = ["./sort"] [dependencies] git2 = "0.14.4" -reqwest = { version = "0.11.11", features = ["blocking", "json"] } +reqwest = { version = "0.11.11", features = ["json"] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } clap = "3.0.0-beta.2" @@ -18,8 +18,13 @@ tera = "1.12.1" lazy_static = "1.4.0" regex = "1" rand = "0.8.4" +tokio = { version = "1.33.0", features = ["fs", "macros", "rt-multi-thread"] } +tokio-stream = { version = "0.1.14", features = ["fs"] } [[bin]] name = "leetcode" path = "src/main.rs" + +[dev-dependencies] +tokio = { version = "1.33.0", features = ["macros", "rt"] } diff --git a/src/all.rs b/src/all.rs index 5680c96d..f45118da 100644 --- a/src/all.rs +++ b/src/all.rs @@ -1,12 +1,11 @@ -use crate::file; +use std::sync::{Arc, Mutex}; +use crate::file; use crate::http::Resp; -use std::sync::{Arc, Mutex}; -use std::thread; /// 重新格式化 -pub fn all() { - let files = file::get_all_bin_file(); +pub async fn all() { + let files = file::get_all_bin_file().await; let v = Vec::::with_capacity(files.len()); @@ -23,18 +22,18 @@ pub fn all() { let x = x.clone(); - handlers.push(thread::spawn(move || { + handlers.push(tokio::spawn(async move { for i in files { println!("{} downloading", i); - let resp = crate::http::get_question_info(&i); + let resp = crate::http::get_question_info(&i).await; x.lock().unwrap().push(resp); } })) } for i in handlers { - i.join().unwrap(); + i.await.unwrap(); } - crate::file::write_readme(&mut *x.lock().unwrap()); + file::write_readme(&mut *x.lock().unwrap()).await; } diff --git a/src/file.rs b/src/file.rs index 22b04648..caec830c 100644 --- a/src/file.rs +++ b/src/file.rs @@ -1,7 +1,9 @@ use lazy_static::lazy_static; use regex::Regex; -use std::fs::{self, File}; -use std::io::Write; +use tokio::fs::{self, File}; +use tokio::io::AsyncWriteExt; +use tokio_stream::wrappers::ReadDirStream; +use tokio_stream::StreamExt; use crate::http::{Data, Difficulty, Ques, Resp}; @@ -12,7 +14,7 @@ lazy_static! { } /// 将结果写入README.md中 -pub fn write_readme(r: &mut Vec) { +pub async fn write_readme(r: &mut Vec) { // 先按id排序 r.sort_by(|x, y| { let x_id = x.data.question.question_id.parse::().unwrap(); @@ -21,36 +23,39 @@ pub fn write_readme(r: &mut Vec) { }); let s = crate::render::render(r).unwrap(); - match std::fs::write("README.md", s) { + match tokio::fs::write("README.md", s).await { Ok(_) => (), Err(e) => eprintln!("写入 README.md 失败,err{}", e.to_string()), } } /// 获取 src/bin 目录下所有文件的名称 -pub fn get_all_bin_file() -> Vec { - let dir = fs::read_dir("src/bin/").unwrap(); - dir.into_iter() - .map(|x| { +pub async fn get_all_bin_file() -> Vec { + let mut dir = ReadDirStream::new(fs::read_dir("src/bin/").await.unwrap()); + let mut v = vec![]; + while let Some(x) = dir.next().await { + v.push( x.unwrap() .file_name() .to_str() .unwrap() .trim_end_matches(".rs") - .to_string() - }) - .collect() + .to_string(), + ); + } + + v } /// 创建 bin/{quest_name}.rs 文件 -pub fn write_question(resp: Resp) { +pub async fn write_question(resp: Resp) { let file = format!("src/bin/{}.rs", resp.data.question.title_slug); if std::path::Path::new(file.as_str()).exists() { eprintln!("{} exists", file); return; } - let mut f = File::create(file.as_str()).unwrap(); + let mut f = File::create(file.as_str()).await.unwrap(); let mut s = String::new(); s.push_str("#![allow(dead_code, unused, unused_variables, non_snake_case)]\n\n"); s.push_str("fn main() {}\n\n"); @@ -64,12 +69,12 @@ pub fn write_question(resp: Resp) { } } - f.write_all(s.as_bytes()).unwrap(); + f.write_all(s.as_bytes()).await.unwrap(); } /// 解析README.md -pub fn parse_readme() -> Vec { - let contents = fs::read_to_string("README.md").unwrap(); +pub async fn parse_readme() -> Vec { + let contents = fs::read_to_string("README.md").await.unwrap(); parse(&contents) } @@ -96,11 +101,12 @@ fn parse(contents: &str) -> Vec { #[cfg(test)] mod tests { - use crate::file::{get_all_bin_file, parse}; + use super::get_all_bin_file; + use super::parse; - #[test] - fn test_parse_readme() { - let contents = std::fs::read_to_string("README.md").unwrap(); + #[tokio::test] + async fn test_parse_readme() { + let contents = tokio::fs::read_to_string("README.md").await.unwrap(); let x = parse(&contents); println!("{:?}", x); println!("{}", x.len()); @@ -116,8 +122,8 @@ mod tests { } } - #[test] - fn test_get_all_bin_file() { - println!("{:?}", get_all_bin_file()); + #[tokio::test] + async fn test_get_all_bin_file() { + println!("{:?}", get_all_bin_file().await); } } diff --git a/src/git.rs b/src/git.rs index ef446c82..3e6a8f27 100644 --- a/src/git.rs +++ b/src/git.rs @@ -1,20 +1,20 @@ -use git2::{Repository, StatusOptions}; - use std::process::Command; +use git2::{Repository, StatusOptions}; + /// 把新文件加入到git中 -pub fn push() { +pub async fn push() { // 解析readme.md文件 - let mut r = crate::file::parse_readme(); + let mut r = crate::file::parse_readme().await; let new_file = get_uncommit_files(); for i in new_file.iter() { let x = i.trim_end_matches(".rs"); // 去掉后缀 let x = x.trim_start_matches("src/bin/"); // 去掉路径 git_add(i); - r.push(crate::http::get_question_info(x)); + r.push(crate::http::get_question_info(x).await); } - crate::file::write_readme(&mut r); + crate::file::write_readme(&mut r).await; git_add("README.md"); push_to_origin(); } diff --git a/src/http.rs b/src/http.rs index f7aaa113..251e46e9 100644 --- a/src/http.rs +++ b/src/http.rs @@ -2,9 +2,9 @@ use std::fmt; use lazy_static::lazy_static; use regex::Regex; -use reqwest::blocking::Client; -use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use reqwest::Client; use serde::de::{Error, Visitor}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; lazy_static! { static ref RE: Regex = Regex::new(r".*?/problems/(.*?)/").unwrap(); @@ -32,8 +32,8 @@ impl Difficulty { impl Serialize for Difficulty { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, + where + S: Serializer, { match self { Self::Easy => serializer.serialize_str("Easy"), @@ -45,8 +45,8 @@ impl Serialize for Difficulty { impl<'de> Deserialize<'de> for Difficulty { fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, + where + D: Deserializer<'de>, { struct DifficultyVisitor; @@ -58,8 +58,8 @@ impl<'de> Deserialize<'de> for Difficulty { } fn visit_str(self, v: &str) -> Result - where - E: Error, + where + E: Error, { match v { "Easy" => Ok(Self::Value::Easy), @@ -110,7 +110,7 @@ pub struct Resp { pub data: Data, } -pub fn get_question_info(mut ques: &str) -> Resp { +pub async fn get_question_info(mut ques: &str) -> Resp { if ques.starts_with("http") { ques = RE .captures_iter(ques) @@ -131,21 +131,23 @@ pub fn get_question_info(mut ques: &str) -> Resp { .header("content-type", "application/json") .body(data) .send() + .await .unwrap() .json::() + .await .expect(format!("{} download failed", ques).as_str()) } #[cfg(test)] mod tests { - use crate::http::get_question_info; + use super::get_question_info; - #[test] - fn test_get_question_info() { - println!("{:?}", get_question_info("container-with-most-water")); + #[tokio::test] + async fn test_get_question_info() { + println!("{:?}", get_question_info("container-with-most-water").await); println!( "{:?}", - get_question_info("https://leetcode-cn.com/problems/container-with-most-water/") + get_question_info("https://leetcode-cn.com/problems/container-with-most-water/").await ); } } diff --git a/src/lib.rs b/src/lib.rs index d31caef7..5b844605 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,7 @@ +use std::process; + +use clap::{App, Arg}; + mod all; mod file; mod git; @@ -5,11 +9,7 @@ mod http; mod new; mod render; -use clap::{App, Arg}; - -use std::process; - -pub fn run() { +pub async fn run() { let matches = App::new("leetcode") .version("0.0.1") .author("bestgopher <84328409@qq.com>") @@ -26,15 +26,15 @@ pub fn run() { if let Some(matches) = matches.subcommand_matches("new") { match matches.value_of_t::("question_name") { - Ok(x) => new::new(x), + Ok(x) => new::new(x).await, Err(_) => { eprintln!("please input the name of question"); process::exit(1); } } } else if matches.subcommand_matches("all").is_some() { - all::all(); + all::all().await; } else { - git::push(); + git::push().await; } } diff --git a/src/main.rs b/src/main.rs index 68ec8695..4748a86a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ -fn main() { - leetcode::run(); +#[tokio::main] +async fn main() { + leetcode::run().await; } diff --git a/src/new.rs b/src/new.rs index 9b1599ac..aacf7b54 100644 --- a/src/new.rs +++ b/src/new.rs @@ -2,7 +2,7 @@ /// 2.如果name是url,就不需要拼装,不是就需要拼装 /// 3.请求结构,获取数据 /// 4.将数据写入bin/{question_name}.rs文件中 -pub fn new(ques: String) { - let r = crate::http::get_question_info(ques.as_str()); - crate::file::write_question(r); +pub async fn new(ques: String) { + let r = crate::http::get_question_info(ques.as_str()).await; + crate::file::write_question(r).await; } From a11addf12cf298bb0690de021ebd2699f518a48a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 5 Nov 2023 10:33:29 +0800 Subject: [PATCH 1066/1556] src/bin/maximum-units-on-a-truck.rs --- src/bin/maximum-units-on-a-truck.rs | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/maximum-units-on-a-truck.rs diff --git a/src/bin/maximum-units-on-a-truck.rs b/src/bin/maximum-units-on-a-truck.rs new file mode 100644 index 00000000..e8ab924d --- /dev/null +++ b/src/bin/maximum-units-on-a-truck.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_units(box_types: Vec>, truck_size: i32) -> i32 { + let mut box_types = box_types; + box_types.sort_unstable_by(|x, y| { + use std::cmp::Ordering; + match x[1].cmp(&y[1]) { + Ordering::Equal => {} + x => return x.reverse(), + } + + x[0].cmp(&y[1]).reverse() + }); + + let mut r = 0; + let mut truck_size = truck_size; + + for box_type in box_types { + if box_type[0] >= truck_size { + r += truck_size * box_type[1]; + break; + } else { + r += box_type[0] * box_type[1]; + truck_size -= box_type[0]; + } + } + + r + } +} From b3341e5b0a3a2a3de069d7102024d0e4cfaad961 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 5 Nov 2023 10:33:30 +0800 Subject: [PATCH 1067/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 66e37946..9dd21bfd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 578 | 245 | 305 | 28 | +| 579 | 246 | 305 | 28 | ### 题目 @@ -393,6 +393,7 @@ |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | |1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | +|1829 | 卡车上的最大单元数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-units-on-a-truck.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-units-on-a-truck/) | Easy | |1849 | 任意子数组和的绝对值的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-absolute-sum-of-any-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | |1858 | 替换隐藏数字得到的最晚时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/latest-time-by-replacing-hidden-digits.rs) | [leetcode](https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits/) | Easy | |1894 | 交替合并字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-strings-alternately.rs) | [leetcode](https://leetcode-cn.com/problems/merge-strings-alternately/) | Easy | From 1b0389f88dc69df3643a6f006865eaa2c0d684fb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 Nov 2023 08:15:14 +0800 Subject: [PATCH 1068/1556] src/bin/minimum-number-of-operations-to-make-array-empty.rs --- ...umber-of-operations-to-make-array-empty.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/minimum-number-of-operations-to-make-array-empty.rs diff --git a/src/bin/minimum-number-of-operations-to-make-array-empty.rs b/src/bin/minimum-number-of-operations-to-make-array-empty.rs new file mode 100644 index 00000000..1f55eaea --- /dev/null +++ b/src/bin/minimum-number-of-operations-to-make-array-empty.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_operations(nums: Vec) -> i32 { + let mut hash = std::collections::HashMap::new(); + for i in nums { + hash.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + let mut r = 0; + + for (_, v) in hash { + if v == 1 { + return -1; + } + + if v % 3 == 0 { + r += v / 3; + } else { + r += v / 3 + 1; + } + } + + r + } +} From 71d70e40e3fef80218afbf7f2b20a03489130ab8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 Nov 2023 08:15:15 +0800 Subject: [PATCH 1069/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9dd21bfd..72747a04 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 579 | 246 | 305 | 28 | +| 580 | 246 | 306 | 28 | ### 题目 @@ -461,6 +461,7 @@ |2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | +|3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | From 58901203df74b2616cca336116e5ef3bc698c5f1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 7 Nov 2023 19:45:45 +0800 Subject: [PATCH 1070/1556] src/bin/count-the-number-of-vowel-strings-in-range.rs --- .../count-the-number-of-vowel-strings-in-range.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/bin/count-the-number-of-vowel-strings-in-range.rs diff --git a/src/bin/count-the-number-of-vowel-strings-in-range.rs b/src/bin/count-the-number-of-vowel-strings-in-range.rs new file mode 100644 index 00000000..0b74a1a3 --- /dev/null +++ b/src/bin/count-the-number-of-vowel-strings-in-range.rs @@ -0,0 +1,15 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn vowel_strings(words: Vec, left: i32, right: i32) -> i32 { + words[left as usize..=right as usize] + .into_iter() + .filter(|x| x.starts_with(|x| matches!(x, 'a' | 'e' | 'i' | 'o' | 'u'))) + .filter(|x| x.ends_with(|x| matches!(x, 'a' | 'e' | 'i' | 'o' | 'u'))) + .count() as i32 + } +} From 2af8b19df7c527301f69661db363d2f3cfb2f84f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 7 Nov 2023 19:45:46 +0800 Subject: [PATCH 1071/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 72747a04..bd597276 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 580 | 246 | 306 | 28 | +| 581 | 247 | 306 | 28 | ### 题目 @@ -439,6 +439,7 @@ |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2645 | 递枕头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pass-the-pillow.rs) | [leetcode](https://leetcode-cn.com/problems/pass-the-pillow/) | Easy | |2650 | 最小和分割 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-with-minimum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/split-with-minimum-sum/) | Easy | +|2654 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-the-number-of-vowel-strings-in-range.rs) | [leetcode](https://leetcode-cn.com/problems/count-the-number-of-vowel-strings-in-range/) | Easy | |2662 | 检查骑士巡视方案 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-knight-tour-configuration.rs) | [leetcode](https://leetcode-cn.com/problems/check-knight-tour-configuration/) | Medium | |2663 | 将钱分给最多的儿童 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-money-to-maximum-children.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-money-to-maximum-children/) | Easy | |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | From c29fc3fa96e2a2f161ea86001a3a54ec7a6e6376 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 8 Nov 2023 07:55:21 +0800 Subject: [PATCH 1072/1556] src/bin/find-the-longest-balanced-substring-of-a-binary-string.rs --- ...t-balanced-substring-of-a-binary-string.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/find-the-longest-balanced-substring-of-a-binary-string.rs diff --git a/src/bin/find-the-longest-balanced-substring-of-a-binary-string.rs b/src/bin/find-the-longest-balanced-substring-of-a-binary-string.rs new file mode 100644 index 00000000..fbd2d4bb --- /dev/null +++ b/src/bin/find-the-longest-balanced-substring-of-a-binary-string.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_the_longest_balanced_substring(s: String) -> i32 { + let mut max = 0; + let mut zero_num = 0; + let mut one_num = 0; + for &i in s.as_bytes() { + match i { + b'0' => { + if one_num != 0 { + one_num = 0; + zero_num = 0; + } + zero_num += 1; + } + b'1' => { + if one_num < zero_num { + one_num += 1; + } else { + zero_num = 0; + } + + max = max.max(one_num.min(zero_num) * 2); + } + _ => unreachable!(), + } + } + + max + } +} From 497fbd66d293db8114ee335277a26ad7eb2354ab Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 8 Nov 2023 07:55:22 +0800 Subject: [PATCH 1073/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bd597276..759c2087 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 581 | 247 | 306 | 28 | +| 582 | 248 | 306 | 28 | ### 题目 @@ -452,6 +452,7 @@ |2694 | 找出可整除性得分最大的整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-divisibility-score.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-divisibility-score/) | Easy | |2698 | 找出数组的串联值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-array-concatenation-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-array-concatenation-value/) | Easy | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | +|2723 | 最长平衡子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-longest-balanced-substring-of-a-binary-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-longest-balanced-substring-of-a-binary-string/) | Easy | |2727 | 老人的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-senior-citizens.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-senior-citizens/) | Easy | |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | |2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | From cf99fda1c9433b64a1f8bf0839227dd01f3cc9e6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 9 Nov 2023 08:33:14 +0800 Subject: [PATCH 1074/1556] src/bin/removing-stars-from-a-string.rs --- src/bin/removing-stars-from-a-string.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/removing-stars-from-a-string.rs diff --git a/src/bin/removing-stars-from-a-string.rs b/src/bin/removing-stars-from-a-string.rs new file mode 100644 index 00000000..92ede0e0 --- /dev/null +++ b/src/bin/removing-stars-from-a-string.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn remove_stars(s: String) -> String { + let mut stack = vec![]; + for &i in s.as_bytes() { + if i == b'*' { + stack.pop(); + } else { + stack.push(i); + } + } + + String::from_utf8(stack).unwrap() + } +} From 677afb659ab1174c7fa76516273625e56ea1b9c8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 9 Nov 2023 08:33:15 +0800 Subject: [PATCH 1075/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 759c2087..f7f903bf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 582 | 248 | 306 | 28 | +| 583 | 248 | 307 | 28 | ### 题目 @@ -423,6 +423,7 @@ |2386 | 极大极小游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-max-game.rs) | [leetcode](https://leetcode-cn.com/problems/min-max-game/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | +|2470 | 从字符串中移除星号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-stars-from-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/removing-stars-from-a-string/) | Medium | |2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | From 8a03211d86745fa6e3d455ca657f46c7241d4b0e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 10 Nov 2023 08:04:45 +0800 Subject: [PATCH 1076/1556] src/bin/check-whether-two-strings-are-almost-equivalent.rs --- ...ether-two-strings-are-almost-equivalent.rs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/check-whether-two-strings-are-almost-equivalent.rs diff --git a/src/bin/check-whether-two-strings-are-almost-equivalent.rs b/src/bin/check-whether-two-strings-are-almost-equivalent.rs new file mode 100644 index 00000000..4485ff97 --- /dev/null +++ b/src/bin/check-whether-two-strings-are-almost-equivalent.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use tokio_stream::StreamExt; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn check_almost_equivalent(word1: String, word2: String) -> bool { + let mut v = vec![0i32; 26]; + + for &i in word1.as_bytes() { + v[(i - b'a') as usize] += 1; + } + + for &i in word2.as_bytes() { + v[(i - b'a') as usize] -= 1; + } + + v.into_iter().all(|x| x.abs() <= 3) + } +} From 80dde055836e0e6d4ef9bbd0e73dc740eb91e034 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 10 Nov 2023 08:04:45 +0800 Subject: [PATCH 1077/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f7f903bf..23ab4075 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 583 | 248 | 307 | 28 | +| 584 | 249 | 307 | 28 | ### 题目 @@ -409,6 +409,7 @@ |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | |2161 | 股票价格波动 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/stock-price-fluctuation.rs) | [leetcode](https://leetcode-cn.com/problems/stock-price-fluctuation/) | Medium | +|2177 | 检查两个字符串是否几乎相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-whether-two-strings-are-almost-equivalent.rs) | [leetcode](https://leetcode-cn.com/problems/check-whether-two-strings-are-almost-equivalent/) | Easy | |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | |2226 | 环和杆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rings-and-rods.rs) | [leetcode](https://leetcode-cn.com/problems/rings-and-rods/) | Easy | |2233 | 股票平滑下跌阶段的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-smooth-descent-periods-of-a-stock.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-smooth-descent-periods-of-a-stock/) | Medium | From 44ee1e1365eec03667527df48dfe9590d133f98c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 13 Nov 2023 13:10:40 +0800 Subject: [PATCH 1078/1556] src/bin/range-sum-query-mutable.rs --- src/bin/range-sum-query-mutable.rs | 97 ++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/bin/range-sum-query-mutable.rs diff --git a/src/bin/range-sum-query-mutable.rs b/src/bin/range-sum-query-mutable.rs new file mode 100644 index 00000000..ebdf797f --- /dev/null +++ b/src/bin/range-sum-query-mutable.rs @@ -0,0 +1,97 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::ptr::NonNull; + +fn main() {} + +struct Solution; + +struct NumArray { + nums: Vec, + segment_tree: Vec, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +/** + * Your NumArray object will be instantiated and called as such: + * let obj = NumArray::new(nums); + * obj.update(index, val); + * let ret_2: i32 = obj.sum_range(left, right); + */ +impl NumArray { + fn new(nums: Vec) -> Self { + let mut segment_tree = vec![0; nums.len() * 4]; + let mut num_array = Self { nums, segment_tree }; + + num_array.build(0, 0, num_array.nums.len() - 1); + num_array + } + + fn build(&mut self, tree_index: usize, l: usize, r: usize) { + if l == r { + self.segment_tree[tree_index] = self.nums[l]; + return; + } + + let left_tree_index = tree_index * 2 + 1; + let right_tree_index = tree_index * 2 + 2; + + let mid = l + (r - l) / 2; + self.build(left_tree_index, l, mid); + self.build(right_tree_index, mid + 1, r); + + self.segment_tree[tree_index] = + self.segment_tree[left_tree_index] + self.segment_tree[right_tree_index]; + } + + fn update(&mut self, index: i32, val: i32) { + let v = val - self.nums[index as usize]; + self.nums[index as usize] = val; + self.update_index(0, 0, self.nums.len() - 1, index as usize, v); + } + + fn update_index(&mut self, tree_index: usize, left_index: usize, right_index: usize, index: usize, val: i32) { + self.segment_tree[tree_index] += val; + if left_index == right_index { + return; + } + + let mid = left_index + (right_index - left_index) / 2; + if index <= mid { + self.update_index(tree_index*2+1, left_index, mid, index, val); + } else { + self.update_index(tree_index*2+2, mid + 1, right_index, index, val); + } + } + + fn sum_range(&self, left: i32, right: i32) -> i32 { + self.get_range(0, 0, self.nums.len() - 1, left as usize, right as usize) + } + + /// tree_index: 线段树的索引 + /// l: tree_index表示的左边界 + /// r: tree_index表示的右边界 + /// left: 查询的左边界 + /// right: 查询的右边界 + fn get_range(&self, tree_index: usize, l: usize, r: usize, left: usize, right: usize) -> i32 { + if left == l && right == r { + return self.segment_tree[tree_index]; + } + + let mid = l + (r - l) / 2; + let left_tree_index = tree_index * 2 + 1; + let right_tree_index = tree_index * 2 + 2; + + if left > mid { + return self.get_range(right_tree_index, mid + 1, r, left, right); + } else if right <= mid { + return self.get_range(left_tree_index, l, mid, left, right); + } else { + self.get_range(left_tree_index, l, mid, left, mid) + + self.get_range(right_tree_index, mid + 1, r, mid+1, right) + } + } +} From 5b216c93c6e8ad1f40b7d2ba72aaab0853bbe202 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 13 Nov 2023 13:10:41 +0800 Subject: [PATCH 1079/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 23ab4075..7b9fc0fe 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 584 | 249 | 307 | 28 | +| 585 | 249 | 308 | 28 | ### 题目 @@ -191,6 +191,7 @@ |297 | 二叉树的序列化与反序列化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree/) | Hard | |300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | |303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | +|307 | 区域和检索 - 数组可修改 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-mutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-mutable/) | Medium | |309 | 最佳买卖股票时机含冷冻期 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-with-cooldown.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/) | Medium | |318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | |319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | From 1755ca49abc3e33b26ac22c7bf316c6c8c202599 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 14 Nov 2023 21:39:30 +0800 Subject: [PATCH 1080/1556] src/bin/maximum-value-of-an-ordered-triplet-ii.rs --- .../maximum-value-of-an-ordered-triplet-ii.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/bin/maximum-value-of-an-ordered-triplet-ii.rs diff --git a/src/bin/maximum-value-of-an-ordered-triplet-ii.rs b/src/bin/maximum-value-of-an-ordered-triplet-ii.rs new file mode 100644 index 00000000..45e41af8 --- /dev/null +++ b/src/bin/maximum-value-of-an-ordered-triplet-ii.rs @@ -0,0 +1,22 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cmp::max; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_triplet_value(nums: Vec) -> i64 { + let mut max_diff = 0; + let mut ans = 0; + let mut pre_max = 0; + for x in nums { + ans = ans.max(x as i64 * max_diff as i64); + max_diff = max_diff.max(pre_max - x); + pre_max = pre_max.max(x); + } + + ans + } +} From ba6a8a40e0c736accbf3bf703d82a0578ee6aeaf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 14 Nov 2023 21:39:30 +0800 Subject: [PATCH 1081/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b9fc0fe..c7365844 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 585 | 249 | 308 | 28 | +| 586 | 249 | 309 | 28 | ### 题目 @@ -467,6 +467,7 @@ |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | |3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | +|3152 | 有序三元组中的最大值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-an-ordered-triplet-ii.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-an-ordered-triplet-ii/) | Medium | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | From 85fd05e0dd7145448e08d7fa5b0be46da429ad75 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 15 Nov 2023 18:17:38 +0800 Subject: [PATCH 1082/1556] src/bin/maximum-sum-with-exactly-k-elements.rs --- src/bin/maximum-sum-with-exactly-k-elements.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/bin/maximum-sum-with-exactly-k-elements.rs diff --git a/src/bin/maximum-sum-with-exactly-k-elements.rs b/src/bin/maximum-sum-with-exactly-k-elements.rs new file mode 100644 index 00000000..cc9a4e42 --- /dev/null +++ b/src/bin/maximum-sum-with-exactly-k-elements.rs @@ -0,0 +1,12 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximize_sum(nums: Vec, k: i32) -> i32 { + let max = nums.into_iter().max().unwrap(); + max * k + (k - 1) * k / 2 + } +} From 53374f211de264caa23a99774f3644190e76681a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 15 Nov 2023 18:17:39 +0800 Subject: [PATCH 1083/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c7365844..df359ce8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 586 | 249 | 309 | 28 | +| 587 | 250 | 309 | 28 | ### 题目 @@ -460,6 +460,7 @@ |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | |2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | |2752 | 倍数求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-multiples.rs) | [leetcode](https://leetcode-cn.com/problems/sum-multiples/) | Easy | +|2767 | K 个元素的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-with-exactly-k-elements.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-with-exactly-k-elements/) | Easy | |2787 | 移动机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/movement-of-robots.rs) | [leetcode](https://leetcode-cn.com/problems/movement-of-robots/) | Medium | |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | |2802 | 求一个整数的惩罚数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-punishment-number-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-punishment-number-of-an-integer/) | Medium | From 6281fc06c1ed7659886498837fa7f567824821a0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 16 Nov 2023 11:54:13 +0800 Subject: [PATCH 1084/1556] src/bin/longest-even-odd-subarray-with-threshold.rs --- ...ongest-even-odd-subarray-with-threshold.rs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bin/longest-even-odd-subarray-with-threshold.rs diff --git a/src/bin/longest-even-odd-subarray-with-threshold.rs b/src/bin/longest-even-odd-subarray-with-threshold.rs new file mode 100644 index 00000000..a6ae4724 --- /dev/null +++ b/src/bin/longest-even-odd-subarray-with-threshold.rs @@ -0,0 +1,37 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn longest_alternating_subarray(nums: Vec, threshold: i32) -> i32 { + let mut result = 0; + let mut index = 0; + let mut left_index = nums.len(); + while index < nums.len() { + if nums[index] > threshold { + index += 1; + left_index = nums.len(); + continue; + } + + if left_index == nums.len() { + if nums[index] % 2 == 0 { + left_index = index; + result = result.max(1); + } + index += 1; + } else { + if nums[index - 1] % 2 != nums[index] % 2 && nums[index] <= threshold { + result = result.max(index - left_index + 1); + index += 1; + } else { + left_index = nums.len(); + } + } + } + + result as i32 + } +} From 9b82e4004db61247633513c02b7cd2cc6699527e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 16 Nov 2023 11:54:13 +0800 Subject: [PATCH 1085/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index df359ce8..b614a1a3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 587 | 250 | 309 | 28 | +| 588 | 251 | 309 | 28 | ### 题目 @@ -466,6 +466,7 @@ |2802 | 求一个整数的惩罚数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-punishment-number-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-punishment-number-of-an-integer/) | Medium | |2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | +|2866 | 最长奇偶子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-even-odd-subarray-with-threshold.rs) | [leetcode](https://leetcode-cn.com/problems/longest-even-odd-subarray-with-threshold/) | Easy | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | |3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | |3152 | 有序三元组中的最大值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-an-ordered-triplet-ii.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-an-ordered-triplet-ii/) | Medium | From 1dd1644df1d09a44d765507f4c338a464f2b7374 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 16 Nov 2023 11:54:48 +0800 Subject: [PATCH 1086/1556] style: fmt some files --- src/bin/queens-that-can-attack-the-king.rs | 3 --- src/bin/range-sum-query-mutable.rs | 15 +++++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/bin/queens-that-can-attack-the-king.rs b/src/bin/queens-that-can-attack-the-king.rs index a9c92153..9050cb84 100644 --- a/src/bin/queens-that-can-attack-the-king.rs +++ b/src/bin/queens-that-can-attack-the-king.rs @@ -34,7 +34,6 @@ impl Solution { s += 1; } - let mut s = king[1]; while s >= 1 { if hash.contains(&vec![king[0], s - 1]) { @@ -63,7 +62,6 @@ impl Solution { s2 -= 1; } - let (mut s1, mut s2) = (king[0], king[1]); while s1 <= 6 && s2 <= 6 { if hash.contains(&vec![s1 + 1, s2 + 1]) { @@ -84,7 +82,6 @@ impl Solution { s2 += 1; } - let (mut s1, mut s2) = (king[0], king[1]); while s1 <= 6 && s2 >= 0 { if hash.contains(&vec![s1 + 1, s2 - 1]) { diff --git a/src/bin/range-sum-query-mutable.rs b/src/bin/range-sum-query-mutable.rs index ebdf797f..a968c3fb 100644 --- a/src/bin/range-sum-query-mutable.rs +++ b/src/bin/range-sum-query-mutable.rs @@ -53,7 +53,14 @@ impl NumArray { self.update_index(0, 0, self.nums.len() - 1, index as usize, v); } - fn update_index(&mut self, tree_index: usize, left_index: usize, right_index: usize, index: usize, val: i32) { + fn update_index( + &mut self, + tree_index: usize, + left_index: usize, + right_index: usize, + index: usize, + val: i32, + ) { self.segment_tree[tree_index] += val; if left_index == right_index { return; @@ -61,9 +68,9 @@ impl NumArray { let mid = left_index + (right_index - left_index) / 2; if index <= mid { - self.update_index(tree_index*2+1, left_index, mid, index, val); + self.update_index(tree_index * 2 + 1, left_index, mid, index, val); } else { - self.update_index(tree_index*2+2, mid + 1, right_index, index, val); + self.update_index(tree_index * 2 + 2, mid + 1, right_index, index, val); } } @@ -91,7 +98,7 @@ impl NumArray { return self.get_range(left_tree_index, l, mid, left, right); } else { self.get_range(left_tree_index, l, mid, left, mid) - + self.get_range(right_tree_index, mid + 1, r, mid+1, right) + + self.get_range(right_tree_index, mid + 1, r, mid + 1, right) } } } From a9a2dfb71648389d83654458a4bc38ab61a8dca4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 17 Nov 2023 14:19:45 +0800 Subject: [PATCH 1087/1556] src/bin/flipping-an-image.rs --- src/bin/flipping-an-image.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/flipping-an-image.rs diff --git a/src/bin/flipping-an-image.rs b/src/bin/flipping-an-image.rs new file mode 100644 index 00000000..0376031b --- /dev/null +++ b/src/bin/flipping-an-image.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn flip_and_invert_image(image: Vec>) -> Vec> { + let mut image = image; + for i in 0..image.len() { + let (mut s, mut m) = (0, image[0].len() - 1); + + while s <= m { + if s == m { + image[i][s] ^= 1; + break; + } + + image[i].swap(s, m); + image[i][s] ^= 1; + image[i][m] ^= 1; + s += 1; + m -= 1; + } + } + + image + } +} From c34e5cbb561454d215372f4a0002a1e1098236e4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 17 Nov 2023 14:19:46 +0800 Subject: [PATCH 1088/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c7365844..21862d77 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 586 | 249 | 309 | 28 | +| 587 | 250 | 309 | 28 | ### 题目 @@ -296,6 +296,7 @@ |842 | 翻转卡片游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/card-flipping-game.rs) | [leetcode](https://leetcode-cn.com/problems/card-flipping-game/) | Medium | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | +|861 | 翻转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/flipping-an-image.rs) | [leetcode](https://leetcode-cn.com/problems/flipping-an-image/) | Easy | |862 | 字符串中的查找与替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-and-replace-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-and-replace-in-string/) | Medium | |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | |879 | 到最近的人的最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximize-distance-to-closest-person.rs) | [leetcode](https://leetcode-cn.com/problems/maximize-distance-to-closest-person/) | Medium | From c72b9de029bb08c8c081d4847eccb9e607aa2d4e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 19 Nov 2023 21:56:34 +0800 Subject: [PATCH 1089/1556] src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs --- ...-sum-of-a-pair-with-equal-sum-of-digits.rs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs diff --git a/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs b/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs new file mode 100644 index 00000000..85bebde3 --- /dev/null +++ b/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs @@ -0,0 +1,37 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_sum(nums: Vec) -> i32 { + let mut hash = std::collections::HashMap::new(); + let mut result = -1; + for i in nums { + let s = Self::sum(i); + if !hash.contains_key(&s) { + hash.insert(s, i); + continue; + } + + let old = hash[&s]; + result = result.max(old + i); + if old < i { + hash.insert(s, i); + } + } + + result + } + + pub fn sum(mut num: i32) -> i32 { + let mut sum = 0; + while num > 0 { + sum += num % 10; + num /= 10; + } + + sum + } +} From 2d44b8c50c98c4f370069a4395361b165600babe Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 20 Nov 2023 19:39:10 +0800 Subject: [PATCH 1090/1556] src/bin/capitalize-the-title.rs --- README.md | 4 +++- src/bin/capitalize-the-title.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/bin/capitalize-the-title.rs diff --git a/README.md b/README.md index 21862d77..b6c0f8bf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 587 | 250 | 309 | 28 | +| 589 | 251 | 310 | 28 | ### 题目 @@ -415,6 +415,7 @@ |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | |2226 | 环和杆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rings-and-rods.rs) | [leetcode](https://leetcode-cn.com/problems/rings-and-rods/) | Easy | |2233 | 股票平滑下跌阶段的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-smooth-descent-periods-of-a-stock.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-smooth-descent-periods-of-a-stock/) | Medium | +|2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | |2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | @@ -427,6 +428,7 @@ |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | |2470 | 从字符串中移除星号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-stars-from-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/removing-stars-from-a-string/) | Medium | +|2473 | 数位和相等数对的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs) | [leetcode](https://leetcode-cn.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | |2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | diff --git a/src/bin/capitalize-the-title.rs b/src/bin/capitalize-the-title.rs new file mode 100644 index 00000000..0866333f --- /dev/null +++ b/src/bin/capitalize-the-title.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn capitalize_title(title: String) -> String { + title + .split(' ') + .map(|x| { + if x.len() <= 2 { + x.to_lowercase() + } else { + let mut s = x.to_lowercase(); + if s.as_bytes()[0] >= b'a' && s.as_bytes()[0] <= b'z' { + let w = s.as_bytes()[0] - b'a'; + unsafe { s.as_bytes_mut()[0] = b'A' + w }; + } + + s + } + }) + .collect::>() + .join(" ") + } +} From d9609253a566a76538ade6ef106a03016dee0e42 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 20 Nov 2023 19:39:10 +0800 Subject: [PATCH 1091/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b6c0f8bf..7188a008 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 589 | 251 | 310 | 28 | +| 590 | 252 | 310 | 28 | ### 题目 @@ -416,6 +416,7 @@ |2226 | 环和杆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rings-and-rods.rs) | [leetcode](https://leetcode-cn.com/problems/rings-and-rods/) | Easy | |2233 | 股票平滑下跌阶段的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-smooth-descent-periods-of-a-stock.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-smooth-descent-periods-of-a-stock/) | Medium | |2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | +|2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | |2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | From 1daef76bf51b7fd05a446786ce277092d8f1b384 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 21 Nov 2023 20:23:48 +0800 Subject: [PATCH 1092/1556] src/bin/check-if-all-characters-have-equal-number-of-occurrences.rs --- ...acters-have-equal-number-of-occurrences.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/check-if-all-characters-have-equal-number-of-occurrences.rs diff --git a/src/bin/check-if-all-characters-have-equal-number-of-occurrences.rs b/src/bin/check-if-all-characters-have-equal-number-of-occurrences.rs new file mode 100644 index 00000000..7a3a6174 --- /dev/null +++ b/src/bin/check-if-all-characters-have-equal-number-of-occurrences.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn are_occurrences_equal(s: String) -> bool { + let mut v = [0; 26]; + for &i in s.as_bytes() { + v[(i - b'a') as usize] += 1; + } + + let mut i = 0; + + for x in v { + if x == 0 { + continue; + } + + if i != 0 { + if i != x { + return false; + } + } else { + i = x; + } + } + + true + } +} From dead4de2739430101e3bdf8494b89499e4ec7dac Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 21 Nov 2023 20:23:49 +0800 Subject: [PATCH 1093/1556] README.md --- README.md | 1193 +++++++++++++++++++++++++++-------------------------- 1 file changed, 597 insertions(+), 596 deletions(-) diff --git a/README.md b/README.md index 79ba2090..b63b6471 100644 --- a/README.md +++ b/README.md @@ -1,602 +1,603 @@ # leetcode | Total | Easy | Medium | Hard | -|:-----:|:----:|:------:|:----:| -| 590 | 252 | 310 | 28 | +| :----: | :----: | :----: | :----: | +| 593 | 255 | 310 | 28 | ### 题目 -| 编号 | 题目 | 代码 | 题目描述 | 难度 | -|---------|----------------------------|------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|--------| -| 1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | Easy | -| 2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | Medium | -| 3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | Medium | -| 4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Hard | -| 5 | 最长回文子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindromic-substring.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindromic-substring/) | Medium | -| 6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | Medium | -| 7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | Medium | -| 8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | Medium | -| 9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number/) | Easy | -| 11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | Medium | -| 12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) | Medium | -| 13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer/) | Easy | -| 14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix/) | Easy | -| 15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum/) | Medium | -| 16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest/) | Medium | -| 17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | Medium | -| 18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | Medium | -| 19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Medium | -| 20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | Easy | -| 21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | Easy | -| 22 | 括号生成 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/generate-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/generate-parentheses/) | Medium | -| 23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Hard | -| 24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | Medium | -| 25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Hard | -| 26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | Easy | -| 27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | Easy | -| 28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | Easy | -| 29 | 两数相除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/divide-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/divide-two-integers/) | Medium | -| 30 | 串联所有单词的子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/substring-with-concatenation-of-all-words.rs) | [leetcode](https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words/) | Hard | -| 31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Medium | -| 32 | 最长有效括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/longest-valid-parentheses/) | Hard | -| 33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Medium | -| 34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Medium | -| 35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | Easy | -| 36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Medium | -| 37 | 解数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sudoku-solver.rs) | [leetcode](https://leetcode-cn.com/problems/sudoku-solver/) | Hard | -| 37 | 解数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sudoku-solver.rs) | [leetcode](https://leetcode-cn.com/problems/sudoku-solver/) | Hard | -| 38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Medium | -| 39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | -| 41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Hard | -| 42 | 接雨水 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/trapping-rain-water.rs) | [leetcode](https://leetcode-cn.com/problems/trapping-rain-water/) | Hard | -| 42 | 接雨水 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/trapping-rain-water.rs) | [leetcode](https://leetcode-cn.com/problems/trapping-rain-water/) | Hard | -| 43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Medium | -| 45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Medium | -| 46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Medium | -| 48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | Medium | -| 49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | Medium | -| 50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | Medium | -| 51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Hard | -| 52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Hard | -| 53 | 最大子数组和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) | Easy | -| 54 | 螺旋矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix/) | Medium | -| 55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | Medium | -| 56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | Medium | -| 57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | Medium | -| 58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word/) | Easy | -| 62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths/) | Medium | -| 63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) | Medium | -| 64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) | Medium | -| 66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | Easy | -| 67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary/) | Easy | -| 69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | Easy | -| 70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | Easy | -| 71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | Medium | -| 72 | 编辑距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/edit-distance.rs) | [leetcode](https://leetcode-cn.com/problems/edit-distance/) | Hard | -| 73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | Medium | -| 74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | Medium | -| 75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | Medium | -| 77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | Medium | -| 78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | Medium | -| 79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | Medium | -| 80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) | Medium | -| 81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | Medium | -| 82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | Medium | -| 83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | Easy | -| 84 | 柱状图中最大的矩形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-rectangle-in-histogram.rs) | [leetcode](https://leetcode-cn.com/problems/largest-rectangle-in-histogram/) | Hard | -| 85 | 最大矩形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-rectangle.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-rectangle/) | Hard | -| 87 | 扰乱字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/scramble-string.rs) | [leetcode](https://leetcode-cn.com/problems/scramble-string/) | Hard | -| 88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | Easy | -| 89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Medium | -| 91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Medium | -| 93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | Medium | -| 94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) | Easy | -| 95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | Medium | -| 96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | Medium | -| 98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | Medium | -| 100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree/) | Easy | -| 101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) | Easy | -| 102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | Medium | -| 103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | Medium | -| 104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | Easy | -| 105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | Medium | -| 106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | Medium | -| 107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | Medium | -| 108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) | Easy | -| 110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree/) | Easy | -| 111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) | Easy | -| 112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum/) | Easy | -| 113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) | Medium | -| 118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle/) | Easy | -| 119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii/) | Easy | -| 120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | Medium | -| 121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/) | Easy | -| 122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | Medium | -| 124 | 二叉树中的最大路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-maximum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-maximum-path-sum/) | Hard | -| 125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | Easy | -| 128 | 最长连续序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-consecutive-sequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-consecutive-sequence/) | Medium | -| 129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Medium | -| 136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | Easy | -| 137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Medium | -| 139 | 单词拆分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-break.rs) | [leetcode](https://leetcode-cn.com/problems/word-break/) | Medium | -| 143 | 重排链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reorder-list.rs) | [leetcode](https://leetcode-cn.com/problems/reorder-list/) | Medium | -| 144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | Easy | -| 145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | Easy | -| 146 | LRU 缓存 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lru-cache.rs) | [leetcode](https://leetcode-cn.com/problems/lru-cache/) | Medium | -| 148 | 排序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-list.rs) | [leetcode](https://leetcode-cn.com/problems/sort-list/) | Medium | -| 150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Medium | -| 151 | 颠倒字符串中的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | Medium | -| 152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Medium | -| 153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | Medium | -| 154 | 寻找旋转排序数组中的最小值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii/) | Hard | -| 155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | Medium | -| 162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | Medium | -| 165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | Medium | -| 166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | Medium | -| 167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | Medium | -| 168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | Easy | -| 169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element/) | Easy | -| 171 | Excel 表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) | Easy | -| 172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | Medium | -| 173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | Medium | -| 187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | Medium | -| 190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | Easy | -| 191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | Easy | -| 198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | Medium | -| 199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | Medium | -| 200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | Medium | -| 201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | Medium | -| 202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number/) | Easy | -| 203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) | Easy | -| 204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | Medium | -| 205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | Easy | -| 206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | Easy | -| 207 | 课程表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/course-schedule.rs) | [leetcode](https://leetcode-cn.com/problems/course-schedule/) | Medium | -| 208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | Medium | -| 211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | Medium | -| 213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | Medium | -| 215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) | Medium | -| 216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) | Medium | -| 217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate/) | Easy | -| 219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii/) | Easy | -| 222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) | Medium | -| 223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area/) | Medium | -| 225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues/) | Easy | -| 226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree/) | Easy | -| 228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges/) | Easy | -| 229 | 多数元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) | Medium | -| 230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) | Medium | -| 231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two/) | Easy | -| 232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks/) | Easy | -| 234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) | Easy | -| 235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | Easy | -| 236 | 二叉树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/) | Medium | -| 238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Medium | -| 239 | 滑动窗口最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sliding-window-maximum.rs) | [leetcode](https://leetcode-cn.com/problems/sliding-window-maximum/) | Hard | -| 240 | 搜索二维矩阵 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix-ii/) | Medium | -| 242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | Easy | -| 257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | Easy | -| 258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits/) | Easy | -| 260 | 只出现一次的数字 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-iii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-iii/) | Medium | -| 263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | Easy | -| 268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | Easy | -| 274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Medium | -| 275 | H 指数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index-ii.rs) | [leetcode](https://leetcode-cn.com/problems/h-index-ii/) | Medium | -| 278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | -| 279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | -| 283 | 移动零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/move-zeroes/) | Easy | -| 287 | 寻找重复数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-duplicate-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-duplicate-number/) | Medium | -| 290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | -| 292 | Nim 游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nim-game.rs) | [leetcode](https://leetcode-cn.com/problems/nim-game/) | Easy | -| 297 | 二叉树的序列化与反序列化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree/) | Hard | -| 300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | -| 303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | -| 307 | 区域和检索 - 数组可修改 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-mutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-mutable/) | Medium | -| 309 | 最佳买卖股票时机含冷冻期 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-with-cooldown.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/) | Medium | -| 318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | -| 319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | -| 322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | -| 326 | 3 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | -| 334 | 递增的三元子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increasing-triplet-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/increasing-triplet-subsequence/) | Medium | -| 337 | 打家劫舍 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-iii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-iii/) | Medium | -| 338 | 比特位计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-bits.rs) | [leetcode](https://leetcode-cn.com/problems/counting-bits/) | Easy | -| 344 | 反转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string/) | Easy | -| 345 | 反转字符串中的元音字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-vowels-of-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-vowels-of-a-string/) | Easy | -| 347 | 前 K 个高频元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/top-k-frequent-elements.rs) | [leetcode](https://leetcode-cn.com/problems/top-k-frequent-elements/) | Medium | -| 349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | -| 350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | -| 355 | 设计推特 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-twitter.rs) | [leetcode](https://leetcode-cn.com/problems/design-twitter/) | Medium | -| 357 | 统计各位数字都不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | -| 367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | -| 371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | -| 374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | -| 376 | 摆动序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wiggle-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/wiggle-subsequence/) | Medium | -| 378 | 有序矩阵中第 K 小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-sorted-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/) | Medium | -| 380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | -| 381 | O(1) 时间插入、删除和获取随机元素 - 允许重复 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed/) | Hard | -| 382 | 链表随机节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/linked-list-random-node.rs) | [leetcode](https://leetcode-cn.com/problems/linked-list-random-node/) | Medium | -| 383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | -| 384 | 打乱数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shuffle-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/shuffle-an-array/) | Medium | -| 386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | -| 387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | -| 389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | -| 390 | 消除游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/elimination-game.rs) | [leetcode](https://leetcode-cn.com/problems/elimination-game/) | Medium | -| 392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | -| 393 | UTF-8 编码验证 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/utf-8-validation.rs) | [leetcode](https://leetcode-cn.com/problems/utf-8-validation/) | Medium | -| 397 | 整数替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-replacement.rs) | [leetcode](https://leetcode-cn.com/problems/integer-replacement/) | Medium | -| 398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | -| 400 | 第 N 位数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nth-digit.rs) | [leetcode](https://leetcode-cn.com/problems/nth-digit/) | Medium | -| 404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | -| 406 | 根据身高重建队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/queue-reconstruction-by-height.rs) | [leetcode](https://leetcode-cn.com/problems/queue-reconstruction-by-height/) | Medium | -| 409 | 最长回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindrome/) | Easy | -| 412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | -| 413 | 等差数列划分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/arithmetic-slices.rs) | [leetcode](https://leetcode-cn.com/problems/arithmetic-slices/) | Medium | -| 415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | -| 419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | -| 423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | -| 434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | -| 438 | 找到字符串中所有字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-anagrams-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-anagrams-in-a-string/) | Medium | -| 442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | -| 445 | 两数相加 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers-ii.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers-ii/) | Medium | -| 448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | -| 449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | -| 460 | LFU 缓存 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lfu-cache.rs) | [leetcode](https://leetcode-cn.com/problems/lfu-cache/) | Hard | -| 461 | 汉明距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/hamming-distance.rs) | [leetcode](https://leetcode-cn.com/problems/hamming-distance/) | Easy | -| 476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | -| 481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | -| 485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | -| 486 | 预测赢家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/predict-the-winner.rs) | [leetcode](https://leetcode-cn.com/problems/predict-the-winner/) | Medium | -| 489 | 第 K 条最小指令 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-instructions.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-instructions/) | Hard | -| 494 | 目标和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/target-sum/) | Medium | -| 494 | 目标和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/target-sum/) | Medium | -| 500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | -| 504 | 七进制数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/base-7.rs) | [leetcode](https://leetcode-cn.com/problems/base-7/) | Easy | -| 507 | 完美数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-number.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-number/) | Easy | -| 508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | -| 513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | -| 515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | -| 520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | -| 528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | -| 530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | -| 535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | -| 538 | 把二叉搜索树转换为累加树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-bst-to-greater-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-bst-to-greater-tree/) | Medium | -| 541 | 反转字符串 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string-ii/) | Easy | -| 543 | 二叉树的直径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diameter-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/diameter-of-binary-tree/) | Easy | -| 551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | -| 560 | 和为 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | -| 565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | -| 581 | 最短无序连续子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shortest-unsorted-continuous-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/shortest-unsorted-continuous-subarray/) | Medium | -| 594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | -| 599 | 两个列表的最小索引总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-index-sum-of-two-lists.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-index-sum-of-two-lists/) | Easy | -| 605 | 种花问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/can-place-flowers.rs) | [leetcode](https://leetcode-cn.com/problems/can-place-flowers/) | Easy | -| 617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | -| 621 | 任务调度器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/task-scheduler.rs) | [leetcode](https://leetcode-cn.com/problems/task-scheduler/) | Medium | -| 623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | -| 637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | -| 643 | 子数组最大平均数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-average-subarray-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-average-subarray-i/) | Easy | -| 647 | 回文子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindromic-substrings.rs) | [leetcode](https://leetcode-cn.com/problems/palindromic-substrings/) | Medium | -| 649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | -| 650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | -| 653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | -| 657 | 机器人能否返回原点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-return-to-origin.rs) | [leetcode](https://leetcode-cn.com/problems/robot-return-to-origin/) | Easy | -| 658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | -| 674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | -| 718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | -| 722 | 删除注释 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-comments.rs) | [leetcode](https://leetcode-cn.com/problems/remove-comments/) | Medium | -| 724 | 寻找数组的中心下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-pivot-index.rs) | [leetcode](https://leetcode-cn.com/problems/find-pivot-index/) | Easy | -| 739 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/daily-temperatures.rs) | [leetcode](https://leetcode-cn.com/problems/daily-temperatures/) | Medium | -| 742 | 转换成小写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/to-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/to-lower-case/) | Easy | -| 782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | -| 783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | -| 784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | -| 800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | -| 825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | -| 829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | -| 834 | 模糊坐标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ambiguous-coordinates.rs) | [leetcode](https://leetcode-cn.com/problems/ambiguous-coordinates/) | Medium | -| 842 | 翻转卡片游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/card-flipping-game.rs) | [leetcode](https://leetcode-cn.com/problems/card-flipping-game/) | Medium | -| 857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | -| 860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | -| 861 | 翻转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/flipping-an-image.rs) | [leetcode](https://leetcode-cn.com/problems/flipping-an-image/) | Easy | -| 862 | 字符串中的查找与替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-and-replace-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-and-replace-in-string/) | Medium | -| 868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | -| 879 | 到最近的人的最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximize-distance-to-closest-person.rs) | [leetcode](https://leetcode-cn.com/problems/maximize-distance-to-closest-person/) | Medium | -| 890 | 柠檬水找零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lemonade-change.rs) | [leetcode](https://leetcode-cn.com/problems/lemonade-change/) | Easy | -| 904 | 叶子相似的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/leaf-similar-trees.rs) | [leetcode](https://leetcode-cn.com/problems/leaf-similar-trees/) | Easy | -| 905 | 最长的斐波那契子序列的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-longest-fibonacci-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence/) | Medium | -| 906 | 模拟行走机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/walking-robot-simulation.rs) | [leetcode](https://leetcode-cn.com/problems/walking-robot-simulation/) | Medium | -| 908 | 链表的中间结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/middle-of-the-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/middle-of-the-linked-list/) | Easy | -| 917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | -| 921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | -| 924 | 公平的糖果交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | -| 925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | -| 932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | -| 936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | -| 937 | 股票价格跨度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-stock-span.rs) | [leetcode](https://leetcode-cn.com/problems/online-stock-span/) | Medium | -| 947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | -| 953 | 仅仅反转字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-only-letters.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-only-letters/) | Easy | -| 954 | 环形子数组的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-circular-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-circular-subarray/) | Medium | -| 967 | 下降路径最小和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-falling-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-falling-path-sum/) | Medium | -| 977 | 不同的子序列 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distinct-subsequences-ii.rs) | [leetcode](https://leetcode-cn.com/problems/distinct-subsequences-ii/) | Hard | -| 979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | -| 981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | -| 982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Medium | -| 983 | 验证栈序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-stack-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/validate-stack-sequences/) | Medium | -| 1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | Medium | -| 1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | Easy | -| 1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | -| 1010 | 强整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powerful-integers.rs) | [leetcode](https://leetcode-cn.com/problems/powerful-integers/) | Medium | -| 1021 | 在二叉树中分配硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-coins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-coins-in-binary-tree/) | Medium | -| 1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | -| 1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | -| 1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | -| 1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | -| 1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | -| 1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | -| 1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | -| 1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | -| 1218 | 最深叶节点的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-deepest-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves/) | Medium | -| 1236 | 第 N 个泰波那契数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-th-tribonacci-number.rs) | [leetcode](https://leetcode-cn.com/problems/n-th-tribonacci-number/) | Easy | -| 1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | -| 1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | -| 1263 | 掷骰子等于目标和的方法数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-dice-rolls-with-target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-dice-rolls-with-target-sum/) | Medium | -| 1273 | 比较字符串最小字母出现频次 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-strings-by-frequency-of-the-smallest-character.rs) | [leetcode](https://leetcode-cn.com/problems/compare-strings-by-frequency-of-the-smallest-character/) | Medium | -| 1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | -| 1293 | 存在连续三个奇数的数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/three-consecutive-odds.rs) | [leetcode](https://leetcode-cn.com/problems/three-consecutive-odds/) | Easy | -| 1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | -| 1319 | 独一无二的出现次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-number-of-occurrences.rs) | [leetcode](https://leetcode-cn.com/problems/unique-number-of-occurrences/) | Easy | -| 1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | -| 1329 | 玩筹码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cost-to-move-chips-to-the-same-position.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position/) | Easy | -| 1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | -| 1342 | 可以攻击国王的皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/queens-that-can-attack-the-king.rs) | [leetcode](https://leetcode-cn.com/problems/queens-that-can-attack-the-king/) | Medium | -| 1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | -| 1363 | 兼具大小写的最好英文字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/greatest-english-letter-in-upper-and-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/greatest-english-letter-in-upper-and-lower-case/) | Easy | -| 1364 | 同积元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tuple-with-same-product.rs) | [leetcode](https://leetcode-cn.com/problems/tuple-with-same-product/) | Medium | -| 1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | -| 1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | -| 1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | -| 1380 | 统计封闭岛屿的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-closed-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-closed-islands/) | Medium | -| 1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | -| 1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | -| 1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | -| 1406 | 整数的各位积和之差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/) | Easy | -| 1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | -| 1426 | 和为零的 N 个不同整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | -| 1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Medium | -| 1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | Easy | -| 1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | -| 1450 | 删除给定值的叶子节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-leaves-with-a-given-value.rs) | [leetcode](https://leetcode-cn.com/problems/delete-leaves-with-a-given-value/) | Medium | -| 1455 | 餐厅过滤器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/filter-restaurants-by-vegan-friendly-price-and-distance.rs) | [leetcode](https://leetcode-cn.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance/) | Medium | -| 1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | -| 1472 | 上升下降字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increasing-decreasing-string.rs) | [leetcode](https://leetcode-cn.com/problems/increasing-decreasing-string/) | Easy | -| 1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | -| 1491 | 二进制字符串前缀一致的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-times-binary-string-is-prefix-aligned.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-times-binary-string-is-prefix-aligned/) | Medium | -| 1501 | 圆和矩形是否有重叠 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circle-and-rectangle-overlapping.rs) | [leetcode](https://leetcode-cn.com/problems/circle-and-rectangle-overlapping/) | Medium | -| 1503 | 做菜顺序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reducing-dishes.rs) | [leetcode](https://leetcode-cn.com/problems/reducing-dishes/) | Hard | -| 1505 | 按既定顺序创建目标数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/create-target-array-in-the-given-order.rs) | [leetcode](https://leetcode-cn.com/problems/create-target-array-in-the-given-order/) | Easy | -| 1512 | 设计地铁系统 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-underground-system.rs) | [leetcode](https://leetcode-cn.com/problems/design-underground-system/) | Medium | -| 1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | -| 1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | -| 1544 | 统计二叉树中好节点的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-nodes-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-nodes-in-binary-tree/) | Medium | -| 1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | -| 1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | -| 1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Medium | -| 1575 | 切割后面积最大的蛋糕 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/) | Medium | -| 1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | -| 1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | -| 1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | -| 1636 | 仅含 1 的子串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-substrings-with-only-1s.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-substrings-with-only-1s/) | Medium | -| 1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | Easy | -| 1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | Easy | -| 1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | -| 1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | -| 1677 | 矩阵对角线元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/matrix-diagonal-sum.rs) | [leetcode](https://leetcode-cn.com/problems/matrix-diagonal-sum/) | Easy | -| 1782 | 具有给定数值的最小字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-string-with-a-given-numeric-value.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-string-with-a-given-numeric-value/) | Medium | -| 1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | -| 1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | -| 1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | -| 1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | -| 1829 | 卡车上的最大单元数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-units-on-a-truck.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-units-on-a-truck/) | Easy | -| 1849 | 任意子数组和的绝对值的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-absolute-sum-of-any-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | -| 1858 | 替换隐藏数字得到的最晚时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/latest-time-by-replacing-hidden-digits.rs) | [leetcode](https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits/) | Easy | -| 1894 | 交替合并字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-strings-alternately.rs) | [leetcode](https://leetcode-cn.com/problems/merge-strings-alternately/) | Easy | -| 1929 | 有界数组中指定下标处的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-at-a-given-index-in-a-bounded-array/) | Medium | -| 1938 | 最少操作使数组递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-make-the-array-increasing.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-increasing/) | Easy | -| 1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | -| 1952 | 最少侧跳次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sideway-jumps.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sideway-jumps/) | Medium | -| 1971 | 增长的内存泄露 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/incremental-memory-leak.rs) | [leetcode](https://leetcode-cn.com/problems/incremental-memory-leak/) | Medium | -| 1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | -| 2022 | 最大子序列交替和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-alternating-subsequence-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-alternating-subsequence-sum/) | Medium | -| 2049 | 消灭怪物的最大数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/eliminate-maximum-number-of-monsters.rs) | [leetcode](https://leetcode-cn.com/problems/eliminate-maximum-number-of-monsters/) | Medium | -| 2104 | 树上的操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/operations-on-tree.rs) | [leetcode](https://leetcode-cn.com/problems/operations-on-tree/) | Medium | -| 2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | -| 2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | -| 2161 | 股票价格波动 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/stock-price-fluctuation.rs) | [leetcode](https://leetcode-cn.com/problems/stock-price-fluctuation/) | Medium | -| 2177 | 检查两个字符串是否几乎相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-whether-two-strings-are-almost-equivalent.rs) | [leetcode](https://leetcode-cn.com/problems/check-whether-two-strings-are-almost-equivalent/) | Easy | -| 2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | -| 2226 | 环和杆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rings-and-rods.rs) | [leetcode](https://leetcode-cn.com/problems/rings-and-rods/) | Easy | -| 2233 | 股票平滑下跌阶段的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-smooth-descent-periods-of-a-stock.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-smooth-descent-periods-of-a-stock/) | Medium | -| 2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | -| 2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | -| 2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | -| 2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | -| 2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | -| 2310 | 将数组和减半的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-halve-array-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-halve-array-sum/) | Medium | -| 2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | -| 2346 | 字符串中最大的 3 位相同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-3-same-digit-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-3-same-digit-number-in-string/) | Easy | -| 2351 | 买钢笔和铅笔的方案数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-ways-to-buy-pens-and-pencils.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-ways-to-buy-pens-and-pencils/) | Medium | -| 2384 | 判断根结点是否等于子结点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/root-equals-sum-of-children.rs) | [leetcode](https://leetcode-cn.com/problems/root-equals-sum-of-children/) | Easy | -| 2386 | 极大极小游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-max-game.rs) | [leetcode](https://leetcode-cn.com/problems/min-max-game/) | Easy | -| 2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | -| 2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | -| 2470 | 从字符串中移除星号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-stars-from-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/removing-stars-from-a-string/) | Medium | -| 2473 | 数位和相等数对的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs) | [leetcode](https://leetcode-cn.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | -| 2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | -| 2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | -| 2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | -| 2571 | 找出中枢整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-pivot-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-pivot-integer/) | Easy | -| 2575 | 分割圆的最少切割次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cuts-to-divide-a-circle.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cuts-to-divide-a-circle/) | Easy | -| 2580 | 回环句 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circular-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/circular-sentence/) | Easy | -| 2585 | 删除每行中的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-greatest-value-in-each-row.rs) | [leetcode](https://leetcode-cn.com/problems/delete-greatest-value-in-each-row/) | Easy | -| 2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | -| 2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | -| 2603 | 奖励最顶尖的 K 名学生 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reward-top-k-students.rs) | [leetcode](https://leetcode-cn.com/problems/reward-top-k-students/) | Medium | -| 2608 | 统计能整除数字的位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-the-digits-that-divide-a-number.rs) | [leetcode](https://leetcode-cn.com/problems/count-the-digits-that-divide-a-number/) | Easy | -| 2616 | 执行 K 次操作后的最大分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-score-after-applying-k-operations.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-score-after-applying-k-operations/) | Medium | -| 2619 | 根据规则将箱子分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/categorize-box-according-to-criteria.rs) | [leetcode](https://leetcode-cn.com/problems/categorize-box-according-to-criteria/) | Easy | -| 2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | -| 2645 | 递枕头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pass-the-pillow.rs) | [leetcode](https://leetcode-cn.com/problems/pass-the-pillow/) | Easy | -| 2650 | 最小和分割 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-with-minimum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/split-with-minimum-sum/) | Easy | -| 2654 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-the-number-of-vowel-strings-in-range.rs) | [leetcode](https://leetcode-cn.com/problems/count-the-number-of-vowel-strings-in-range/) | Easy | -| 2662 | 检查骑士巡视方案 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-knight-tour-configuration.rs) | [leetcode](https://leetcode-cn.com/problems/check-knight-tour-configuration/) | Medium | -| 2663 | 将钱分给最多的儿童 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-money-to-maximum-children.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-money-to-maximum-children/) | Easy | -| 2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | -| 2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | -| 2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | -| 2679 | 统计桌面上的不同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-distinct-numbers-on-board.rs) | [leetcode](https://leetcode-cn.com/problems/count-distinct-numbers-on-board/) | Easy | -| 2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | -| 2692 | 从数量最多的堆取走礼物 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/take-gifts-from-the-richest-pile.rs) | [leetcode](https://leetcode-cn.com/problems/take-gifts-from-the-richest-pile/) | Easy | -| 2692 | 从数量最多的堆取走礼物 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/take-gifts-from-the-richest-pile.rs) | [leetcode](https://leetcode-cn.com/problems/take-gifts-from-the-richest-pile/) | Easy | -| 2694 | 找出可整除性得分最大的整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-divisibility-score.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-divisibility-score/) | Easy | -| 2698 | 找出数组的串联值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-array-concatenation-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-array-concatenation-value/) | Easy | -| 2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | -| 2723 | 最长平衡子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-longest-balanced-substring-of-a-binary-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-longest-balanced-substring-of-a-binary-string/) | Easy | -| 2727 | 老人的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-senior-citizens.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-senior-citizens/) | Easy | -| 2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | -| 2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | -| 2752 | 倍数求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-multiples.rs) | [leetcode](https://leetcode-cn.com/problems/sum-multiples/) | Easy | -| 2767 | K 个元素的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-with-exactly-k-elements.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-with-exactly-k-elements/) | Easy | -| 2787 | 移动机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/movement-of-robots.rs) | [leetcode](https://leetcode-cn.com/problems/movement-of-robots/) | Medium | -| 2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | -| 2802 | 求一个整数的惩罚数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-punishment-number-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-punishment-number-of-an-integer/) | Medium | -| 2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | -| 2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | -| 2866 | 最长奇偶子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-even-odd-subarray-with-threshold.rs) | [leetcode](https://leetcode-cn.com/problems/longest-even-odd-subarray-with-threshold/) | Easy | -| 2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | -| 3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | -| 3152 | 有序三元组中的最大值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-an-ordered-triplet-ii.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-an-ordered-triplet-ii/) | Medium | -| 100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | -| 100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | -| 100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | -| 100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | -| 100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | -| 100276 | 二维数组中的查找 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-wei-shu-zu-zhong-de-cha-zhao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/) | Medium | -| 100277 | 青蛙跳台阶问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) | Easy | -| 100278 | 旋转数组的最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/) | Easy | -| 100279 | 矩阵中的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ju-zhen-zhong-de-lu-jing-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ju-zhen-zhong-de-lu-jing-lcof/) | Medium | -| 100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | -| 100281 | 机器人的运动范围 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ji-qi-ren-de-yun-dong-fan-wei-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/) | Medium | -| 100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | -| 100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | -| 100284 | 剪绳子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-lcof/) | Medium | -| 100285 | 剪绳子 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/) | Medium | -| 100286 | 合并两个排序的链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/he-bing-liang-ge-pai-xu-de-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/) | Easy | -| 100287 | 树的子结构 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-de-zi-jie-gou-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof/) | Medium | -| 100288 | 二叉树的镜像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-jing-xiang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof/) | Easy | -| 100289 | 对称的二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dui-cheng-de-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof/) | Easy | -| 100290 | 表示数值的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/biao-shi-shu-zhi-de-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/biao-shi-shu-zhi-de-zi-fu-chuan-lcof/) | Medium | -| 100291 | 调整数组顺序使奇数位于偶数前面 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/) | Easy | -| 100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | -| 100293 | 顺时针打印矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shun-shi-zhen-da-yin-ju-zhen-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shun-shi-zhen-da-yin-ju-zhen-lcof/) | Easy | -| 100294 | 链表中倒数第k个节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/) | Easy | -| 100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | -| 100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | -| 100296 | 打印从1到最大的n位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) | Easy | -| 100296 | 打印从1到最大的n位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) | Easy | -| 100298 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fan-zhuan-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/) | Easy | -| 100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | -| 100301 | 最小的k个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-xiao-de-kge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof/) | Easy | -| 100302 | 包含min函数的栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/) | Easy | -| 100303 | 数据流中的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-ju-liu-zhong-de-zhong-wei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof/) | Hard | -| 100304 | 连续子数组的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lian-xu-zi-shu-zu-de-zui-da-he-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/) | Easy | -| 100306 | 栈的压入、弹出序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) | Medium | -| 100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | -| 100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | -| 100309 | 1~n 整数中 1 出现的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof/) | Hard | -| 100310 | 数组中出现次数超过一半的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof/) | Easy | -| 100311 | 从上到下打印二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) | Medium | -| 100312 | 从上到下打印二叉树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/) | Easy | -| 100313 | 数字序列中某一位的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof/) | Medium | -| 100314 | 从上到下打印二叉树 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof/) | Medium | -| 100315 | 二叉搜索树的后序遍历序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof/) | Medium | -| 100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | -| 100317 | 二叉树中和为某一值的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/) | Medium | -| 100318 | 数组中的逆序对 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-de-ni-xu-dui-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/) | Hard | -| 100319 | 二叉树的深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-shen-du-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) | Easy | -| 100319 | 二叉树的深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-shen-du-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) | Easy | -| 100320 | 数组中数字出现的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/) | Medium | -| 100321 | 数组中数字出现的次数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/) | Medium | -| 100322 | 和为s的两个数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/he-wei-sde-liang-ge-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof/) | Easy | -| 100323 | 把数组排成最小的数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | Medium | -| 100324 | 和为s的连续正数序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/) | Easy | -| 100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | -| 100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | -| 100327 | 礼物的最大价值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/) | Medium | -| 100328 | 翻转单词顺序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fan-zhuan-dan-ci-shun-xu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof/) | Easy | -| 100329 | 在排序数组中查找数字 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/) | Easy | -| 100330 | 左旋转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zuo-xuan-zhuan-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/) | Easy | -| 100331 | 0~n-1中缺失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/que-shi-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/) | Easy | -| 100332 | 最长不含重复字符的子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) | Medium | -| 100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | -| 100334 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chou-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/chou-shu-lcof/) | Medium | -| 100335 | 不用加减乘除做加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/) | Easy | -| 100337 | 队列的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dui-lie-de-zui-da-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof/) | Medium | -| 100338 | 构建乘积数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gou-jian-cheng-ji-shu-zu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof/) | Medium | -| 100339 | n个骰子的点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nge-tou-zi-de-dian-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/nge-tou-zi-de-dian-shu-lcof/) | Medium | -| 100340 | 把字符串转换成整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof/) | Medium | -| 100341 | 扑克牌中的顺子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bu-ke-pai-zhong-de-shun-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof/) | Easy | -| 100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | -| 100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | -| 100343 | 圆圈中最后剩下的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/) | Easy | -| 100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | -| 100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | -| 100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | -| 100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | -| 100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | -| 1000021 | 最小K个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-k-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-k-lcci/) | Medium | -| 1000022 | 最长单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-word-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/longest-word-lcci/) | Medium | -| 1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | -| 1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | -| 1000228 | 整数除法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xoh6Oh.rs) | [leetcode](https://leetcode-cn.com/problems/xoh6Oh/) | Easy | -| 1000230 | 前 n 个数字二进制中 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/w3tCBm.rs) | [leetcode](https://leetcode-cn.com/problems/w3tCBm/) | Easy | -| 1000231 | 二进制加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/JFETK5.rs) | [leetcode](https://leetcode-cn.com/problems/JFETK5/) | Easy | -| 1000233 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WGki4K.rs) | [leetcode](https://leetcode-cn.com/problems/WGki4K/) | Medium | -| 1000236 | 单词长度的最大乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aseY1I.rs) | [leetcode](https://leetcode-cn.com/problems/aseY1I/) | Medium | -| 1000237 | 排序数组中两个数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kLl5u1.rs) | [leetcode](https://leetcode-cn.com/problems/kLl5u1/) | Easy | -| 1000238 | 括号生成 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/IDBivT.rs) | [leetcode](https://leetcode-cn.com/problems/IDBivT/) | Medium | -| 1000242 | 和大于等于 target 的最短子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2VG8Kg.rs) | [leetcode](https://leetcode-cn.com/problems/2VG8Kg/) | Medium | -| 1000244 | 乘积小于 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ZVAVXX.rs) | [leetcode](https://leetcode-cn.com/problems/ZVAVXX/) | Medium | -| 1000246 | 和为 k 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/QTMn0o.rs) | [leetcode](https://leetcode-cn.com/problems/QTMn0o/) | Medium | -| 1000247 | 0 和 1 个数相同的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/A1NYOS.rs) | [leetcode](https://leetcode-cn.com/problems/A1NYOS/) | Medium | -| 1000248 | 左右两边子数组的和相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tvdfij.rs) | [leetcode](https://leetcode-cn.com/problems/tvdfij/) | Easy | -| 1000249 | 二维子矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/O4NDxx.rs) | [leetcode](https://leetcode-cn.com/problems/O4NDxx/) | Medium | -| 1000250 | 字符串中的变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/MPnaiL.rs) | [leetcode](https://leetcode-cn.com/problems/MPnaiL/) | Medium | -| 1000251 | 字符串中的所有变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/VabMRr.rs) | [leetcode](https://leetcode-cn.com/problems/VabMRr/) | Medium | -| 1000252 | 不含重复字符的最长子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wtcaE1.rs) | [leetcode](https://leetcode-cn.com/problems/wtcaE1/) | Medium | -| 1000254 | 有效的回文 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XltzEq.rs) | [leetcode](https://leetcode-cn.com/problems/XltzEq/) | Easy | -| 1000255 | 最多删除一个字符得到回文 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/RQku0D.rs) | [leetcode](https://leetcode-cn.com/problems/RQku0D/) | Easy | -| 1000256 | 回文子字符串的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/a7VOhD.rs) | [leetcode](https://leetcode-cn.com/problems/a7VOhD/) | Medium | -| 1000261 | 链表中的两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lMSNwu.rs) | [leetcode](https://leetcode-cn.com/problems/lMSNwu/) | Medium | -| 1000262 | 重排链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/LGjMqU.rs) | [leetcode](https://leetcode-cn.com/problems/LGjMqU/) | Medium | -| 1000263 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aMhZSa.rs) | [leetcode](https://leetcode-cn.com/problems/aMhZSa/) | Easy | -| 1000273 | 有效的变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dKk3P7.rs) | [leetcode](https://leetcode-cn.com/problems/dKk3P7/) | Easy | -| 1000275 | 变位词组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sfvd7V.rs) | [leetcode](https://leetcode-cn.com/problems/sfvd7V/) | Medium | -| 1000276 | 外星语言是否排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lwyVBB.rs) | [leetcode](https://leetcode-cn.com/problems/lwyVBB/) | Easy | -| 1000278 | 最小时间差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/569nqc.rs) | [leetcode](https://leetcode-cn.com/problems/569nqc/) | Medium | -| 1000279 | 后缀表达式 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/8Zf90G.rs) | [leetcode](https://leetcode-cn.com/problems/8Zf90G/) | Medium | -| 1000281 | 小行星碰撞 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XagZNi.rs) | [leetcode](https://leetcode-cn.com/problems/XagZNi/) | Medium | -| 1000282 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/iIQa4I.rs) | [leetcode](https://leetcode-cn.com/problems/iIQa4I/) | Medium | -| 1000288 | 加减的目标值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/YaVDxD.rs) | [leetcode](https://leetcode-cn.com/problems/YaVDxD/) | Medium | -| 1000292 | 滑动窗口的平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qIsx9U.rs) | [leetcode](https://leetcode-cn.com/problems/qIsx9U/) | Easy | -| 1000295 | 往完全二叉树添加节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NaqhDT.rs) | [leetcode](https://leetcode-cn.com/problems/NaqhDT/) | Medium | -| 1000297 | 二叉树每层的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/hPov7L.rs) | [leetcode](https://leetcode-cn.com/problems/hPov7L/) | Medium | -| 1000298 | 二叉树最底层最左边的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/LwUNpT.rs) | [leetcode](https://leetcode-cn.com/problems/LwUNpT/) | Medium | -| 1000299 | 二叉树的右侧视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WNC0Lk.rs) | [leetcode](https://leetcode-cn.com/problems/WNC0Lk/) | Medium | -| 1000301 | 二叉树剪枝 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pOCWxh.rs) | [leetcode](https://leetcode-cn.com/problems/pOCWxh/) | Medium | -| 1000306 | 从根节点到叶节点的路径数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3Etpl5.rs) | [leetcode](https://leetcode-cn.com/problems/3Etpl5/) | Medium | -| 1000307 | 向下的路径节点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/6eUYwP.rs) | [leetcode](https://leetcode-cn.com/problems/6eUYwP/) | Medium | -| 1000311 | 展平二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NYBBNL.rs) | [leetcode](https://leetcode-cn.com/problems/NYBBNL/) | Easy | -| 1000319 | 二叉搜索树中两个节点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/opLdQZ.rs) | [leetcode](https://leetcode-cn.com/problems/opLdQZ/) | Easy | -| 1000321 | 值和下标之差都在给定的范围内 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WqeDu.rs) | [leetcode](https://leetcode-cn.com/problems/7WqeDu/) | Medium | -| 1000333 | 山峰数组的顶部 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/B1IidL.rs) | [leetcode](https://leetcode-cn.com/problems/B1IidL/) | Easy | -| 1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | -| 1000433 | 宝石补给 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WHnhjV.rs) | [leetcode](https://leetcode-cn.com/problems/WHnhjV/) | Easy | +| 编号 | 题目 | 代码 | 题目描述 | 难度 | +| ---- | ---- | ---- | ---- | ---- | +|1 | 两数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum/) | Easy | +|2 | 两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers/) | Medium | +|3 | 无重复字符的最长子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-substring-without-repeating-characters.rs) | [leetcode](https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/) | Medium | +|4 | 寻找两个正序数组的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/median-of-two-sorted-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/median-of-two-sorted-arrays/) | Hard | +|5 | 最长回文子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindromic-substring.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindromic-substring/) | Medium | +|6 | Z 字形变换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zigzag-conversion.rs) | [leetcode](https://leetcode-cn.com/problems/zigzag-conversion/) | Medium | +|7 | 整数反转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-integer.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-integer/) | Medium | +|8 | 字符串转换整数 (atoi) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-integer-atoi.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-integer-atoi/) | Medium | +|9 | 回文数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-number.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-number/) | Easy | +|11 | 盛最多水的容器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/container-with-most-water.rs) | [leetcode](https://leetcode-cn.com/problems/container-with-most-water/) | Medium | +|12 | 整数转罗马数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-to-roman.rs) | [leetcode](https://leetcode-cn.com/problems/integer-to-roman/) | Medium | +|13 | 罗马数字转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/roman-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/roman-to-integer/) | Easy | +|14 | 最长公共前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-common-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/longest-common-prefix/) | Easy | +|15 | 三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum.rs) | [leetcode](https://leetcode-cn.com/problems/3sum/) | Medium | +|16 | 最接近的三数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3sum-closest.rs) | [leetcode](https://leetcode-cn.com/problems/3sum-closest/) | Medium | +|17 | 电话号码的字母组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-combinations-of-a-phone-number.rs) | [leetcode](https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/) | Medium | +|18 | 四数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/4sum.rs) | [leetcode](https://leetcode-cn.com/problems/4sum/) | Medium | +|19 | 删除链表的倒数第 N 个结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nth-node-from-end-of-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/) | Medium | +|20 | 有效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/valid-parentheses/) | Easy | +|21 | 合并两个有序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-sorted-lists/) | Easy | +|22 | 括号生成 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/generate-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/generate-parentheses/) | Medium | +|23 | 合并K个升序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-k-sorted-lists.rs) | [leetcode](https://leetcode-cn.com/problems/merge-k-sorted-lists/) | Hard | +|24 | 两两交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swap-nodes-in-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/swap-nodes-in-pairs/) | Medium | +|25 | K 个一组翻转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-nodes-in-k-group.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-nodes-in-k-group/) | Hard | +|26 | 删除有序数组中的重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/) | Easy | +|27 | 移除元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-element.rs) | [leetcode](https://leetcode-cn.com/problems/remove-element/) | Easy | +|28 | 实现 strStr() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-strstr.rs) | [leetcode](https://leetcode-cn.com/problems/implement-strstr/) | Easy | +|29 | 两数相除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/divide-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/divide-two-integers/) | Medium | +|30 | 串联所有单词的子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/substring-with-concatenation-of-all-words.rs) | [leetcode](https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words/) | Hard | +|31 | 下一个排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/next-permutation/) | Medium | +|32 | 最长有效括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/longest-valid-parentheses/) | Hard | +|33 | 搜索旋转排序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array/) | Medium | +|34 | 在排序数组中查找元素的第一个和最后一个位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-first-and-last-position-of-element-in-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/) | Medium | +|35 | 搜索插入位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-insert-position.rs) | [leetcode](https://leetcode-cn.com/problems/search-insert-position/) | Easy | +|36 | 有效的数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-sudoku.rs) | [leetcode](https://leetcode-cn.com/problems/valid-sudoku/) | Medium | +|37 | 解数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sudoku-solver.rs) | [leetcode](https://leetcode-cn.com/problems/sudoku-solver/) | Hard | +|37 | 解数独 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sudoku-solver.rs) | [leetcode](https://leetcode-cn.com/problems/sudoku-solver/) | Hard | +|38 | 外观数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-and-say.rs) | [leetcode](https://leetcode-cn.com/problems/count-and-say/) | Medium | +|39 | 组合总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum/) | Medium | +|41 | 缺失的第一个正数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-missing-positive.rs) | [leetcode](https://leetcode-cn.com/problems/first-missing-positive/) | Hard | +|42 | 接雨水 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/trapping-rain-water.rs) | [leetcode](https://leetcode-cn.com/problems/trapping-rain-water/) | Hard | +|42 | 接雨水 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/trapping-rain-water.rs) | [leetcode](https://leetcode-cn.com/problems/trapping-rain-water/) | Hard | +|43 | 字符串相乘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/multiply-strings.rs) | [leetcode](https://leetcode-cn.com/problems/multiply-strings/) | Medium | +|45 | 跳跃游戏 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-ii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-ii/) | Medium | +|46 | 全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutations.rs) | [leetcode](https://leetcode-cn.com/problems/permutations/) | Medium | +|48 | 旋转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotate-image.rs) | [leetcode](https://leetcode-cn.com/problems/rotate-image/) | Medium | +|49 | 字母异位词分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/group-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/group-anagrams/) | Medium | +|50 | Pow(x, n) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powx-n.rs) | [leetcode](https://leetcode-cn.com/problems/powx-n/) | Medium | +|51 | N 皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens/) | Hard | +|52 | N皇后 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-queens-ii.rs) | [leetcode](https://leetcode-cn.com/problems/n-queens-ii/) | Hard | +|53 | 最大子数组和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-subarray/) | Easy | +|54 | 螺旋矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix/) | Medium | +|55 | 跳跃游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game/) | Medium | +|56 | 合并区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-intervals.rs) | [leetcode](https://leetcode-cn.com/problems/merge-intervals/) | Medium | +|57 | 插入区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-interval.rs) | [leetcode](https://leetcode-cn.com/problems/insert-interval/) | Medium | +|58 | 最后一个单词的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-last-word.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-last-word/) | Easy | +|62 | 不同路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths/) | Medium | +|63 | 不同路径 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-paths-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-paths-ii/) | Medium | +|64 | 最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-sum/) | Medium | +|66 | 加一 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/plus-one.rs) | [leetcode](https://leetcode-cn.com/problems/plus-one/) | Easy | +|67 | 二进制求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-binary.rs) | [leetcode](https://leetcode-cn.com/problems/add-binary/) | Easy | +|69 | x 的平方根 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sqrtx.rs) | [leetcode](https://leetcode-cn.com/problems/sqrtx/) | Easy | +|70 | 爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/climbing-stairs/) | Easy | +|71 | 简化路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simplify-path.rs) | [leetcode](https://leetcode-cn.com/problems/simplify-path/) | Medium | +|72 | 编辑距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/edit-distance.rs) | [leetcode](https://leetcode-cn.com/problems/edit-distance/) | Hard | +|73 | 矩阵置零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/set-matrix-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/set-matrix-zeroes/) | Medium | +|74 | 搜索二维矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix/) | Medium | +|75 | 颜色分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-colors.rs) | [leetcode](https://leetcode-cn.com/problems/sort-colors/) | Medium | +|77 | 组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combinations.rs) | [leetcode](https://leetcode-cn.com/problems/combinations/) | Medium | +|78 | 子集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subsets.rs) | [leetcode](https://leetcode-cn.com/problems/subsets/) | Medium | +|79 | 单词搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-search.rs) | [leetcode](https://leetcode-cn.com/problems/word-search/) | Medium | +|80 | 删除有序数组中的重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array-ii/) | Medium | +|81 | 搜索旋转排序数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-rotated-sorted-array-ii/) | Medium | +|82 | 删除排序链表中的重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/) | Medium | +|83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | Easy | +|84 | 柱状图中最大的矩形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-rectangle-in-histogram.rs) | [leetcode](https://leetcode-cn.com/problems/largest-rectangle-in-histogram/) | Hard | +|85 | 最大矩形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-rectangle.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-rectangle/) | Hard | +|87 | 扰乱字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/scramble-string.rs) | [leetcode](https://leetcode-cn.com/problems/scramble-string/) | Hard | +|88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | Easy | +|89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Medium | +|91 | 解码方法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decode-ways.rs) | [leetcode](https://leetcode-cn.com/problems/decode-ways/) | Medium | +|93 | 复原 IP 地址 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/restore-ip-addresses.rs) | [leetcode](https://leetcode-cn.com/problems/restore-ip-addresses/) | Medium | +|94 | 二叉树的中序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-inorder-traversal/) | Easy | +|95 | 不同的二叉搜索树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees-ii.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees-ii/) | Medium | +|96 | 不同的二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/unique-binary-search-trees/) | Medium | +|98 | 验证二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/validate-binary-search-tree/) | Medium | +|100 | 相同的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/same-tree.rs) | [leetcode](https://leetcode-cn.com/problems/same-tree/) | Easy | +|101 | 对称二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/symmetric-tree.rs) | [leetcode](https://leetcode-cn.com/problems/symmetric-tree/) | Easy | +|102 | 二叉树的层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal/) | Medium | +|103 | 二叉树的锯齿形层序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-zigzag-level-order-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-zigzag-level-order-traversal/) | Medium | +|104 | 二叉树的最大深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/) | Easy | +|105 | 从前序与中序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-inorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/) | Medium | +|106 | 从中序与后序遍历序列构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-inorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/) | Medium | +|107 | 二叉树的层序遍历 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-level-order-traversal-ii.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/) | Medium | +|108 | 将有序数组转换为二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-sorted-array-to-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/) | Easy | +|110 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/balanced-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/balanced-binary-tree/) | Easy | +|111 | 二叉树的最小深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-depth-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/) | Easy | +|112 | 路径总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum/) | Easy | +|113 | 路径总和 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-ii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-ii/) | Medium | +|118 | 杨辉三角 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle/) | Easy | +|119 | 杨辉三角 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pascals-triangle-ii.rs) | [leetcode](https://leetcode-cn.com/problems/pascals-triangle-ii/) | Easy | +|120 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/triangle.rs) | [leetcode](https://leetcode-cn.com/problems/triangle/) | Medium | +|121 | 买卖股票的最佳时机 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/) | Easy | +|122 | 买卖股票的最佳时机 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-ii.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/) | Medium | +|124 | 二叉树中的最大路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-maximum-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-maximum-path-sum/) | Hard | +|125 | 验证回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/valid-palindrome/) | Easy | +|128 | 最长连续序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-consecutive-sequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-consecutive-sequence/) | Medium | +|129 | 求根节点到叶节点数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-root-to-leaf-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-root-to-leaf-numbers/) | Medium | +|136 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number.rs) | [leetcode](https://leetcode-cn.com/problems/single-number/) | Easy | +|137 | 只出现一次的数字 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-ii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-ii/) | Medium | +|139 | 单词拆分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-break.rs) | [leetcode](https://leetcode-cn.com/problems/word-break/) | Medium | +|143 | 重排链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reorder-list.rs) | [leetcode](https://leetcode-cn.com/problems/reorder-list/) | Medium | +|144 | 二叉树的前序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-preorder-traversal/) | Easy | +|145 | 二叉树的后序遍历 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-postorder-traversal/) | Easy | +|146 | LRU 缓存 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lru-cache.rs) | [leetcode](https://leetcode-cn.com/problems/lru-cache/) | Medium | +|148 | 排序链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-list.rs) | [leetcode](https://leetcode-cn.com/problems/sort-list/) | Medium | +|150 | 逆波兰表达式求值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/evaluate-reverse-polish-notation.rs) | [leetcode](https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/) | Medium | +|151 | 颠倒字符串中的单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-words-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-words-in-a-string/) | Medium | +|152 | 乘积最大子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-subarray/) | Medium | +|153 | 寻找旋转排序数组中的最小值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array/) | Medium | +|154 | 寻找旋转排序数组中的最小值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii/) | Hard | +|155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | Medium | +|162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | Medium | +|165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | Medium | +|166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | Medium | +|167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | Medium | +|168 | Excel表列名称 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-title.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-title/) | Easy | +|169 | 多数元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element/) | Easy | +|171 | Excel 表列序号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/excel-sheet-column-number.rs) | [leetcode](https://leetcode-cn.com/problems/excel-sheet-column-number/) | Easy | +|172 | 阶乘后的零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/factorial-trailing-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/factorial-trailing-zeroes/) | Medium | +|173 | 二叉搜索树迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-iterator/) | Medium | +|187 | 重复的DNA序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/repeated-dna-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/repeated-dna-sequences/) | Medium | +|190 | 颠倒二进制位 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-bits.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-bits/) | Easy | +|191 | 位1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-1-bits/) | Easy | +|198 | 打家劫舍 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber/) | Medium | +|199 | 二叉树的右视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-right-side-view.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-right-side-view/) | Medium | +|200 | 岛屿数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-islands/) | Medium | +|201 | 数字范围按位与 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bitwise-and-of-numbers-range.rs) | [leetcode](https://leetcode-cn.com/problems/bitwise-and-of-numbers-range/) | Medium | +|202 | 快乐数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/happy-number.rs) | [leetcode](https://leetcode-cn.com/problems/happy-number/) | Easy | +|203 | 移除链表元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-linked-list-elements.rs) | [leetcode](https://leetcode-cn.com/problems/remove-linked-list-elements/) | Easy | +|204 | 计数质数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-primes.rs) | [leetcode](https://leetcode-cn.com/problems/count-primes/) | Medium | +|205 | 同构字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/isomorphic-strings.rs) | [leetcode](https://leetcode-cn.com/problems/isomorphic-strings/) | Easy | +|206 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-linked-list/) | Easy | +|207 | 课程表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/course-schedule.rs) | [leetcode](https://leetcode-cn.com/problems/course-schedule/) | Medium | +|208 | 实现 Trie (前缀树) | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-trie-prefix-tree.rs) | [leetcode](https://leetcode-cn.com/problems/implement-trie-prefix-tree/) | Medium | +|211 | 添加与搜索单词 - 数据结构设计 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-add-and-search-words-data-structure.rs) | [leetcode](https://leetcode-cn.com/problems/design-add-and-search-words-data-structure/) | Medium | +|213 | 打家劫舍 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-ii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-ii/) | Medium | +|215 | 数组中的第K个最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-element-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-element-in-an-array/) | Medium | +|216 | 组合总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iii/) | Medium | +|217 | 存在重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate/) | Easy | +|219 | 存在重复元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/contains-duplicate-ii.rs) | [leetcode](https://leetcode-cn.com/problems/contains-duplicate-ii/) | Easy | +|222 | 完全二叉树的节点个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-complete-tree-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/count-complete-tree-nodes/) | Medium | +|223 | 矩形面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rectangle-area.rs) | [leetcode](https://leetcode-cn.com/problems/rectangle-area/) | Medium | +|225 | 用队列实现栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-stack-using-queues.rs) | [leetcode](https://leetcode-cn.com/problems/implement-stack-using-queues/) | Easy | +|226 | 翻转二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/invert-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/invert-binary-tree/) | Easy | +|228 | 汇总区间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/summary-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/summary-ranges/) | Easy | +|229 | 多数元素 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/majority-element-ii.rs) | [leetcode](https://leetcode-cn.com/problems/majority-element-ii/) | Medium | +|230 | 二叉搜索树中第K小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-bst/) | Medium | +|231 | 2 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-two.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-two/) | Easy | +|232 | 用栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-queue-using-stacks.rs) | [leetcode](https://leetcode-cn.com/problems/implement-queue-using-stacks/) | Easy | +|234 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindrome-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/palindrome-linked-list/) | Easy | +|235 | 二叉搜索树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) | Easy | +|236 | 二叉树的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/) | Medium | +|238 | 除自身以外数组的乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/product-of-array-except-self.rs) | [leetcode](https://leetcode-cn.com/problems/product-of-array-except-self/) | Medium | +|239 | 滑动窗口最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sliding-window-maximum.rs) | [leetcode](https://leetcode-cn.com/problems/sliding-window-maximum/) | Hard | +|240 | 搜索二维矩阵 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-a-2d-matrix-ii.rs) | [leetcode](https://leetcode-cn.com/problems/search-a-2d-matrix-ii/) | Medium | +|242 | 有效的字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-anagram.rs) | [leetcode](https://leetcode-cn.com/problems/valid-anagram/) | Easy | +|257 | 二叉树的所有路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-tree-paths.rs) | [leetcode](https://leetcode-cn.com/problems/binary-tree-paths/) | Easy | +|258 | 各位相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-digits.rs) | [leetcode](https://leetcode-cn.com/problems/add-digits/) | Easy | +|260 | 只出现一次的数字 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/single-number-iii.rs) | [leetcode](https://leetcode-cn.com/problems/single-number-iii/) | Medium | +|263 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ugly-number.rs) | [leetcode](https://leetcode-cn.com/problems/ugly-number/) | Easy | +|268 | 丢失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/missing-number.rs) | [leetcode](https://leetcode-cn.com/problems/missing-number/) | Easy | +|274 | H 指数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index.rs) | [leetcode](https://leetcode-cn.com/problems/h-index/) | Medium | +|275 | H 指数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/h-index-ii.rs) | [leetcode](https://leetcode-cn.com/problems/h-index-ii/) | Medium | +|278 | 第一个错误的版本 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-bad-version.rs) | [leetcode](https://leetcode-cn.com/problems/first-bad-version/) | Easy | +|279 | 完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-squares.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-squares/) | Medium | +|283 | 移动零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-zeroes.rs) | [leetcode](https://leetcode-cn.com/problems/move-zeroes/) | Easy | +|287 | 寻找重复数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-duplicate-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-duplicate-number/) | Medium | +|290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | +|292 | Nim 游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nim-game.rs) | [leetcode](https://leetcode-cn.com/problems/nim-game/) | Easy | +|297 | 二叉树的序列化与反序列化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree/) | Hard | +|300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | +|303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | +|307 | 区域和检索 - 数组可修改 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-mutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-mutable/) | Medium | +|309 | 最佳买卖股票时机含冷冻期 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-time-to-buy-and-sell-stock-with-cooldown.rs) | [leetcode](https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/) | Medium | +|318 | 最大单词长度乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-word-lengths.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) | Medium | +|319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | +|322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | +|326 | 3 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | +|334 | 递增的三元子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increasing-triplet-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/increasing-triplet-subsequence/) | Medium | +|337 | 打家劫舍 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-iii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-iii/) | Medium | +|338 | 比特位计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-bits.rs) | [leetcode](https://leetcode-cn.com/problems/counting-bits/) | Easy | +|344 | 反转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string/) | Easy | +|345 | 反转字符串中的元音字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-vowels-of-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-vowels-of-a-string/) | Easy | +|347 | 前 K 个高频元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/top-k-frequent-elements.rs) | [leetcode](https://leetcode-cn.com/problems/top-k-frequent-elements/) | Medium | +|349 | 两个数组的交集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays/) | Easy | +|350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | +|355 | 设计推特 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-twitter.rs) | [leetcode](https://leetcode-cn.com/problems/design-twitter/) | Medium | +|357 | 统计各位数字都不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | +|367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | +|371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | +|374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | +|376 | 摆动序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wiggle-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/wiggle-subsequence/) | Medium | +|378 | 有序矩阵中第 K 小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-sorted-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/) | Medium | +|380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | +|381 | O(1) 时间插入、删除和获取随机元素 - 允许重复 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed/) | Hard | +|382 | 链表随机节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/linked-list-random-node.rs) | [leetcode](https://leetcode-cn.com/problems/linked-list-random-node/) | Medium | +|383 | 赎金信 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ransom-note.rs) | [leetcode](https://leetcode-cn.com/problems/ransom-note/) | Easy | +|384 | 打乱数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shuffle-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/shuffle-an-array/) | Medium | +|386 | 字典序排数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographical-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographical-numbers/) | Medium | +|387 | 字符串中的第一个唯一字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-unique-character-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/first-unique-character-in-a-string/) | Easy | +|389 | 找不同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-difference.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-difference/) | Easy | +|390 | 消除游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/elimination-game.rs) | [leetcode](https://leetcode-cn.com/problems/elimination-game/) | Medium | +|392 | 判断子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/is-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/is-subsequence/) | Easy | +|393 | UTF-8 编码验证 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/utf-8-validation.rs) | [leetcode](https://leetcode-cn.com/problems/utf-8-validation/) | Medium | +|397 | 整数替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-replacement.rs) | [leetcode](https://leetcode-cn.com/problems/integer-replacement/) | Medium | +|398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | +|400 | 第 N 位数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nth-digit.rs) | [leetcode](https://leetcode-cn.com/problems/nth-digit/) | Medium | +|404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | +|406 | 根据身高重建队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/queue-reconstruction-by-height.rs) | [leetcode](https://leetcode-cn.com/problems/queue-reconstruction-by-height/) | Medium | +|409 | 最长回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindrome/) | Easy | +|412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | +|413 | 等差数列划分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/arithmetic-slices.rs) | [leetcode](https://leetcode-cn.com/problems/arithmetic-slices/) | Medium | +|415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | +|419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | +|423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | +|434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | +|438 | 找到字符串中所有字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-anagrams-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-anagrams-in-a-string/) | Medium | +|442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | +|445 | 两数相加 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers-ii.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers-ii/) | Medium | +|448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | +|449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | +|460 | LFU 缓存 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lfu-cache.rs) | [leetcode](https://leetcode-cn.com/problems/lfu-cache/) | Hard | +|461 | 汉明距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/hamming-distance.rs) | [leetcode](https://leetcode-cn.com/problems/hamming-distance/) | Easy | +|476 | 数字的补数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-complement.rs) | [leetcode](https://leetcode-cn.com/problems/number-complement/) | Easy | +|481 | 神奇字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magical-string.rs) | [leetcode](https://leetcode-cn.com/problems/magical-string/) | Medium | +|485 | 最大连续 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones/) | Easy | +|486 | 预测赢家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/predict-the-winner.rs) | [leetcode](https://leetcode-cn.com/problems/predict-the-winner/) | Medium | +|489 | 第 K 条最小指令 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-instructions.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-instructions/) | Hard | +|494 | 目标和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/target-sum/) | Medium | +|494 | 目标和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/target-sum/) | Medium | +|500 | 键盘行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/keyboard-row.rs) | [leetcode](https://leetcode-cn.com/problems/keyboard-row/) | Easy | +|504 | 七进制数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/base-7.rs) | [leetcode](https://leetcode-cn.com/problems/base-7/) | Easy | +|507 | 完美数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/perfect-number.rs) | [leetcode](https://leetcode-cn.com/problems/perfect-number/) | Easy | +|508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | +|513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | +|515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | +|520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | +|528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | +|530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | +|535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | +|538 | 把二叉搜索树转换为累加树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-bst-to-greater-tree.rs) | [leetcode](https://leetcode-cn.com/problems/convert-bst-to-greater-tree/) | Medium | +|541 | 反转字符串 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-string-ii/) | Easy | +|543 | 二叉树的直径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diameter-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/diameter-of-binary-tree/) | Easy | +|551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | +|560 | 和为 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | +|565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | +|581 | 最短无序连续子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shortest-unsorted-continuous-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/shortest-unsorted-continuous-subarray/) | Medium | +|594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | +|599 | 两个列表的最小索引总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-index-sum-of-two-lists.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-index-sum-of-two-lists/) | Easy | +|605 | 种花问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/can-place-flowers.rs) | [leetcode](https://leetcode-cn.com/problems/can-place-flowers/) | Easy | +|617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | +|621 | 任务调度器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/task-scheduler.rs) | [leetcode](https://leetcode-cn.com/problems/task-scheduler/) | Medium | +|623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | +|637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | +|643 | 子数组最大平均数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-average-subarray-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-average-subarray-i/) | Easy | +|647 | 回文子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindromic-substrings.rs) | [leetcode](https://leetcode-cn.com/problems/palindromic-substrings/) | Medium | +|649 | Dota2 参议院 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dota2-senate.rs) | [leetcode](https://leetcode-cn.com/problems/dota2-senate/) | Medium | +|650 | 只有两个键的键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2-keys-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/2-keys-keyboard/) | Medium | +|653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | +|657 | 机器人能否返回原点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-return-to-origin.rs) | [leetcode](https://leetcode-cn.com/problems/robot-return-to-origin/) | Easy | +|658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | +|674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | +|718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | +|722 | 删除注释 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-comments.rs) | [leetcode](https://leetcode-cn.com/problems/remove-comments/) | Medium | +|724 | 寻找数组的中心下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-pivot-index.rs) | [leetcode](https://leetcode-cn.com/problems/find-pivot-index/) | Easy | +|739 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/daily-temperatures.rs) | [leetcode](https://leetcode-cn.com/problems/daily-temperatures/) | Medium | +|742 | 转换成小写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/to-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/to-lower-case/) | Easy | +|782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | +|783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | +|784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | +|800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | +|825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | +|829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | +|834 | 模糊坐标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ambiguous-coordinates.rs) | [leetcode](https://leetcode-cn.com/problems/ambiguous-coordinates/) | Medium | +|842 | 翻转卡片游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/card-flipping-game.rs) | [leetcode](https://leetcode-cn.com/problems/card-flipping-game/) | Medium | +|857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | +|860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | +|861 | 翻转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/flipping-an-image.rs) | [leetcode](https://leetcode-cn.com/problems/flipping-an-image/) | Easy | +|862 | 字符串中的查找与替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-and-replace-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-and-replace-in-string/) | Medium | +|868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | +|879 | 到最近的人的最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximize-distance-to-closest-person.rs) | [leetcode](https://leetcode-cn.com/problems/maximize-distance-to-closest-person/) | Medium | +|890 | 柠檬水找零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lemonade-change.rs) | [leetcode](https://leetcode-cn.com/problems/lemonade-change/) | Easy | +|904 | 叶子相似的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/leaf-similar-trees.rs) | [leetcode](https://leetcode-cn.com/problems/leaf-similar-trees/) | Easy | +|905 | 最长的斐波那契子序列的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-longest-fibonacci-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence/) | Medium | +|906 | 模拟行走机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/walking-robot-simulation.rs) | [leetcode](https://leetcode-cn.com/problems/walking-robot-simulation/) | Medium | +|908 | 链表的中间结点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/middle-of-the-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/middle-of-the-linked-list/) | Easy | +|917 | 救生艇 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/boats-to-save-people.rs) | [leetcode](https://leetcode-cn.com/problems/boats-to-save-people/) | Medium | +|921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | +|924 | 公平的糖果交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | +|925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | +|932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | +|936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | +|937 | 股票价格跨度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-stock-span.rs) | [leetcode](https://leetcode-cn.com/problems/online-stock-span/) | Medium | +|947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | +|953 | 仅仅反转字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-only-letters.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-only-letters/) | Easy | +|954 | 环形子数组的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-circular-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-circular-subarray/) | Medium | +|967 | 下降路径最小和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-falling-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-falling-path-sum/) | Medium | +|977 | 不同的子序列 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distinct-subsequences-ii.rs) | [leetcode](https://leetcode-cn.com/problems/distinct-subsequences-ii/) | Hard | +|979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | +|981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | +|982 | 使数组唯一的最小增量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-increment-to-make-array-unique.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-increment-to-make-array-unique/) | Medium | +|983 | 验证栈序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/validate-stack-sequences.rs) | [leetcode](https://leetcode-cn.com/problems/validate-stack-sequences/) | Medium | +|1002 | 最大宽度坡 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-width-ramp.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-width-ramp/) | Medium | +|1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | Easy | +|1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | +|1010 | 强整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powerful-integers.rs) | [leetcode](https://leetcode-cn.com/problems/powerful-integers/) | Medium | +|1021 | 在二叉树中分配硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-coins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-coins-in-binary-tree/) | Medium | +|1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | +|1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | +|1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | +|1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | +|1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | +|1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | +|1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | +|1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | +|1218 | 最深叶节点的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-deepest-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves/) | Medium | +|1236 | 第 N 个泰波那契数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-th-tribonacci-number.rs) | [leetcode](https://leetcode-cn.com/problems/n-th-tribonacci-number/) | Easy | +|1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | +|1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | +|1263 | 掷骰子等于目标和的方法数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-dice-rolls-with-target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-dice-rolls-with-target-sum/) | Medium | +|1273 | 比较字符串最小字母出现频次 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-strings-by-frequency-of-the-smallest-character.rs) | [leetcode](https://leetcode-cn.com/problems/compare-strings-by-frequency-of-the-smallest-character/) | Medium | +|1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | +|1293 | 存在连续三个奇数的数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/three-consecutive-odds.rs) | [leetcode](https://leetcode-cn.com/problems/three-consecutive-odds/) | Easy | +|1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | +|1319 | 独一无二的出现次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-number-of-occurrences.rs) | [leetcode](https://leetcode-cn.com/problems/unique-number-of-occurrences/) | Easy | +|1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | +|1329 | 玩筹码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cost-to-move-chips-to-the-same-position.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position/) | Easy | +|1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | +|1342 | 可以攻击国王的皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/queens-that-can-attack-the-king.rs) | [leetcode](https://leetcode-cn.com/problems/queens-that-can-attack-the-king/) | Medium | +|1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | +|1363 | 兼具大小写的最好英文字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/greatest-english-letter-in-upper-and-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/greatest-english-letter-in-upper-and-lower-case/) | Easy | +|1364 | 同积元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tuple-with-same-product.rs) | [leetcode](https://leetcode-cn.com/problems/tuple-with-same-product/) | Medium | +|1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | +|1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | +|1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | +|1380 | 统计封闭岛屿的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-closed-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-closed-islands/) | Medium | +|1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | +|1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | +|1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | +|1406 | 整数的各位积和之差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/) | Easy | +|1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | +|1426 | 和为零的 N 个不同整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | +|1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Medium | +|1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | Easy | +|1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | +|1450 | 删除给定值的叶子节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-leaves-with-a-given-value.rs) | [leetcode](https://leetcode-cn.com/problems/delete-leaves-with-a-given-value/) | Medium | +|1455 | 餐厅过滤器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/filter-restaurants-by-vegan-friendly-price-and-distance.rs) | [leetcode](https://leetcode-cn.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance/) | Medium | +|1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | +|1472 | 上升下降字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increasing-decreasing-string.rs) | [leetcode](https://leetcode-cn.com/problems/increasing-decreasing-string/) | Easy | +|1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | +|1491 | 二进制字符串前缀一致的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-times-binary-string-is-prefix-aligned.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-times-binary-string-is-prefix-aligned/) | Medium | +|1501 | 圆和矩形是否有重叠 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circle-and-rectangle-overlapping.rs) | [leetcode](https://leetcode-cn.com/problems/circle-and-rectangle-overlapping/) | Medium | +|1503 | 做菜顺序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reducing-dishes.rs) | [leetcode](https://leetcode-cn.com/problems/reducing-dishes/) | Hard | +|1505 | 按既定顺序创建目标数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/create-target-array-in-the-given-order.rs) | [leetcode](https://leetcode-cn.com/problems/create-target-array-in-the-given-order/) | Easy | +|1512 | 设计地铁系统 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-underground-system.rs) | [leetcode](https://leetcode-cn.com/problems/design-underground-system/) | Medium | +|1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | +|1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | +|1544 | 统计二叉树中好节点的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-nodes-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-nodes-in-binary-tree/) | Medium | +|1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | +|1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | +|1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Medium | +|1575 | 切割后面积最大的蛋糕 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/) | Medium | +|1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | +|1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | +|1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | +|1636 | 仅含 1 的子串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-substrings-with-only-1s.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-substrings-with-only-1s/) | Medium | +|1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | Easy | +|1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | Easy | +|1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | +|1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | +|1677 | 矩阵对角线元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/matrix-diagonal-sum.rs) | [leetcode](https://leetcode-cn.com/problems/matrix-diagonal-sum/) | Easy | +|1782 | 具有给定数值的最小字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-string-with-a-given-numeric-value.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-string-with-a-given-numeric-value/) | Medium | +|1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | +|1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | +|1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | +|1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | +|1829 | 卡车上的最大单元数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-units-on-a-truck.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-units-on-a-truck/) | Easy | +|1849 | 任意子数组和的绝对值的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-absolute-sum-of-any-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | +|1858 | 替换隐藏数字得到的最晚时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/latest-time-by-replacing-hidden-digits.rs) | [leetcode](https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits/) | Easy | +|1894 | 交替合并字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-strings-alternately.rs) | [leetcode](https://leetcode-cn.com/problems/merge-strings-alternately/) | Easy | +|1929 | 有界数组中指定下标处的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-at-a-given-index-in-a-bounded-array/) | Medium | +|1938 | 最少操作使数组递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-make-the-array-increasing.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-increasing/) | Easy | +|1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | +|1952 | 最少侧跳次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sideway-jumps.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sideway-jumps/) | Medium | +|1971 | 增长的内存泄露 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/incremental-memory-leak.rs) | [leetcode](https://leetcode-cn.com/problems/incremental-memory-leak/) | Medium | +|1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | +|2022 | 最大子序列交替和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-alternating-subsequence-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-alternating-subsequence-sum/) | Medium | +|2049 | 消灭怪物的最大数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/eliminate-maximum-number-of-monsters.rs) | [leetcode](https://leetcode-cn.com/problems/eliminate-maximum-number-of-monsters/) | Medium | +|2053 | 检查是否所有字符出现次数相同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-all-characters-have-equal-number-of-occurrences.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-all-characters-have-equal-number-of-occurrences/) | Easy | +|2104 | 树上的操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/operations-on-tree.rs) | [leetcode](https://leetcode-cn.com/problems/operations-on-tree/) | Medium | +|2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | +|2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | +|2161 | 股票价格波动 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/stock-price-fluctuation.rs) | [leetcode](https://leetcode-cn.com/problems/stock-price-fluctuation/) | Medium | +|2177 | 检查两个字符串是否几乎相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-whether-two-strings-are-almost-equivalent.rs) | [leetcode](https://leetcode-cn.com/problems/check-whether-two-strings-are-almost-equivalent/) | Easy | +|2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | +|2226 | 环和杆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rings-and-rods.rs) | [leetcode](https://leetcode-cn.com/problems/rings-and-rods/) | Easy | +|2233 | 股票平滑下跌阶段的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-smooth-descent-periods-of-a-stock.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-smooth-descent-periods-of-a-stock/) | Medium | +|2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | +|2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | +|2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | +|2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | +|2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | +|2310 | 将数组和减半的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-halve-array-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-halve-array-sum/) | Medium | +|2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | +|2346 | 字符串中最大的 3 位相同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-3-same-digit-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-3-same-digit-number-in-string/) | Easy | +|2351 | 买钢笔和铅笔的方案数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-ways-to-buy-pens-and-pencils.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-ways-to-buy-pens-and-pencils/) | Medium | +|2384 | 判断根结点是否等于子结点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/root-equals-sum-of-children.rs) | [leetcode](https://leetcode-cn.com/problems/root-equals-sum-of-children/) | Easy | +|2386 | 极大极小游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-max-game.rs) | [leetcode](https://leetcode-cn.com/problems/min-max-game/) | Easy | +|2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | +|2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | +|2470 | 从字符串中移除星号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-stars-from-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/removing-stars-from-a-string/) | Medium | +|2473 | 数位和相等数对的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs) | [leetcode](https://leetcode-cn.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | +|2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | +|2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | +|2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | +|2571 | 找出中枢整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-pivot-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-pivot-integer/) | Easy | +|2575 | 分割圆的最少切割次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cuts-to-divide-a-circle.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cuts-to-divide-a-circle/) | Easy | +|2580 | 回环句 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circular-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/circular-sentence/) | Easy | +|2585 | 删除每行中的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-greatest-value-in-each-row.rs) | [leetcode](https://leetcode-cn.com/problems/delete-greatest-value-in-each-row/) | Easy | +|2589 | 数组中字符串的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-a-string-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-a-string-in-an-array/) | Easy | +|2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | +|2603 | 奖励最顶尖的 K 名学生 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reward-top-k-students.rs) | [leetcode](https://leetcode-cn.com/problems/reward-top-k-students/) | Medium | +|2608 | 统计能整除数字的位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-the-digits-that-divide-a-number.rs) | [leetcode](https://leetcode-cn.com/problems/count-the-digits-that-divide-a-number/) | Easy | +|2616 | 执行 K 次操作后的最大分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-score-after-applying-k-operations.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-score-after-applying-k-operations/) | Medium | +|2619 | 根据规则将箱子分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/categorize-box-according-to-criteria.rs) | [leetcode](https://leetcode-cn.com/problems/categorize-box-according-to-criteria/) | Easy | +|2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | +|2645 | 递枕头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pass-the-pillow.rs) | [leetcode](https://leetcode-cn.com/problems/pass-the-pillow/) | Easy | +|2650 | 最小和分割 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-with-minimum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/split-with-minimum-sum/) | Easy | +|2654 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-the-number-of-vowel-strings-in-range.rs) | [leetcode](https://leetcode-cn.com/problems/count-the-number-of-vowel-strings-in-range/) | Easy | +|2662 | 检查骑士巡视方案 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-knight-tour-configuration.rs) | [leetcode](https://leetcode-cn.com/problems/check-knight-tour-configuration/) | Medium | +|2663 | 将钱分给最多的儿童 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-money-to-maximum-children.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-money-to-maximum-children/) | Easy | +|2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | +|2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | +|2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | +|2679 | 统计桌面上的不同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-distinct-numbers-on-board.rs) | [leetcode](https://leetcode-cn.com/problems/count-distinct-numbers-on-board/) | Easy | +|2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | +|2692 | 从数量最多的堆取走礼物 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/take-gifts-from-the-richest-pile.rs) | [leetcode](https://leetcode-cn.com/problems/take-gifts-from-the-richest-pile/) | Easy | +|2692 | 从数量最多的堆取走礼物 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/take-gifts-from-the-richest-pile.rs) | [leetcode](https://leetcode-cn.com/problems/take-gifts-from-the-richest-pile/) | Easy | +|2694 | 找出可整除性得分最大的整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-divisibility-score.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-divisibility-score/) | Easy | +|2698 | 找出数组的串联值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-array-concatenation-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-array-concatenation-value/) | Easy | +|2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | +|2723 | 最长平衡子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-longest-balanced-substring-of-a-binary-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-longest-balanced-substring-of-a-binary-string/) | Easy | +|2727 | 老人的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-senior-citizens.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-senior-citizens/) | Easy | +|2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | +|2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | +|2752 | 倍数求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-multiples.rs) | [leetcode](https://leetcode-cn.com/problems/sum-multiples/) | Easy | +|2767 | K 个元素的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-with-exactly-k-elements.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-with-exactly-k-elements/) | Easy | +|2787 | 移动机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/movement-of-robots.rs) | [leetcode](https://leetcode-cn.com/problems/movement-of-robots/) | Medium | +|2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | +|2802 | 求一个整数的惩罚数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-punishment-number-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-punishment-number-of-an-integer/) | Medium | +|2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | +|2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | +|2866 | 最长奇偶子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-even-odd-subarray-with-threshold.rs) | [leetcode](https://leetcode-cn.com/problems/longest-even-odd-subarray-with-threshold/) | Easy | +|2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | +|3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | +|3152 | 有序三元组中的最大值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-an-ordered-triplet-ii.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-an-ordered-triplet-ii/) | Medium | +|100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | +|100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | +|100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | +|100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | +|100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | +|100276 | 二维数组中的查找 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-wei-shu-zu-zhong-de-cha-zhao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/) | Medium | +|100277 | 青蛙跳台阶问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qing-wa-tiao-tai-jie-wen-ti-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qing-wa-tiao-tai-jie-wen-ti-lcof/) | Easy | +|100278 | 旋转数组的最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/) | Easy | +|100279 | 矩阵中的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ju-zhen-zhong-de-lu-jing-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ju-zhen-zhong-de-lu-jing-lcof/) | Medium | +|100280 | 替换空格 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ti-huan-kong-ge-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/) | Easy | +|100281 | 机器人的运动范围 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ji-qi-ren-de-yun-dong-fan-wei-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/) | Medium | +|100282 | 从尾到头打印链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-wei-dao-tou-da-yin-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/) | Easy | +|100283 | 重建二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhong-jian-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof/) | Medium | +|100284 | 剪绳子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-lcof/) | Medium | +|100285 | 剪绳子 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jian-sheng-zi-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/jian-sheng-zi-ii-lcof/) | Medium | +|100286 | 合并两个排序的链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/he-bing-liang-ge-pai-xu-de-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/) | Easy | +|100287 | 树的子结构 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-de-zi-jie-gou-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-de-zi-jie-gou-lcof/) | Medium | +|100288 | 二叉树的镜像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-jing-xiang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-jing-xiang-lcof/) | Easy | +|100289 | 对称的二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dui-cheng-de-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof/) | Easy | +|100290 | 表示数值的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/biao-shi-shu-zhi-de-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/biao-shi-shu-zhi-de-zi-fu-chuan-lcof/) | Medium | +|100291 | 调整数组顺序使奇数位于偶数前面 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/) | Easy | +|100292 | 二进制中1的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-jin-zhi-zhong-1de-ge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/) | Easy | +|100293 | 顺时针打印矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shun-shi-zhen-da-yin-ju-zhen-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shun-shi-zhen-da-yin-ju-zhen-lcof/) | Easy | +|100294 | 链表中倒数第k个节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/) | Easy | +|100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | +|100295 | 数值的整数次方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zhi-de-zheng-shu-ci-fang-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/) | Medium | +|100296 | 打印从1到最大的n位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) | Easy | +|100296 | 打印从1到最大的n位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/) | Easy | +|100298 | 反转链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fan-zhuan-lian-biao-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fan-zhuan-lian-biao-lcof/) | Easy | +|100299 | 删除链表的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shan-chu-lian-biao-de-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/) | Easy | +|100301 | 最小的k个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-xiao-de-kge-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-xiao-de-kge-shu-lcof/) | Easy | +|100302 | 包含min函数的栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bao-han-minhan-shu-de-zhan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof/) | Easy | +|100303 | 数据流中的中位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-ju-liu-zhong-de-zhong-wei-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-ju-liu-zhong-de-zhong-wei-shu-lcof/) | Hard | +|100304 | 连续子数组的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lian-xu-zi-shu-zu-de-zui-da-he-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/) | Easy | +|100306 | 栈的压入、弹出序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zhan-de-ya-ru-dan-chu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) | Medium | +|100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | +|100308 | 字符串的排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zi-fu-chuan-de-pai-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof/) | Medium | +|100309 | 1~n 整数中 1 出现的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof/) | Hard | +|100310 | 数组中出现次数超过一半的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof/) | Easy | +|100311 | 从上到下打印二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-lcof/) | Medium | +|100312 | 从上到下打印二叉树 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof/) | Easy | +|100313 | 数字序列中某一位的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof/) | Medium | +|100314 | 从上到下打印二叉树 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof/) | Medium | +|100315 | 二叉搜索树的后序遍历序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof/) | Medium | +|100316 | 第一个只出现一次的字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/) | Easy | +|100317 | 二叉树中和为某一值的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-zhong-he-wei-mou-yi-zhi-de-lu-jing-lcof/) | Medium | +|100318 | 数组中的逆序对 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-de-ni-xu-dui-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/) | Hard | +|100319 | 二叉树的深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-shen-du-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) | Easy | +|100319 | 二叉树的深度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-shu-de-shen-du-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-shu-de-shen-du-lcof/) | Easy | +|100320 | 数组中数字出现的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/) | Medium | +|100321 | 数组中数字出现的次数 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof/) | Medium | +|100322 | 和为s的两个数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/he-wei-sde-liang-ge-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof/) | Easy | +|100323 | 把数组排成最小的数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof/) | Medium | +|100324 | 和为s的连续正数序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof/) | Easy | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | +|100325 | 把数字翻译成字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/) | Medium | +|100327 | 礼物的最大价值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/li-wu-de-zui-da-jie-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/) | Medium | +|100328 | 翻转单词顺序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fan-zhuan-dan-ci-shun-xu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof/) | Easy | +|100329 | 在排序数组中查找数字 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/) | Easy | +|100330 | 左旋转字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zuo-xuan-zhuan-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/) | Easy | +|100331 | 0~n-1中缺失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/que-shi-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof/) | Easy | +|100332 | 最长不含重复字符的子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/) | Medium | +|100333 | 二叉搜索树的第k大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/) | Easy | +|100334 | 丑数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chou-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/chou-shu-lcof/) | Medium | +|100335 | 不用加减乘除做加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/) | Easy | +|100337 | 队列的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dui-lie-de-zui-da-zhi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/dui-lie-de-zui-da-zhi-lcof/) | Medium | +|100338 | 构建乘积数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gou-jian-cheng-ji-shu-zu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gou-jian-cheng-ji-shu-zu-lcof/) | Medium | +|100339 | n个骰子的点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nge-tou-zi-de-dian-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/nge-tou-zi-de-dian-shu-lcof/) | Medium | +|100340 | 把字符串转换成整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof/) | Medium | +|100341 | 扑克牌中的顺子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bu-ke-pai-zhong-de-shun-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/bu-ke-pai-zhong-de-shun-zi-lcof/) | Easy | +|100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | +|100342 | 平衡二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ping-heng-er-cha-shu-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/ping-heng-er-cha-shu-lcof/) | Easy | +|100343 | 圆圈中最后剩下的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/) | Easy | +|100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | +|100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | +|100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | +|100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | +|100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | +|1000021 | 最小K个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-k-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-k-lcci/) | Medium | +|1000022 | 最长单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-word-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/longest-word-lcci/) | Medium | +|1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | +|1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | +|1000228 | 整数除法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xoh6Oh.rs) | [leetcode](https://leetcode-cn.com/problems/xoh6Oh/) | Easy | +|1000230 | 前 n 个数字二进制中 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/w3tCBm.rs) | [leetcode](https://leetcode-cn.com/problems/w3tCBm/) | Easy | +|1000231 | 二进制加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/JFETK5.rs) | [leetcode](https://leetcode-cn.com/problems/JFETK5/) | Easy | +|1000233 | 只出现一次的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WGki4K.rs) | [leetcode](https://leetcode-cn.com/problems/WGki4K/) | Medium | +|1000236 | 单词长度的最大乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aseY1I.rs) | [leetcode](https://leetcode-cn.com/problems/aseY1I/) | Medium | +|1000237 | 排序数组中两个数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kLl5u1.rs) | [leetcode](https://leetcode-cn.com/problems/kLl5u1/) | Easy | +|1000238 | 括号生成 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/IDBivT.rs) | [leetcode](https://leetcode-cn.com/problems/IDBivT/) | Medium | +|1000242 | 和大于等于 target 的最短子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/2VG8Kg.rs) | [leetcode](https://leetcode-cn.com/problems/2VG8Kg/) | Medium | +|1000244 | 乘积小于 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ZVAVXX.rs) | [leetcode](https://leetcode-cn.com/problems/ZVAVXX/) | Medium | +|1000246 | 和为 k 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/QTMn0o.rs) | [leetcode](https://leetcode-cn.com/problems/QTMn0o/) | Medium | +|1000247 | 0 和 1 个数相同的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/A1NYOS.rs) | [leetcode](https://leetcode-cn.com/problems/A1NYOS/) | Medium | +|1000248 | 左右两边子数组的和相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tvdfij.rs) | [leetcode](https://leetcode-cn.com/problems/tvdfij/) | Easy | +|1000249 | 二维子矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/O4NDxx.rs) | [leetcode](https://leetcode-cn.com/problems/O4NDxx/) | Medium | +|1000250 | 字符串中的变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/MPnaiL.rs) | [leetcode](https://leetcode-cn.com/problems/MPnaiL/) | Medium | +|1000251 | 字符串中的所有变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/VabMRr.rs) | [leetcode](https://leetcode-cn.com/problems/VabMRr/) | Medium | +|1000252 | 不含重复字符的最长子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wtcaE1.rs) | [leetcode](https://leetcode-cn.com/problems/wtcaE1/) | Medium | +|1000254 | 有效的回文 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XltzEq.rs) | [leetcode](https://leetcode-cn.com/problems/XltzEq/) | Easy | +|1000255 | 最多删除一个字符得到回文 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/RQku0D.rs) | [leetcode](https://leetcode-cn.com/problems/RQku0D/) | Easy | +|1000256 | 回文子字符串的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/a7VOhD.rs) | [leetcode](https://leetcode-cn.com/problems/a7VOhD/) | Medium | +|1000261 | 链表中的两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lMSNwu.rs) | [leetcode](https://leetcode-cn.com/problems/lMSNwu/) | Medium | +|1000262 | 重排链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/LGjMqU.rs) | [leetcode](https://leetcode-cn.com/problems/LGjMqU/) | Medium | +|1000263 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aMhZSa.rs) | [leetcode](https://leetcode-cn.com/problems/aMhZSa/) | Easy | +|1000273 | 有效的变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dKk3P7.rs) | [leetcode](https://leetcode-cn.com/problems/dKk3P7/) | Easy | +|1000275 | 变位词组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sfvd7V.rs) | [leetcode](https://leetcode-cn.com/problems/sfvd7V/) | Medium | +|1000276 | 外星语言是否排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lwyVBB.rs) | [leetcode](https://leetcode-cn.com/problems/lwyVBB/) | Easy | +|1000278 | 最小时间差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/569nqc.rs) | [leetcode](https://leetcode-cn.com/problems/569nqc/) | Medium | +|1000279 | 后缀表达式 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/8Zf90G.rs) | [leetcode](https://leetcode-cn.com/problems/8Zf90G/) | Medium | +|1000281 | 小行星碰撞 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XagZNi.rs) | [leetcode](https://leetcode-cn.com/problems/XagZNi/) | Medium | +|1000282 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/iIQa4I.rs) | [leetcode](https://leetcode-cn.com/problems/iIQa4I/) | Medium | +|1000288 | 加减的目标值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/YaVDxD.rs) | [leetcode](https://leetcode-cn.com/problems/YaVDxD/) | Medium | +|1000292 | 滑动窗口的平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qIsx9U.rs) | [leetcode](https://leetcode-cn.com/problems/qIsx9U/) | Easy | +|1000295 | 往完全二叉树添加节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NaqhDT.rs) | [leetcode](https://leetcode-cn.com/problems/NaqhDT/) | Medium | +|1000297 | 二叉树每层的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/hPov7L.rs) | [leetcode](https://leetcode-cn.com/problems/hPov7L/) | Medium | +|1000298 | 二叉树最底层最左边的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/LwUNpT.rs) | [leetcode](https://leetcode-cn.com/problems/LwUNpT/) | Medium | +|1000299 | 二叉树的右侧视图 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WNC0Lk.rs) | [leetcode](https://leetcode-cn.com/problems/WNC0Lk/) | Medium | +|1000301 | 二叉树剪枝 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pOCWxh.rs) | [leetcode](https://leetcode-cn.com/problems/pOCWxh/) | Medium | +|1000306 | 从根节点到叶节点的路径数字之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/3Etpl5.rs) | [leetcode](https://leetcode-cn.com/problems/3Etpl5/) | Medium | +|1000307 | 向下的路径节点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/6eUYwP.rs) | [leetcode](https://leetcode-cn.com/problems/6eUYwP/) | Medium | +|1000311 | 展平二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NYBBNL.rs) | [leetcode](https://leetcode-cn.com/problems/NYBBNL/) | Easy | +|1000319 | 二叉搜索树中两个节点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/opLdQZ.rs) | [leetcode](https://leetcode-cn.com/problems/opLdQZ/) | Easy | +|1000321 | 值和下标之差都在给定的范围内 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WqeDu.rs) | [leetcode](https://leetcode-cn.com/problems/7WqeDu/) | Medium | +|1000333 | 山峰数组的顶部 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/B1IidL.rs) | [leetcode](https://leetcode-cn.com/problems/B1IidL/) | Easy | +|1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | +|1000433 | 宝石补给 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WHnhjV.rs) | [leetcode](https://leetcode-cn.com/problems/WHnhjV/) | Easy | From a498a4b9e3504eff200aa2dd8ca61a10cf7b6088 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 22 Nov 2023 21:53:24 +0800 Subject: [PATCH 1094/1556] src/bin/minimum-path-cost-in-a-grid.rs --- src/bin/minimum-path-cost-in-a-grid.rs | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/minimum-path-cost-in-a-grid.rs diff --git a/src/bin/minimum-path-cost-in-a-grid.rs b/src/bin/minimum-path-cost-in-a-grid.rs new file mode 100644 index 00000000..6df0bba7 --- /dev/null +++ b/src/bin/minimum-path-cost-in-a-grid.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_path_cost(mut grid: Vec>, move_cost: Vec>) -> i32 { + // let mut v = vec![vec![0; grid[0].len()]; grid.len()]; + // for i in 0..grid[0].len() { + // v[grid.len() - 1][i] = grid[grid.len() - 1][i]; + // } + + for i in (0..grid.len() - 1).rev() { + for j in 0..grid[0].len() { + let mut min = move_cost[grid[i][j] as usize][0] + grid[i + 1][0] + grid[i][j]; + for k in 1..move_cost[grid[i][j] as usize].len() { + min = min.min(move_cost[grid[i][j] as usize][k] + grid[i + 1][k] + grid[i][j]); + } + + grid[i][j] = min; + } + } + + *grid[0].iter().min().unwrap() + } +} From cbd87e0ff3b240707e16d49c11bcb4d04b097863 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 22 Nov 2023 21:53:24 +0800 Subject: [PATCH 1095/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b63b6471..d319ee4e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 593 | 255 | 310 | 28 | +| 594 | 255 | 311 | 28 | ### 题目 @@ -356,6 +356,7 @@ |1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | |1380 | 统计封闭岛屿的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-closed-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-closed-islands/) | Medium | |1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | +|1394 | 网格中的最小路径代价 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-cost-in-a-grid.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-cost-in-a-grid/) | Medium | |1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | |1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | |1406 | 整数的各位积和之差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/) | Easy | From 3f8d4d2f9067c01557257bf12b49d7a363c27ec4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 23 Nov 2023 08:37:48 +0800 Subject: [PATCH 1096/1556] src/bin/html-entity-parser.rs --- src/bin/html-entity-parser.rs | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/bin/html-entity-parser.rs diff --git a/src/bin/html-entity-parser.rs b/src/bin/html-entity-parser.rs new file mode 100644 index 00000000..dbec471d --- /dev/null +++ b/src/bin/html-entity-parser.rs @@ -0,0 +1,39 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn entity_parser(text: String) -> String { + let mut string = String::new(); + let mut s = &text[..]; + + while !s.is_empty() { + if s.starts_with(""") { + string.push('"'); + s = &s[6..] + } else if s.starts_with("&apos") { + string.push('\''); + s = &s[6..] + } else if s.starts_with("&") { + string.push('&'); + s = &s[5..] + } else if s.starts_with(">") { + string.push('>'); + s = &s[4..] + } else if s.starts_with("<") { + string.push('<'); + s = &s[4..] + } else if s.starts_with("⁄") { + string.push('/'); + s = &s[7..] + } else { + string.push_str(&s[0..1]); + s = &s[1..]; + } + } + + string + } +} From adaccabd24ad715074d2da6778a90837c363e187 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 23 Nov 2023 08:37:49 +0800 Subject: [PATCH 1097/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d319ee4e..291b92ba 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 594 | 255 | 311 | 28 | +| 595 | 255 | 312 | 28 | ### 题目 @@ -375,6 +375,7 @@ |1503 | 做菜顺序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reducing-dishes.rs) | [leetcode](https://leetcode-cn.com/problems/reducing-dishes/) | Hard | |1505 | 按既定顺序创建目标数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/create-target-array-in-the-given-order.rs) | [leetcode](https://leetcode-cn.com/problems/create-target-array-in-the-given-order/) | Easy | |1512 | 设计地铁系统 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-underground-system.rs) | [leetcode](https://leetcode-cn.com/problems/design-underground-system/) | Medium | +|1526 | HTML 实体解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/html-entity-parser.rs) | [leetcode](https://leetcode-cn.com/problems/html-entity-parser/) | Medium | |1537 | 分割字符串的最大得分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-score-after-splitting-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-score-after-splitting-a-string/) | Easy | |1538 | 可获得的最大点数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-points-you-can-obtain-from-cards.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-points-you-can-obtain-from-cards/) | Medium | |1544 | 统计二叉树中好节点的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-nodes-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-nodes-in-binary-tree/) | Medium | From 3d7a26a793a75330b574ed491fd5f387ab744013 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 24 Nov 2023 08:46:19 +0800 Subject: [PATCH 1098/1556] src/bin/count-pairs-whose-sum-is-less-than-target.rs --- ...unt-pairs-whose-sum-is-less-than-target.rs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bin/count-pairs-whose-sum-is-less-than-target.rs diff --git a/src/bin/count-pairs-whose-sum-is-less-than-target.rs b/src/bin/count-pairs-whose-sum-is-less-than-target.rs new file mode 100644 index 00000000..f94d47b1 --- /dev/null +++ b/src/bin/count-pairs-whose-sum-is-less-than-target.rs @@ -0,0 +1,40 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_pairs(nums: Vec, target: i32) -> i32 { + if nums.len() < 2 { + return 0; + } + + let mut nums = nums; + nums.sort(); + + let (mut s1, mut s2) = (0, 1); // 双指针 + let mut result = 0; + + for i in 1..nums.len() { + result += Self::search(target - nums[i], &nums[..i]); + } + + result + } + + fn search(target: i32, nums: &[i32]) -> i32 { + let (mut start, mut end) = (0, nums.len()); + + while start < end { + let middle = start + (end - start) / 2; + if nums[middle] < target { + start = middle + 1; + } else { + end = middle; + } + } + + end as i32 + } +} From 71146fd417d70820a858c9edc89899edfb5dc580 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 24 Nov 2023 08:46:20 +0800 Subject: [PATCH 1099/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 291b92ba..c3f28a8b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 595 | 255 | 312 | 28 | +| 596 | 256 | 312 | 28 | ### 题目 @@ -474,6 +474,7 @@ |2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |2866 | 最长奇偶子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-even-odd-subarray-with-threshold.rs) | [leetcode](https://leetcode-cn.com/problems/longest-even-odd-subarray-with-threshold/) | Easy | +|2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | |3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | |3152 | 有序三元组中的最大值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-an-ordered-triplet-ii.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-an-ordered-triplet-ii/) | Medium | From a46ec0dad827e24e9c4a0bdbc796cf145351aea6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 Nov 2023 12:33:10 +0800 Subject: [PATCH 1100/1556] src/bin/pseudo-palindromic-paths-in-a-binary-tree.rs --- ...eudo-palindromic-paths-in-a-binary-tree.rs | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/bin/pseudo-palindromic-paths-in-a-binary-tree.rs diff --git a/src/bin/pseudo-palindromic-paths-in-a-binary-tree.rs b/src/bin/pseudo-palindromic-paths-in-a-binary-tree.rs new file mode 100644 index 00000000..d5118c06 --- /dev/null +++ b/src/bin/pseudo-palindromic-paths-in-a-binary-tree.rs @@ -0,0 +1,61 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +impl Solution { + pub fn pseudo_palindromic_paths(root: Option>>) -> i32 { + let mut map = [0; 10]; + Self::dfs(root, &mut map) + } + + fn dfs(root: Option>>, map: &mut [u8]) -> i32 { + if root.is_none() { + return 0; + } + + let root = root.unwrap(); + let root_val = root.borrow().val; + let left = root.borrow_mut().left.take(); + let right = root.borrow_mut().right.take(); + + map[(root_val - 0) as usize] += 1; + + let value = if left.is_none() && right.is_none() { + if map.iter().filter(|x| **x % 2 == 1).count() > 1 { + 0 + } else { + 1 + } + } else { + Self::dfs(left, map) + Self::dfs(right, map) + }; + + map[(root_val - 0) as usize] -= 1; + + value + } +} From 737caabc1981e40abff07467c13a645927954d7c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 Nov 2023 12:33:11 +0800 Subject: [PATCH 1101/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c3f28a8b..75efc4c0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 596 | 256 | 312 | 28 | +| 597 | 256 | 313 | 28 | ### 题目 @@ -382,6 +382,7 @@ |1552 | 用栈操作构建数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/build-an-array-with-stack-operations.rs) | [leetcode](https://leetcode-cn.com/problems/build-an-array-with-stack-operations/) | Easy | |1566 | 检查单词是否为句中其他单词的前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | |1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Medium | +|1568 | 二叉树中的伪回文路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pseudo-palindromic-paths-in-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/pseudo-palindromic-paths-in-a-binary-tree/) | Medium | |1575 | 切割后面积最大的蛋糕 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/) | Medium | |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | |1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | From 92bdd7ad550effa3969513787052620ff27077b0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 26 Nov 2023 12:26:56 +0800 Subject: [PATCH 1102/1556] src/bin/living-people-lcci.rs --- src/bin/living-people-lcci.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/living-people-lcci.rs diff --git a/src/bin/living-people-lcci.rs b/src/bin/living-people-lcci.rs new file mode 100644 index 00000000..aedc89c3 --- /dev/null +++ b/src/bin/living-people-lcci.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cmp::max; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_alive_year(birth: Vec, death: Vec) -> i32 { + let mut s = std::collections::HashMap::new(); + let mut max_year = i32::MAX; + let mut max_num = 0; + for i in 0..birth.len() { + for j in birth[i]..=death[i] { + s.entry(j).and_modify(|x| *x += 1).or_insert(1); + if s[&j] > max_num { + max_num = s[&j]; + max_year = j; + } + + match s[&j].cmp(&max_num) { + std::cmp::Ordering::Equal => max_year = max_year.min(j), + std::cmp::Ordering::Greater => { + max_year = j; + max_num = s[&j]; + } + _ => {} + } + } + } + + max_year + } +} From b0d7abada4bc329ff84a8d6aad24f73a5226a3bf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 26 Nov 2023 12:26:57 +0800 Subject: [PATCH 1103/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 75efc4c0..a09bf181 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 597 | 256 | 313 | 28 | +| 598 | 256 | 314 | 28 | ### 题目 @@ -555,6 +555,7 @@ |100344 | 股票的最大利润 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gu-piao-de-zui-da-li-run-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/) | Medium | |100345 | 求1+2+…+n | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qiu-12n-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/qiu-12n-lcof/) | Medium | |100349 | 最大数值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-lcci/) | Easy | +|100351 | 生存人数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/living-people-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/living-people-lcci/) | Medium | |100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | |100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | |1000021 | 最小K个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-k-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-k-lcci/) | Medium | From 7f2a609354924ef9e40a55f15873f6ae85c67742 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 27 Nov 2023 20:32:45 +0800 Subject: [PATCH 1104/1556] src/bin/magic-index-lcci.rs --- src/bin/magic-index-lcci.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/bin/magic-index-lcci.rs diff --git a/src/bin/magic-index-lcci.rs b/src/bin/magic-index-lcci.rs new file mode 100644 index 00000000..105f26fa --- /dev/null +++ b/src/bin/magic-index-lcci.rs @@ -0,0 +1,17 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_magic_index(nums: Vec) -> i32 { + for i in 0..nums.len() { + if nums[i] as usize == i { + return nums[i]; + } + } + + -1 + } +} From 3beb8ae5b46664b7551d6edc2b7b7ae2f9f389ea Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 27 Nov 2023 20:32:46 +0800 Subject: [PATCH 1105/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a09bf181..0fb6d822 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 598 | 256 | 314 | 28 | +| 599 | 257 | 314 | 28 | ### 题目 @@ -481,6 +481,7 @@ |3152 | 有序三元组中的最大值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-an-ordered-triplet-ii.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-an-ordered-triplet-ii/) | Medium | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | +|100240 | 魔术索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magic-index-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/magic-index-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | |100275 | 数组中重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shu-zu-zhong-zhong-fu-de-shu-zi-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/) | Easy | From 256f73aee9633bd5b5a9650889baf994a6b19350 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 28 Nov 2023 21:13:51 +0800 Subject: [PATCH 1106/1556] src/bin/design-front-middle-back-queue.rs --- src/bin/design-front-middle-back-queue.rs | 96 +++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/bin/design-front-middle-back-queue.rs diff --git a/src/bin/design-front-middle-back-queue.rs b/src/bin/design-front-middle-back-queue.rs new file mode 100644 index 00000000..2cba8e60 --- /dev/null +++ b/src/bin/design-front-middle-back-queue.rs @@ -0,0 +1,96 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +struct FrontMiddleBackQueue { + pre: std::collections::LinkedList, + back: std::collections::LinkedList, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +/** + * Your FrontMiddleBackQueue object will be instantiated and called as such: + * let obj = FrontMiddleBackQueue::new(); + * obj.push_front(val); + * obj.push_middle(val); + * obj.push_back(val); + * let ret_4: i32 = obj.pop_front(); + * let ret_5: i32 = obj.pop_middle(); + * let ret_6: i32 = obj.pop_back(); + */ +impl FrontMiddleBackQueue { + fn new() -> Self { + Self { + pre: std::collections::LinkedList::new(), + back: std::collections::LinkedList::new(), + } + } + + fn push_front(&mut self, val: i32) { + if self.pre.len() > self.back.len() { + if let Some(x) = self.pre.pop_back() { + self.back.push_front(x); + } + } + self.pre.push_front(val); + } + + fn push_middle(&mut self, val: i32) { + match self.pre.len() - self.back.len() { + 1 => { + if let Some(x) = self.pre.pop_back() { + self.back.push_front(x); + } + self.pre.push_back(val); + } + _ => self.pre.push_back(val), + } + } + + fn push_back(&mut self, val: i32) { + self.back.push_back(val); + if self.back.len() > self.pre.len() { + if let Some(x) = self.back.pop_front() { + self.pre.push_back(x); + } + } + } + + fn pop_front(&mut self) -> i32 { + if self.pre.len() == self.back.len() { + if let Some(x) = self.back.pop_front() { + self.pre.push_back(x); + } + } + + self.pre.pop_front().unwrap_or(-1) + } + + fn pop_middle(&mut self) -> i32 { + match self.pre.len() - self.back.len() { + 1 => self.pre.pop_back().unwrap_or(-1), + _ => { + let val = self.pre.pop_back().unwrap_or(-1); + if let Some(x) = self.back.pop_front() { + self.pre.push_back(x); + } + val + } + } + } + + fn pop_back(&mut self) -> i32 { + if self.pre.len() - self.back.len() > 0 { + if let Some(x) = self.pre.pop_back() { + self.back.push_front(x); + } + } + + self.back.pop_back().unwrap_or(-1) + } +} From 9eac1e6294bd03a6693f894890611e7cf668e1ac Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 28 Nov 2023 21:13:53 +0800 Subject: [PATCH 1107/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0fb6d822..ef70ecbd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 599 | 257 | 314 | 28 | +| 600 | 257 | 315 | 28 | ### 题目 @@ -393,6 +393,7 @@ |1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | |1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | |1677 | 矩阵对角线元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/matrix-diagonal-sum.rs) | [leetcode](https://leetcode-cn.com/problems/matrix-diagonal-sum/) | Easy | +|1767 | 设计前中后队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-front-middle-back-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-front-middle-back-queue/) | Medium | |1782 | 具有给定数值的最小字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-string-with-a-given-numeric-value.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-string-with-a-given-numeric-value/) | Medium | |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | From 8b610dd4c8c90db140fa13d046e6f4e9ddec4b0e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 29 Nov 2023 08:11:50 +0800 Subject: [PATCH 1108/1556] src/bin/smallest-number-in-infinite-set.rs --- src/bin/smallest-number-in-infinite-set.rs | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/bin/smallest-number-in-infinite-set.rs diff --git a/src/bin/smallest-number-in-infinite-set.rs b/src/bin/smallest-number-in-infinite-set.rs new file mode 100644 index 00000000..dbea83ea --- /dev/null +++ b/src/bin/smallest-number-in-infinite-set.rs @@ -0,0 +1,54 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +struct SmallestInfiniteSet { + s: std::collections::BTreeSet, + latest: i32, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +/** + * Your SmallestInfiniteSet object will be instantiated and called as such: + * let obj = SmallestInfiniteSet::new(); + * let ret_1: i32 = obj.pop_smallest(); + * obj.add_back(num); + */ +impl SmallestInfiniteSet { + fn new() -> Self { + Self { + s: std::collections::BTreeSet::new(), + latest: 1, + } + } + + fn pop_smallest(&mut self) -> i32 { + if let Some(&x) = self.s.iter().next() { + if x < self.latest { + self.s.remove(&x); + return x; + } + } + + self.latest += 1; + self.latest - 1 + } + + fn add_back(&mut self, num: i32) { + if num >= self.latest { + return; + } + + if num == self.latest - 1 { + self.latest -= 1; + return; + } + + self.s.insert(num); + } +} From bf47248bfa1b17297819b75510ce2a52874bc12d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 29 Nov 2023 08:11:51 +0800 Subject: [PATCH 1109/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ef70ecbd..968f0c19 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 600 | 257 | 315 | 28 | +| 601 | 257 | 316 | 28 | ### 题目 @@ -432,6 +432,7 @@ |2384 | 判断根结点是否等于子结点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/root-equals-sum-of-children.rs) | [leetcode](https://leetcode-cn.com/problems/root-equals-sum-of-children/) | Easy | |2386 | 极大极小游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-max-game.rs) | [leetcode](https://leetcode-cn.com/problems/min-max-game/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | +|2413 | 无限集中的最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-number-in-infinite-set.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-number-in-infinite-set/) | Medium | |2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | |2470 | 从字符串中移除星号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-stars-from-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/removing-stars-from-a-string/) | Medium | |2473 | 数位和相等数对的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs) | [leetcode](https://leetcode-cn.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | From b8db08c4a434e9c31237ce5272a6f99ce0e0326c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 30 Nov 2023 08:29:05 +0800 Subject: [PATCH 1110/1556] src/bin/determine-if-two-strings-are-close.rs --- src/bin/determine-if-two-strings-are-close.rs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bin/determine-if-two-strings-are-close.rs diff --git a/src/bin/determine-if-two-strings-are-close.rs b/src/bin/determine-if-two-strings-are-close.rs new file mode 100644 index 00000000..e0015507 --- /dev/null +++ b/src/bin/determine-if-two-strings-are-close.rs @@ -0,0 +1,37 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn close_strings(word1: String, word2: String) -> bool { + if word1.len() != word2.len() { + return false; + } + let (mut h1, mut h2) = ([0; 26], [0; 26]); + for i in 0..word1.len() { + h1[(word1.as_bytes()[i] - b'a') as usize] += 1; + h2[(word2.as_bytes()[i] - b'a') as usize] += 1; + } + + for i in 0..26 { + match (h1[i], h2[i]) { + (0, 0) => continue, + (0, _) | (_, 0) => return false, + _ => continue, + } + } + + h1.sort(); + h2.sort(); + + for i in 0..h1.len() { + if h1[i] != h2[i] { + return false; + } + } + + true + } +} From c7cc483f1b5844f537f0f0b8196b3a8a6981a7ea Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 30 Nov 2023 08:29:06 +0800 Subject: [PATCH 1111/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 968f0c19..fda5ce9b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 601 | 257 | 316 | 28 | +| 602 | 257 | 317 | 28 | ### 题目 @@ -394,6 +394,7 @@ |1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | |1677 | 矩阵对角线元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/matrix-diagonal-sum.rs) | [leetcode](https://leetcode-cn.com/problems/matrix-diagonal-sum/) | Easy | |1767 | 设计前中后队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-front-middle-back-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-front-middle-back-queue/) | Medium | +|1777 | 确定两个字符串是否接近 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/determine-if-two-strings-are-close.rs) | [leetcode](https://leetcode-cn.com/problems/determine-if-two-strings-are-close/) | Medium | |1782 | 具有给定数值的最小字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-string-with-a-given-numeric-value.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-string-with-a-given-numeric-value/) | Medium | |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | From afc53e3fff9e5d66f9b29297e311a37ea657c795 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 1 Dec 2023 08:47:17 +0800 Subject: [PATCH 1112/1556] src/bin/first-completely-painted-row-or-column.rs --- .../first-completely-painted-row-or-column.rs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/first-completely-painted-row-or-column.rs diff --git a/src/bin/first-completely-painted-row-or-column.rs b/src/bin/first-completely-painted-row-or-column.rs new file mode 100644 index 00000000..cf329fad --- /dev/null +++ b/src/bin/first-completely-painted-row-or-column.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn first_complete_index(arr: Vec, mat: Vec>) -> i32 { + let mut r = arr.len(); + + let mut hash: std::collections::HashMap = Default::default(); + // s1存放每行的个数 + // s2存放没列的个数 + let (mut s1, mut s2) = (vec![0usize; mat.len()], vec![0usize; mat[0].len()]); + + for i in 0..mat.len() { + for j in 0..mat[0].len() { + hash.insert(mat[i][j], (i, j)); + } + } + + for i in 0..arr.len() { + let (x, y) = hash[&arr[i]]; + + s1[x] += 1usize; + s2[y] += 1usize; + + if s1[x] == mat[0].len() || s2[y] == mat.len() { + return i as i32; + } + } + + unreachable!() + } +} From 649d34ce073597fb723436a10be270a5e861d471 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 1 Dec 2023 08:47:18 +0800 Subject: [PATCH 1113/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fda5ce9b..07f401bc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 602 | 257 | 317 | 28 | +| 603 | 257 | 318 | 28 | ### 题目 @@ -460,6 +460,7 @@ |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | |2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | |2679 | 统计桌面上的不同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-distinct-numbers-on-board.rs) | [leetcode](https://leetcode-cn.com/problems/count-distinct-numbers-on-board/) | Easy | +|2685 | 找出叠涂元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-completely-painted-row-or-column.rs) | [leetcode](https://leetcode-cn.com/problems/first-completely-painted-row-or-column/) | Medium | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | |2692 | 从数量最多的堆取走礼物 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/take-gifts-from-the-richest-pile.rs) | [leetcode](https://leetcode-cn.com/problems/take-gifts-from-the-richest-pile/) | Easy | |2692 | 从数量最多的堆取走礼物 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/take-gifts-from-the-richest-pile.rs) | [leetcode](https://leetcode-cn.com/problems/take-gifts-from-the-richest-pile/) | Easy | From 3e2ac06315a6ddf8af0adffa51502163ead8a326 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 2 Dec 2023 11:35:04 +0800 Subject: [PATCH 1114/1556] src/bin/car-pooling.rs --- src/bin/car-pooling.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/car-pooling.rs diff --git a/src/bin/car-pooling.rs b/src/bin/car-pooling.rs new file mode 100644 index 00000000..482ea080 --- /dev/null +++ b/src/bin/car-pooling.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn car_pooling(trips: Vec>, capacity: i32) -> bool { + let mut v = vec![0; 1002]; + + for i in trips { + v[i[1] as usize + 1] += i[0]; + v[i[2] as usize + 1] -= i[0]; + } + + for i in 1..v.len() { + v[i] = v[i] + v[i - 1]; + if v[i] > capacity { + return false; + } + } + + true + } +} From de9a22e90d38f8bbc2c74d62e7443582d8de4eb1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 2 Dec 2023 11:35:05 +0800 Subject: [PATCH 1115/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 07f401bc..d7e54620 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 603 | 257 | 318 | 28 | +| 604 | 257 | 319 | 28 | ### 题目 @@ -333,6 +333,7 @@ |1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | |1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | +|1184 | 拼车 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/car-pooling.rs) | [leetcode](https://leetcode-cn.com/problems/car-pooling/) | Medium | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | |1218 | 最深叶节点的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-deepest-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves/) | Medium | |1236 | 第 N 个泰波那契数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-th-tribonacci-number.rs) | [leetcode](https://leetcode-cn.com/problems/n-th-tribonacci-number/) | Easy | From 84e8969a37205a4fba49e99ebfc7d8635dd262cf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 3 Dec 2023 22:17:28 +0800 Subject: [PATCH 1116/1556] src/bin/x-of-a-kind-in-a-deck-of-cards.rs --- src/bin/x-of-a-kind-in-a-deck-of-cards.rs | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/bin/x-of-a-kind-in-a-deck-of-cards.rs diff --git a/src/bin/x-of-a-kind-in-a-deck-of-cards.rs b/src/bin/x-of-a-kind-in-a-deck-of-cards.rs new file mode 100644 index 00000000..4cff0064 --- /dev/null +++ b/src/bin/x-of-a-kind-in-a-deck-of-cards.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn has_groups_size_x(deck: Vec) -> bool { + let mut h = std::collections::HashMap::new(); + for i in deck { + h.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + + let mut max = 0; + + for (_, j) in h { + max = Self::gcd(max, j); + } + + max >= 2 + } + + fn gcd(a: i32, b: i32) -> i32 { + if a == 0 { + b + } else { + Self::gcd(b % a, a) + } + } +} From 5e15897e53828be04994f41e74be84385a9bd2a2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 3 Dec 2023 22:17:28 +0800 Subject: [PATCH 1117/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d7e54620..674bf2bb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 604 | 257 | 319 | 28 | +| 605 | 258 | 319 | 28 | ### 题目 @@ -313,6 +313,7 @@ |936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | |937 | 股票价格跨度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-stock-span.rs) | [leetcode](https://leetcode-cn.com/problems/online-stock-span/) | Medium | |947 | 在线选举 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-election.rs) | [leetcode](https://leetcode-cn.com/problems/online-election/) | Medium | +|950 | 卡牌分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/x-of-a-kind-in-a-deck-of-cards.rs) | [leetcode](https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards/) | Easy | |953 | 仅仅反转字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-only-letters.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-only-letters/) | Easy | |954 | 环形子数组的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-circular-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-circular-subarray/) | Medium | |967 | 下降路径最小和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-falling-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-falling-path-sum/) | Medium | From e103b106b4741f76868c1200432a6c191639cfcb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 4 Dec 2023 22:33:40 +0800 Subject: [PATCH 1118/1556] src/bin/binary-search-tree-to-greater-sum-tree.rs --- .../binary-search-tree-to-greater-sum-tree.rs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/bin/binary-search-tree-to-greater-sum-tree.rs diff --git a/src/bin/binary-search-tree-to-greater-sum-tree.rs b/src/bin/binary-search-tree-to-greater-sum-tree.rs new file mode 100644 index 00000000..9d14f868 --- /dev/null +++ b/src/bin/binary-search-tree-to-greater-sum-tree.rs @@ -0,0 +1,47 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +fn main() {} + +struct Solution; + +impl Solution { + pub fn bst_to_gst(root: Option>>) -> Option>> { + let mut total = 0; + Self::dfs(root.clone(), &mut total); + root + } + + fn dfs(root: Option>>, total: &mut i32) { + if root.is_none() { + return; + } + + Self::dfs(root.as_ref().and_then(|x| x.borrow().right.clone()), total); + + root.as_ref().map(|x| x.borrow_mut().val += *total); + *total = root.as_ref().map(|x| x.borrow().val).unwrap_or(0); + Self::dfs(root.as_ref().and_then(|x| x.borrow().left.clone()), total); + } +} From 3551569737dc1fab727274f6a11fa0f5736256f9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 4 Dec 2023 22:33:40 +0800 Subject: [PATCH 1119/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 674bf2bb..ff915cdc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 605 | 258 | 319 | 28 | +| 606 | 258 | 320 | 28 | ### 题目 @@ -331,6 +331,7 @@ |1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | |1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | +|1114 | 从二叉搜索树到更大和树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-to-greater-sum-tree.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree/) | Medium | |1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | |1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | From ba62fe1f13710b0aff9cac01dce8c26a16994bc3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 5 Dec 2023 20:13:24 +0800 Subject: [PATCH 1120/1556] src/bin/minimum-changes-to-make-alternating-binary-string.rs --- ...anges-to-make-alternating-binary-string.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/minimum-changes-to-make-alternating-binary-string.rs diff --git a/src/bin/minimum-changes-to-make-alternating-binary-string.rs b/src/bin/minimum-changes-to-make-alternating-binary-string.rs new file mode 100644 index 00000000..82cc989b --- /dev/null +++ b/src/bin/minimum-changes-to-make-alternating-binary-string.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_operations(s: String) -> i32 { + let (mut r1, mut r2) = (0, 0); + let (mut s1, mut s2) = (b'1', b'0'); + + for &i in s.as_bytes() { + if i != s1 { + r1 += 1; + } + + if i != s2 { + r2 += 1; + } + + s1 = if s1 == b'1' { b'0' } else { b'1' }; + s2 = if s2 == b'1' { b'0' } else { b'1' }; + } + + r1.min(r2) + } +} From 7e5fbb450a6d32c857bc7c20531986bcad0d23cb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 5 Dec 2023 20:13:25 +0800 Subject: [PATCH 1121/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ff915cdc..9f625956 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 606 | 258 | 320 | 28 | +| 607 | 259 | 320 | 28 | ### 题目 @@ -406,6 +406,7 @@ |1829 | 卡车上的最大单元数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-units-on-a-truck.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-units-on-a-truck/) | Easy | |1849 | 任意子数组和的绝对值的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-absolute-sum-of-any-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | |1858 | 替换隐藏数字得到的最晚时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/latest-time-by-replacing-hidden-digits.rs) | [leetcode](https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits/) | Easy | +|1884 | 生成交替二进制字符串的最少操作数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-changes-to-make-alternating-binary-string.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-changes-to-make-alternating-binary-string/) | Easy | |1894 | 交替合并字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-strings-alternately.rs) | [leetcode](https://leetcode-cn.com/problems/merge-strings-alternately/) | Easy | |1929 | 有界数组中指定下标处的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-at-a-given-index-in-a-bounded-array/) | Medium | |1938 | 最少操作使数组递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-make-the-array-increasing.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-increasing/) | Easy | From 81bd6da83df3ff1ea971f91f19857d1b45bd4c68 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 6 Dec 2023 20:42:53 +0800 Subject: [PATCH 1122/1556] src/bin/check-if-numbers-are-ascending-in-a-sentence.rs --- ...-if-numbers-are-ascending-in-a-sentence.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/check-if-numbers-are-ascending-in-a-sentence.rs diff --git a/src/bin/check-if-numbers-are-ascending-in-a-sentence.rs b/src/bin/check-if-numbers-are-ascending-in-a-sentence.rs new file mode 100644 index 00000000..38e3c856 --- /dev/null +++ b/src/bin/check-if-numbers-are-ascending-in-a-sentence.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn are_numbers_ascending(s: String) -> bool { + let mut last = -1; + for i in s.split(' ').filter_map(|x| x.parse::().ok()) { + if i <= last { + return false; + } + + last = i; + } + + true + } +} From bed16c0f42a6f67178e7b99f566d952c89f978e9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 6 Dec 2023 20:42:53 +0800 Subject: [PATCH 1123/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f625956..9b71f1bb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 607 | 259 | 320 | 28 | +| 608 | 260 | 320 | 28 | ### 题目 @@ -421,6 +421,7 @@ |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | |2161 | 股票价格波动 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/stock-price-fluctuation.rs) | [leetcode](https://leetcode-cn.com/problems/stock-price-fluctuation/) | Medium | +|2168 | 检查句子中的数字是否递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-numbers-are-ascending-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-numbers-are-ascending-in-a-sentence/) | Easy | |2177 | 检查两个字符串是否几乎相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-whether-two-strings-are-almost-equivalent.rs) | [leetcode](https://leetcode-cn.com/problems/check-whether-two-strings-are-almost-equivalent/) | Easy | |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | |2226 | 环和杆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rings-and-rods.rs) | [leetcode](https://leetcode-cn.com/problems/rings-and-rods/) | Easy | From 4402b477d2f97311e406ea7cf28970b180339c0c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 7 Dec 2023 20:24:40 +0800 Subject: [PATCH 1124/1556] src/bin/reorder-routes-to-make-all-paths-lead-to-the-city-zero.rs --- ...to-make-all-paths-lead-to-the-city-zero.rs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/bin/reorder-routes-to-make-all-paths-lead-to-the-city-zero.rs diff --git a/src/bin/reorder-routes-to-make-all-paths-lead-to-the-city-zero.rs b/src/bin/reorder-routes-to-make-all-paths-lead-to-the-city-zero.rs new file mode 100644 index 00000000..22693548 --- /dev/null +++ b/src/bin/reorder-routes-to-make-all-paths-lead-to-the-city-zero.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +#[derive(Clone)] +enum Direction { + Go(i32), + Back(i32), +} + +impl Solution { + pub fn min_reorder(n: i32, connections: Vec>) -> i32 { + let mut c = vec![Vec::new(); n as usize]; + + for i in connections { + c[i[0] as usize].push(Direction::Go(i[1])); + c[i[1] as usize].push(Direction::Back(i[0])); + } + + Self::dfs(0, -1, &c[..]) + } + + fn dfs(x: usize, parent: i32, connections: &[Vec]) -> i32 { + let mut res = 0; + for i in connections[x].iter() { + match *i { + Direction::Back(d) if d != parent => { + res += Self::dfs(d as usize, x as i32, connections); + } + Direction::Go(d) if d != parent => { + res += Self::dfs(d as usize, x as i32, connections) + 1; + } + _ => {} + } + } + + res + } +} From 59a238f8254b5cbe014bbb8fa95796edc06068cb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 7 Dec 2023 20:24:41 +0800 Subject: [PATCH 1125/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b71f1bb..5c7aa54a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 608 | 260 | 320 | 28 | +| 609 | 260 | 321 | 28 | ### 题目 @@ -387,6 +387,7 @@ |1567 | 定长子串中元音的最大数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-vowels-in-a-substring-of-given-length.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/) | Medium | |1568 | 二叉树中的伪回文路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pseudo-palindromic-paths-in-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/pseudo-palindromic-paths-in-a-binary-tree/) | Medium | |1575 | 切割后面积最大的蛋糕 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/) | Medium | +|1576 | 重新规划路线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reorder-routes-to-make-all-paths-lead-to-the-city-zero.rs) | [leetcode](https://leetcode-cn.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero/) | Medium | |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | |1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | |1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | From a4d29ed962826022209bf8a3199c1627ed09ba01 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 8 Dec 2023 08:42:57 +0800 Subject: [PATCH 1126/1556] src/bin/binary-watch.rs --- src/bin/binary-watch.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/binary-watch.rs diff --git a/src/bin/binary-watch.rs b/src/bin/binary-watch.rs new file mode 100644 index 00000000..846d92e2 --- /dev/null +++ b/src/bin/binary-watch.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::fmt::format; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn read_binary_watch(turned_on: i32) -> Vec { + let mut result = vec![]; + for i in 0..12i8 { + let c = i.count_ones(); + if c > turned_on as u32 { + continue; + } + + for j in 0..60i8 { + if j.count_ones() == turned_on as u32 - c { + result.push(format!("{}:{:0>2}", i, j)); + } + } + } + + result + } +} From c9a12eb70c088821da1b66463e9fe9d4651d240a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 8 Dec 2023 08:42:58 +0800 Subject: [PATCH 1127/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c7aa54a..6e4540bf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 609 | 260 | 321 | 28 | +| 610 | 261 | 321 | 28 | ### 题目 @@ -226,6 +226,7 @@ |397 | 整数替换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/integer-replacement.rs) | [leetcode](https://leetcode-cn.com/problems/integer-replacement/) | Medium | |398 | 随机数索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/random-pick-index.rs) | [leetcode](https://leetcode-cn.com/problems/random-pick-index/) | Medium | |400 | 第 N 位数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nth-digit.rs) | [leetcode](https://leetcode-cn.com/problems/nth-digit/) | Medium | +|401 | 二进制手表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-watch.rs) | [leetcode](https://leetcode-cn.com/problems/binary-watch/) | Easy | |404 | 左叶子之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-left-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-left-leaves/) | Easy | |406 | 根据身高重建队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/queue-reconstruction-by-height.rs) | [leetcode](https://leetcode-cn.com/problems/queue-reconstruction-by-height/) | Medium | |409 | 最长回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindrome/) | Easy | From ba4bd64f250736062aa25e811c25e271088433aa Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 10 Dec 2023 22:13:06 +0800 Subject: [PATCH 1128/1556] src/bin/maximum-product-of-three-numbers.rs --- src/bin/maximum-product-of-three-numbers.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/bin/maximum-product-of-three-numbers.rs diff --git a/src/bin/maximum-product-of-three-numbers.rs b/src/bin/maximum-product-of-three-numbers.rs new file mode 100644 index 00000000..e7952992 --- /dev/null +++ b/src/bin/maximum-product-of-three-numbers.rs @@ -0,0 +1,15 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_product(nums: Vec) -> i32 { + let mut nums = nums; + nums.sort(); + + (nums[0] * nums[1] * nums[nums.len() - 1]) + .max(nums[nums.len() - 1] * nums[nums.len() - 2] * nums[nums.len() - 3]) + } +} From 473e476ba3eec7ff5c7bff8eb1a593a35c62af4b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 10 Dec 2023 22:13:06 +0800 Subject: [PATCH 1129/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e4540bf..c7e27572 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 610 | 261 | 321 | 28 | +| 611 | 262 | 321 | 28 | ### 题目 @@ -273,6 +273,7 @@ |617 | 合并二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-binary-trees/) | Easy | |621 | 任务调度器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/task-scheduler.rs) | [leetcode](https://leetcode-cn.com/problems/task-scheduler/) | Medium | |623 | 在二叉树中增加一行 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-one-row-to-tree.rs) | [leetcode](https://leetcode-cn.com/problems/add-one-row-to-tree/) | Medium | +|628 | 三个数的最大乘积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-product-of-three-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-product-of-three-numbers/) | Easy | |637 | 二叉树的层平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-of-levels-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/) | Easy | |643 | 子数组最大平均数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-average-subarray-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-average-subarray-i/) | Easy | |647 | 回文子串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/palindromic-substrings.rs) | [leetcode](https://leetcode-cn.com/problems/palindromic-substrings/) | Medium | From c91888108111ad61f39a6e7f611bc42de9e3de4d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Dec 2023 20:25:27 +0800 Subject: [PATCH 1130/1556] src/bin/calculate-money-in-leetcode-bank.rs --- src/bin/calculate-money-in-leetcode-bank.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/bin/calculate-money-in-leetcode-bank.rs diff --git a/src/bin/calculate-money-in-leetcode-bank.rs b/src/bin/calculate-money-in-leetcode-bank.rs new file mode 100644 index 00000000..712a5159 --- /dev/null +++ b/src/bin/calculate-money-in-leetcode-bank.rs @@ -0,0 +1,15 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn total_money(n: i32) -> i32 { + const S: i32 = 49; + + let a = n / 7; + let b = n % 7; + ((S + a * 7) * a + (a * 2 + b + 1) * b) >> 1 + } +} From c6de2d8d9dd1604cc9cffc6ac3da227f4c298771 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Dec 2023 20:25:27 +0800 Subject: [PATCH 1131/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c7e27572..21323e25 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 611 | 262 | 321 | 28 | +| 612 | 263 | 321 | 28 | ### 题目 @@ -406,6 +406,7 @@ |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | |1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | +|1817 | 计算力扣银行的钱 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-money-in-leetcode-bank.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-money-in-leetcode-bank/) | Easy | |1829 | 卡车上的最大单元数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-units-on-a-truck.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-units-on-a-truck/) | Easy | |1849 | 任意子数组和的绝对值的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-absolute-sum-of-any-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | |1858 | 替换隐藏数字得到的最晚时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/latest-time-by-replacing-hidden-digits.rs) | [leetcode](https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits/) | Easy | From f6bc6a8451fe93ac8d9eced186acce0e42714e3d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 12 Dec 2023 20:26:27 +0800 Subject: [PATCH 1132/1556] src/bin/minimum-right-shifts-to-sort-the-array.rs --- .../minimum-right-shifts-to-sort-the-array.rs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/minimum-right-shifts-to-sort-the-array.rs diff --git a/src/bin/minimum-right-shifts-to-sort-the-array.rs b/src/bin/minimum-right-shifts-to-sort-the-array.rs new file mode 100644 index 00000000..3d2d5732 --- /dev/null +++ b/src/bin/minimum-right-shifts-to-sort-the-array.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_right_shifts(nums: Vec) -> i32 { + let mut r = 0; + let mut f = false; + for i in 1..nums.len() { + if nums[i] < nums[i - 1] { + if f { + return -1; + } + + f = true; + } + + if f { + r += 1; + } + } + + if f { + if nums[0] >= nums[nums.len() - 1] { + r + } else { + -1 + } + } else { + 0 + } + } +} From 03c09d77ded870beaa915ab520e407eadee1f1e0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 12 Dec 2023 20:26:27 +0800 Subject: [PATCH 1133/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 21323e25..a2fc905b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 612 | 263 | 321 | 28 | +| 613 | 264 | 321 | 28 | ### 题目 @@ -490,6 +490,7 @@ |2866 | 最长奇偶子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-even-odd-subarray-with-threshold.rs) | [leetcode](https://leetcode-cn.com/problems/longest-even-odd-subarray-with-threshold/) | Easy | |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | +|3045 | 使数组成为递增数组的最少右移次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-right-shifts-to-sort-the-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-right-shifts-to-sort-the-array/) | Easy | |3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | |3152 | 有序三元组中的最大值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-an-ordered-triplet-ii.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-an-ordered-triplet-ii/) | Medium | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | From f319de304bcd307686b5ee37a6c618fcf6bfd3b5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 13 Dec 2023 07:46:31 +0800 Subject: [PATCH 1134/1556] src/bin/lexicographically-smallest-palindrome.rs --- .../lexicographically-smallest-palindrome.rs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/lexicographically-smallest-palindrome.rs diff --git a/src/bin/lexicographically-smallest-palindrome.rs b/src/bin/lexicographically-smallest-palindrome.rs new file mode 100644 index 00000000..cae684bb --- /dev/null +++ b/src/bin/lexicographically-smallest-palindrome.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn make_smallest_palindrome(s: String) -> String { + let mut s = s.into_bytes(); + let (mut i, mut j) = (0, s.len() - 1); + + while i < j { + if s[i] > s[j] { + s[i] = s[j]; + } else if s[i] < s[j] { + s[j] = s[i]; + } + + i += 1; + j -= 1; + } + + unsafe { String::from_utf8_unchecked(s) } + } +} From 78e511a6f560e734eaaabbb6755cdf6009bcd307 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 13 Dec 2023 07:46:31 +0800 Subject: [PATCH 1135/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a2fc905b..272f74d8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 613 | 264 | 321 | 28 | +| 614 | 265 | 321 | 28 | ### 题目 @@ -486,6 +486,7 @@ |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | |2802 | 求一个整数的惩罚数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-punishment-number-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-punishment-number-of-an-integer/) | Medium | |2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | +|2816 | 字典序最小回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographically-smallest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographically-smallest-palindrome/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |2866 | 最长奇偶子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-even-odd-subarray-with-threshold.rs) | [leetcode](https://leetcode-cn.com/problems/longest-even-odd-subarray-with-threshold/) | Easy | |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | From d161d72822d9a59ed18d618c47c64a56720891de Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 14 Dec 2023 19:51:18 +0800 Subject: [PATCH 1136/1556] src/bin/count-items-matching-a-rule.rs --- src/bin/count-items-matching-a-rule.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/bin/count-items-matching-a-rule.rs diff --git a/src/bin/count-items-matching-a-rule.rs b/src/bin/count-items-matching-a-rule.rs new file mode 100644 index 00000000..bb5a818f --- /dev/null +++ b/src/bin/count-items-matching-a-rule.rs @@ -0,0 +1,19 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_matches(items: Vec>, rule_key: String, rule_value: String) -> i32 { + items + .into_iter() + .filter(|x| match rule_key.as_str() { + "type" => x[0] == rule_value, + "color" => x[1] == rule_value, + "name" => x[2] == rule_value, + _ => unreachable!(), + }) + .count() as i32 + } +} From 3a6f06924f41be011da442ae9222560a5b10cbd1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 14 Dec 2023 19:51:19 +0800 Subject: [PATCH 1137/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 272f74d8..6822d6b5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 614 | 265 | 321 | 28 | +| 615 | 266 | 321 | 28 | ### 题目 @@ -412,6 +412,7 @@ |1858 | 替换隐藏数字得到的最晚时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/latest-time-by-replacing-hidden-digits.rs) | [leetcode](https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits/) | Easy | |1884 | 生成交替二进制字符串的最少操作数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-changes-to-make-alternating-binary-string.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-changes-to-make-alternating-binary-string/) | Easy | |1894 | 交替合并字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-strings-alternately.rs) | [leetcode](https://leetcode-cn.com/problems/merge-strings-alternately/) | Easy | +|1899 | 统计匹配检索规则的物品数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-items-matching-a-rule.rs) | [leetcode](https://leetcode-cn.com/problems/count-items-matching-a-rule/) | Easy | |1929 | 有界数组中指定下标处的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-at-a-given-index-in-a-bounded-array/) | Medium | |1938 | 最少操作使数组递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-make-the-array-increasing.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-increasing/) | Easy | |1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | From 03cb2e3780a7a567dff41561b0e5ffeb40ee0821 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 15 Dec 2023 08:11:06 +0800 Subject: [PATCH 1138/1556] src/bin/reverse-odd-levels-of-binary-tree.rs --- src/bin/reverse-odd-levels-of-binary-tree.rs | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/bin/reverse-odd-levels-of-binary-tree.rs diff --git a/src/bin/reverse-odd-levels-of-binary-tree.rs b/src/bin/reverse-odd-levels-of-binary-tree.rs new file mode 100644 index 00000000..44114120 --- /dev/null +++ b/src/bin/reverse-odd-levels-of-binary-tree.rs @@ -0,0 +1,70 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +fn main() {} + +struct Solution; + +impl Solution { + pub fn reverse_odd_levels( + root: Option>>, + ) -> Option>> { + let mut edage = 0; + let mut stack = vec![root.clone()]; + + while !stack.is_empty() { + if edage % 2 == 1 { + let (mut start, mut end) = (0, stack.len() - 1); + while start < end { + let l = stack.get(start).unwrap().as_ref().unwrap().borrow().val; + let r = stack.get(end).unwrap().as_ref().unwrap().borrow().val; + + stack.get(start).unwrap().as_ref().unwrap().borrow_mut().val = r; + stack.get(end).unwrap().as_ref().unwrap().borrow_mut().val = l; + + start += 1; + end -= 1; + } + } + + let mut new_stack = Vec::with_capacity(stack.len() * 2); + while let Some(x) = stack.pop() { + let left = x.as_ref().unwrap().borrow().left.clone(); + if left.is_some() { + new_stack.push(left); + } + let right = x.as_ref().unwrap().borrow().right.clone(); + if right.is_some() { + new_stack.push(right); + } + } + + stack = new_stack; + + edage += 1; + } + + root + } +} From c4d04f32947c7fdabed77a7aca7bac48b8b005b0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 15 Dec 2023 08:11:06 +0800 Subject: [PATCH 1139/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6822d6b5..a15c6735 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 615 | 266 | 321 | 28 | +| 616 | 266 | 322 | 28 | ### 题目 @@ -447,6 +447,7 @@ |2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | |2470 | 从字符串中移除星号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-stars-from-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/removing-stars-from-a-string/) | Medium | |2473 | 数位和相等数对的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs) | [leetcode](https://leetcode-cn.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | +|2493 | 反转二叉树的奇数层 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-odd-levels-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-odd-levels-of-binary-tree/) | Medium | |2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | From b11fa336e22674129c308126cf1c27bf8dc4b178 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 17 Dec 2023 19:24:29 +0800 Subject: [PATCH 1140/1556] src/bin/min-cost-climbing-stairs.rs --- src/bin/min-cost-climbing-stairs.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/bin/min-cost-climbing-stairs.rs diff --git a/src/bin/min-cost-climbing-stairs.rs b/src/bin/min-cost-climbing-stairs.rs new file mode 100644 index 00000000..37296b45 --- /dev/null +++ b/src/bin/min-cost-climbing-stairs.rs @@ -0,0 +1,19 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_cost_climbing_stairs(cost: Vec) -> i32 { + let (mut s1, mut s2) = (cost[0], cost[1]); + + for &i in cost[2..].iter() { + let s = i + s1.min(s2); + s1 = s2; + s2 = s; + } + + s1.min(s2) + } +} From da22e96a2ecf474331736af1d3f62d7661c7f5dc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 17 Dec 2023 19:24:30 +0800 Subject: [PATCH 1141/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a15c6735..3da5e970 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 616 | 266 | 322 | 28 | +| 617 | 267 | 322 | 28 | ### 题目 @@ -288,6 +288,7 @@ |724 | 寻找数组的中心下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-pivot-index.rs) | [leetcode](https://leetcode-cn.com/problems/find-pivot-index/) | Easy | |739 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/daily-temperatures.rs) | [leetcode](https://leetcode-cn.com/problems/daily-temperatures/) | Medium | |742 | 转换成小写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/to-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/to-lower-case/) | Easy | +|747 | 使用最小花费爬楼梯 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-cost-climbing-stairs.rs) | [leetcode](https://leetcode-cn.com/problems/min-cost-climbing-stairs/) | Easy | |782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | |783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | |784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | From 6ef09032f74679d5af3fa7718aa17986a90752b4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 18 Dec 2023 20:24:49 +0800 Subject: [PATCH 1142/1556] src/bin/IlPe0q.rs --- src/bin/IlPe0q.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/IlPe0q.rs diff --git a/src/bin/IlPe0q.rs b/src/bin/IlPe0q.rs new file mode 100644 index 00000000..1363cfd5 --- /dev/null +++ b/src/bin/IlPe0q.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_total(triangle: Vec>) -> i32 { + let mut triangle = triangle; + + for i in 1..triangle.len() { + for j in 0..triangle[i].len() { + if j == 0 { + triangle[i][j] += triangle[i - 1][0]; + } else if j == triangle[i].len() - 1 { + triangle[i][j] += triangle[i - 1][j - 1]; + } else { + triangle[i][j] += triangle[i - 1][j - 1].min(triangle[i - 1][j]); + } + } + } + + triangle[triangle.len() - 1] + .iter() + .map(|x| *x) + .min() + .unwrap() + } +} From 1b744dda1eb384dec3b888354e58e714c03c4e0c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 18 Dec 2023 20:24:49 +0800 Subject: [PATCH 1143/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3da5e970..7b7f3c9b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 617 | 267 | 322 | 28 | +| 618 | 267 | 323 | 28 | ### 题目 @@ -610,6 +610,7 @@ |1000279 | 后缀表达式 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/8Zf90G.rs) | [leetcode](https://leetcode-cn.com/problems/8Zf90G/) | Medium | |1000281 | 小行星碰撞 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/XagZNi.rs) | [leetcode](https://leetcode-cn.com/problems/XagZNi/) | Medium | |1000282 | 每日温度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/iIQa4I.rs) | [leetcode](https://leetcode-cn.com/problems/iIQa4I/) | Medium | +|1000286 | 三角形最小路径和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/IlPe0q.rs) | [leetcode](https://leetcode-cn.com/problems/IlPe0q/) | Medium | |1000288 | 加减的目标值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/YaVDxD.rs) | [leetcode](https://leetcode-cn.com/problems/YaVDxD/) | Medium | |1000292 | 滑动窗口的平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/qIsx9U.rs) | [leetcode](https://leetcode-cn.com/problems/qIsx9U/) | Easy | |1000295 | 往完全二叉树添加节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NaqhDT.rs) | [leetcode](https://leetcode-cn.com/problems/NaqhDT/) | Medium | From c501d27a42129ac01ca4cebde6137f84938eebb3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 19 Dec 2023 20:40:15 +0800 Subject: [PATCH 1144/1556] src/bin/sum-of-root-to-leaf-binary-numbers.rs --- src/bin/sum-of-root-to-leaf-binary-numbers.rs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/bin/sum-of-root-to-leaf-binary-numbers.rs diff --git a/src/bin/sum-of-root-to-leaf-binary-numbers.rs b/src/bin/sum-of-root-to-leaf-binary-numbers.rs new file mode 100644 index 00000000..7db18689 --- /dev/null +++ b/src/bin/sum-of-root-to-leaf-binary-numbers.rs @@ -0,0 +1,52 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +fn main() {} + +struct Solution; + +impl Solution { + pub fn sum_root_to_leaf(root: Option>>) -> i32 { + Self::f(root, 0) + } + + fn f(root: Option>>, i: i32) -> i32 { + if root.is_none() { + return 0; + } + + let root = root.unwrap(); + let left = root.borrow_mut().left.take(); + let right = root.borrow_mut().right.take(); + + let new_i = (i << 1) + root.borrow().val; + + match (left, right) { + (None, None) => new_i, + (Some(l), Some(y)) => Self::f(Some(l), new_i) + Self::f(Some(y), new_i), + (Some(l), None) => Self::f(Some(l), new_i), + (None, Some(y)) => Self::f(Some(y), new_i), + } + } +} From 3c78281202fd8165a805b19ee4835bbc7c4afee7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 19 Dec 2023 20:40:16 +0800 Subject: [PATCH 1145/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b7f3c9b..36aa9903 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 618 | 267 | 323 | 28 | +| 619 | 268 | 323 | 28 | ### 题目 @@ -334,6 +334,7 @@ |1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | |1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | +|1079 | 从根到叶的二进制数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-root-to-leaf-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-root-to-leaf-binary-numbers/) | Easy | |1114 | 从二叉搜索树到更大和树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-to-greater-sum-tree.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree/) | Medium | |1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | From be2a7c727f3c0e908c2d68bda63f823c7e4c8e1e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 20 Dec 2023 08:12:22 +0800 Subject: [PATCH 1146/1556] src/bin/largest-odd-number-in-string.rs --- src/bin/largest-odd-number-in-string.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/bin/largest-odd-number-in-string.rs diff --git a/src/bin/largest-odd-number-in-string.rs b/src/bin/largest-odd-number-in-string.rs new file mode 100644 index 00000000..da4a264a --- /dev/null +++ b/src/bin/largest-odd-number-in-string.rs @@ -0,0 +1,19 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn largest_odd_number(num: String) -> String { + let mut s = num.as_bytes(); + + for i in (0..s.len()).rev() { + if (s[i] - b'0') % 2 == 1 { + return String::from_utf8(s[..=i].to_vec()).unwrap(); + } + } + + "".into() + } +} From f83939925f488cc62b48d0bcf51949c4c7a22251 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 20 Dec 2023 08:12:24 +0800 Subject: [PATCH 1147/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 36aa9903..63392b60 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 619 | 268 | 323 | 28 | +| 620 | 269 | 323 | 28 | ### 题目 @@ -422,6 +422,7 @@ |1971 | 增长的内存泄露 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/incremental-memory-leak.rs) | [leetcode](https://leetcode-cn.com/problems/incremental-memory-leak/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2022 | 最大子序列交替和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-alternating-subsequence-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-alternating-subsequence-sum/) | Medium | +|2032 | 字符串中的最大奇数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-odd-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-odd-number-in-string/) | Easy | |2049 | 消灭怪物的最大数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/eliminate-maximum-number-of-monsters.rs) | [leetcode](https://leetcode-cn.com/problems/eliminate-maximum-number-of-monsters/) | Medium | |2053 | 检查是否所有字符出现次数相同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-all-characters-have-equal-number-of-occurrences.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-all-characters-have-equal-number-of-occurrences/) | Easy | |2104 | 树上的操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/operations-on-tree.rs) | [leetcode](https://leetcode-cn.com/problems/operations-on-tree/) | Medium | From e9d22c2d27616bfab0c9919cefa4772a7c4bfd6b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 21 Dec 2023 20:32:36 +0800 Subject: [PATCH 1148/1556] src/bin/check-if-the-sentence-is-pangram.rs --- src/bin/check-if-the-sentence-is-pangram.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/bin/check-if-the-sentence-is-pangram.rs diff --git a/src/bin/check-if-the-sentence-is-pangram.rs b/src/bin/check-if-the-sentence-is-pangram.rs new file mode 100644 index 00000000..e1ec3fd9 --- /dev/null +++ b/src/bin/check-if-the-sentence-is-pangram.rs @@ -0,0 +1,16 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn check_if_pangram(sentence: String) -> bool { + let mut v = [0u8; 26]; + for i in sentence.bytes() { + v[(i - b'a') as usize] = 1; + } + + v.iter().all(|&x| x == 1) + } +} From 5312c7302894fc18872102045dfe9dd87c13a99e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 21 Dec 2023 20:32:38 +0800 Subject: [PATCH 1149/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 63392b60..8b8aa02d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 620 | 269 | 323 | 28 | +| 621 | 270 | 323 | 28 | ### 题目 @@ -419,6 +419,7 @@ |1938 | 最少操作使数组递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-make-the-array-increasing.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-increasing/) | Easy | |1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | |1952 | 最少侧跳次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sideway-jumps.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sideway-jumps/) | Medium | +|1960 | 判断句子是否为全字母句 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-the-sentence-is-pangram.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-the-sentence-is-pangram/) | Easy | |1971 | 增长的内存泄露 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/incremental-memory-leak.rs) | [leetcode](https://leetcode-cn.com/problems/incremental-memory-leak/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2022 | 最大子序列交替和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-alternating-subsequence-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-alternating-subsequence-sum/) | Medium | From 61b21fc3948f82852324f4e6bbcbabd3cab1b975 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 22 Dec 2023 20:49:17 +0800 Subject: [PATCH 1150/1556] src/bin/greatest-common-divisor-of-strings.rs --- src/bin/greatest-common-divisor-of-strings.rs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/bin/greatest-common-divisor-of-strings.rs diff --git a/src/bin/greatest-common-divisor-of-strings.rs b/src/bin/greatest-common-divisor-of-strings.rs new file mode 100644 index 00000000..197cc6b1 --- /dev/null +++ b/src/bin/greatest-common-divisor-of-strings.rs @@ -0,0 +1,47 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn gcd_of_strings(str1: String, str2: String) -> String { + let mut str1_ = str1.clone(); + let mut str2_ = str2.clone(); + + let mut result = String::new(); + let mut i = 1; + + while i <= str1.len() && i <= str2.len() { + if (i > str1.len() || str1.len() % i == 0) && (i > str2.len() || str2.len() % i == 0) { + let s1 = Self::gdc(str1.as_bytes(), i); + let s2 = Self::gdc(str2.as_bytes(), i); + + if s1 == s2 { + result = String::from_utf8_lossy(s1).to_string() + } + } + + i += 1; + } + + result + } + + fn gdc(s: &[u8], mut i: usize) -> &[u8] { + if i > s.len() { + return &s[0..0]; + } + + let mut start = i; + while start <= s.len() { + if s[start - i..start] != s[0..i] { + return &s[0..0]; + } + + start += i; + } + + &s[0..i] + } +} From 7d6b49696c381cb65a998a7216df3ab49b252482 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 22 Dec 2023 20:49:18 +0800 Subject: [PATCH 1151/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b8aa02d..7c8ef54d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 621 | 270 | 323 | 28 | +| 622 | 271 | 323 | 28 | ### 题目 @@ -338,6 +338,7 @@ |1114 | 从二叉搜索树到更大和树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-to-greater-sum-tree.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree/) | Medium | |1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | +|1146 | 字符串的最大公因子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/greatest-common-divisor-of-strings.rs) | [leetcode](https://leetcode-cn.com/problems/greatest-common-divisor-of-strings/) | Easy | |1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | |1184 | 拼车 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/car-pooling.rs) | [leetcode](https://leetcode-cn.com/problems/car-pooling/) | Medium | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | From 0a97446f1184206ee99c3f864511a1ce551a4635 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Dec 2023 21:49:51 +0800 Subject: [PATCH 1152/1556] src/bin/remove-stones-to-minimize-the-total.rs --- src/bin/remove-stones-to-minimize-the-total.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/bin/remove-stones-to-minimize-the-total.rs diff --git a/src/bin/remove-stones-to-minimize-the-total.rs b/src/bin/remove-stones-to-minimize-the-total.rs new file mode 100644 index 00000000..f92e24d7 --- /dev/null +++ b/src/bin/remove-stones-to-minimize-the-total.rs @@ -0,0 +1,18 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_stone_sum(piles: Vec, k: i32) -> i32 { + let mut heap = std::collections::BinaryHeap::from(piles); + + for _ in 0..k { + let x = heap.pop().unwrap(); + heap.push(if x % 2 == 0 { x / 2 } else { x / 2 + 1 }); + } + + heap.into_iter().sum() + } +} From 97e33a7317b8c147633bb1ba84d0865c48a1564c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 23 Dec 2023 21:49:51 +0800 Subject: [PATCH 1153/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c8ef54d..013d323a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 622 | 271 | 323 | 28 | +| 623 | 271 | 324 | 28 | ### 题目 @@ -427,6 +427,7 @@ |2032 | 字符串中的最大奇数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-odd-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-odd-number-in-string/) | Easy | |2049 | 消灭怪物的最大数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/eliminate-maximum-number-of-monsters.rs) | [leetcode](https://leetcode-cn.com/problems/eliminate-maximum-number-of-monsters/) | Medium | |2053 | 检查是否所有字符出现次数相同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-all-characters-have-equal-number-of-occurrences.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-all-characters-have-equal-number-of-occurrences/) | Easy | +|2094 | 移除石子使总数最小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-stones-to-minimize-the-total.rs) | [leetcode](https://leetcode-cn.com/problems/remove-stones-to-minimize-the-total/) | Medium | |2104 | 树上的操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/operations-on-tree.rs) | [leetcode](https://leetcode-cn.com/problems/operations-on-tree/) | Medium | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | From b14d7b3277c4f79797866cd9c863846709d443b4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 24 Dec 2023 21:55:57 +0800 Subject: [PATCH 1154/1556] src/bin/minimum-garden-perimeter-to-collect-enough-apples.rs --- ...rden-perimeter-to-collect-enough-apples.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/minimum-garden-perimeter-to-collect-enough-apples.rs diff --git a/src/bin/minimum-garden-perimeter-to-collect-enough-apples.rs b/src/bin/minimum-garden-perimeter-to-collect-enough-apples.rs new file mode 100644 index 00000000..cce64533 --- /dev/null +++ b/src/bin/minimum-garden-perimeter-to-collect-enough-apples.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_perimeter(needed_apples: i64) -> i64 { + let mut total = 0; + for i in 1.. { + let s = 8 * 3 * (i + 1) * i / 2 - 12 * i; + total += s; + if total >= needed_apples { + return 8 * i; + } + } + + unreachable!() + } +} From 2181564fe1d4ec57a99f15c5b94f516fb842f6ce Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 24 Dec 2023 21:55:58 +0800 Subject: [PATCH 1155/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 013d323a..9f5e8397 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 623 | 271 | 324 | 28 | +| 624 | 271 | 325 | 28 | ### 题目 @@ -350,6 +350,7 @@ |1273 | 比较字符串最小字母出现频次 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-strings-by-frequency-of-the-smallest-character.rs) | [leetcode](https://leetcode-cn.com/problems/compare-strings-by-frequency-of-the-smallest-character/) | Medium | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | |1293 | 存在连续三个奇数的数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/three-consecutive-odds.rs) | [leetcode](https://leetcode-cn.com/problems/three-consecutive-odds/) | Easy | +|1295 | 收集足够苹果的最小花园周长 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-garden-perimeter-to-collect-enough-apples.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-garden-perimeter-to-collect-enough-apples/) | Medium | |1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | |1319 | 独一无二的出现次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-number-of-occurrences.rs) | [leetcode](https://leetcode-cn.com/problems/unique-number-of-occurrences/) | Easy | |1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | From 5f40cef235bd09cc2525ba499c111592fd77c523 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 25 Dec 2023 19:52:58 +0800 Subject: [PATCH 1156/1556] src/bin/number-of-burgers-with-no-waste-of-ingredients.rs --- ...-of-burgers-with-no-waste-of-ingredients.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/bin/number-of-burgers-with-no-waste-of-ingredients.rs diff --git a/src/bin/number-of-burgers-with-no-waste-of-ingredients.rs b/src/bin/number-of-burgers-with-no-waste-of-ingredients.rs new file mode 100644 index 00000000..aee2eca6 --- /dev/null +++ b/src/bin/number-of-burgers-with-no-waste-of-ingredients.rs @@ -0,0 +1,18 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn num_of_burgers(tomato_slices: i32, cheese_slices: i32) -> Vec { + let x = (tomato_slices - 2 * cheese_slices) / 2; + let y = (4 * cheese_slices - tomato_slices) / 2; + + if x < 0 || y < 0 || 4 * x + 2 * y != tomato_slices || x + y != cheese_slices { + vec![] + } else { + vec![x, y] + } + } +} From eedcc4e92bf88a84667e4426de5ae293cd531d05 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 25 Dec 2023 19:52:59 +0800 Subject: [PATCH 1157/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f5e8397..95960be9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 624 | 271 | 325 | 28 | +| 625 | 271 | 326 | 28 | ### 题目 @@ -368,6 +368,7 @@ |1394 | 网格中的最小路径代价 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-cost-in-a-grid.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-cost-in-a-grid/) | Medium | |1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | |1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | +|1401 | 不浪费原料的汉堡制作方案 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-burgers-with-no-waste-of-ingredients.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-burgers-with-no-waste-of-ingredients/) | Medium | |1406 | 整数的各位积和之差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/) | Easy | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | |1426 | 和为零的 N 个不同整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | From 689fae016a8cb916a571e9d0ec8d5babf939fa92 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 26 Dec 2023 20:07:22 +0800 Subject: [PATCH 1158/1556] src/bin/find-champion-i.rs --- src/bin/find-champion-i.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/find-champion-i.rs diff --git a/src/bin/find-champion-i.rs b/src/bin/find-champion-i.rs new file mode 100644 index 00000000..76840e35 --- /dev/null +++ b/src/bin/find-champion-i.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_champion(grid: Vec>) -> i32 { + let mut hash_set = std::collections::HashSet::new(); + let mut champion = 0; + + for i in 0..grid.len() { + for j in 0..grid[0].len() { + if i == j { + continue; + } + + let m = if grid[i][j] == 1 { i } else { j }; + if !hash_set.contains(&m) { + champion = m as i32; + } + + hash_set.insert(if grid[i][j] == 1 { j } else { i }); + } + } + + champion + } +} From 797b4f4e8e220f71830fee3aaef6e3100e7fecc6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 26 Dec 2023 20:07:22 +0800 Subject: [PATCH 1159/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 95960be9..df513479 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 625 | 271 | 326 | 28 | +| 626 | 272 | 326 | 28 | ### 题目 @@ -504,6 +504,7 @@ |3045 | 使数组成为递增数组的最少右移次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-right-shifts-to-sort-the-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-right-shifts-to-sort-the-array/) | Easy | |3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | |3152 | 有序三元组中的最大值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-an-ordered-triplet-ii.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-an-ordered-triplet-ii/) | Medium | +|3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | |100240 | 魔术索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magic-index-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/magic-index-lcci/) | Easy | From f6e1fadcac11aa01bc5cb061652e545bb69de904 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 27 Dec 2023 20:42:11 +0800 Subject: [PATCH 1160/1556] src/bin/determine-the-winner-of-a-bowling-game.rs --- .../determine-the-winner-of-a-bowling-game.rs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bin/determine-the-winner-of-a-bowling-game.rs diff --git a/src/bin/determine-the-winner-of-a-bowling-game.rs b/src/bin/determine-the-winner-of-a-bowling-game.rs new file mode 100644 index 00000000..733b5e90 --- /dev/null +++ b/src/bin/determine-the-winner-of-a-bowling-game.rs @@ -0,0 +1,40 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn is_winner(player1: Vec, player2: Vec) -> i32 { + let (mut r, mut j) = (0, 0); + + for i in 0..player1.len() { + if i == 1 { + if player1[0] == 10 { + r += player1[i]; + } + if player2[0] == 10 { + j += player2[i]; + } + } else if i > 1 { + if player1[i - 1] == 10 || player1[i - 2] == 10 { + r += player1[i]; + } + if player2[i - 1] == 10 || player2[i - 2] == 10 { + j += player2[i]; + } + } + + r += player1[i]; + j += player2[i]; + } + + if r > j { + 1 + } else if j > r { + 2 + } else { + 0 + } + } +} From 5ae289f07afb8b92c76655e3a82814de6cb0159e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 27 Dec 2023 20:42:11 +0800 Subject: [PATCH 1161/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index df513479..3b1dbcd5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 626 | 272 | 326 | 28 | +| 627 | 273 | 326 | 28 | ### 题目 @@ -479,6 +479,7 @@ |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | |2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | |2679 | 统计桌面上的不同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-distinct-numbers-on-board.rs) | [leetcode](https://leetcode-cn.com/problems/count-distinct-numbers-on-board/) | Easy | +|2684 | 保龄球游戏的获胜者 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/determine-the-winner-of-a-bowling-game.rs) | [leetcode](https://leetcode-cn.com/problems/determine-the-winner-of-a-bowling-game/) | Easy | |2685 | 找出叠涂元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/first-completely-painted-row-or-column.rs) | [leetcode](https://leetcode-cn.com/problems/first-completely-painted-row-or-column/) | Medium | |2691 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-vowel-strings-in-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-vowel-strings-in-ranges/) | Medium | |2692 | 从数量最多的堆取走礼物 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/take-gifts-from-the-richest-pile.rs) | [leetcode](https://leetcode-cn.com/problems/take-gifts-from-the-richest-pile/) | Easy | From 6f3f1f6f15fff3bd620584a8bf25f7028cbaeeaa Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 28 Dec 2023 21:34:34 +0800 Subject: [PATCH 1162/1556] src/bin/find-resultant-array-after-removing-anagrams.rs --- ...resultant-array-after-removing-anagrams.rs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/bin/find-resultant-array-after-removing-anagrams.rs diff --git a/src/bin/find-resultant-array-after-removing-anagrams.rs b/src/bin/find-resultant-array-after-removing-anagrams.rs new file mode 100644 index 00000000..a24a889f --- /dev/null +++ b/src/bin/find-resultant-array-after-removing-anagrams.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn remove_anagrams(words: Vec) -> Vec { + let mut result = vec![words[0].clone()]; + for i in 1..words.len() { + if !Self::f(words[i - 1].as_bytes(), words[i].as_bytes()) { + result.push(words[i].clone()); + } + } + + result + } + + fn f(a: &[u8], b: &[u8]) -> bool { + if a.len() != b.len() { + return false; + } + + let mut map = std::collections::HashMap::new(); + for &i in a { + map.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + + for i in b { + if map.contains_key(i) { + if map[i] == 1 { + map.remove(i); + } else { + map.entry(*i).and_modify(|x| *x -= 1); + } + } + } + + map.is_empty() + } +} From 0ff26be9ffd9c29935961ed523fb1c6985f92a4a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 28 Dec 2023 21:34:34 +0800 Subject: [PATCH 1163/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b1dbcd5..255fde7b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 627 | 273 | 326 | 28 | +| 628 | 274 | 326 | 28 | ### 题目 @@ -357,6 +357,7 @@ |1329 | 玩筹码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cost-to-move-chips-to-the-same-position.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position/) | Easy | |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | |1342 | 可以攻击国王的皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/queens-that-can-attack-the-king.rs) | [leetcode](https://leetcode-cn.com/problems/queens-that-can-attack-the-king/) | Medium | +|1353 | 移除字母异位词后的结果数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-resultant-array-after-removing-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/find-resultant-array-after-removing-anagrams/) | Easy | |1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | |1363 | 兼具大小写的最好英文字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/greatest-english-letter-in-upper-and-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/greatest-english-letter-in-upper-and-lower-case/) | Easy | |1364 | 同积元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tuple-with-same-product.rs) | [leetcode](https://leetcode-cn.com/problems/tuple-with-same-product/) | Medium | From ced60706ecf1b7e12ede1ddcc5370d1682d45b32 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 29 Dec 2023 18:25:24 +0800 Subject: [PATCH 1164/1556] src/bin/buy-two-chocolates.rs --- src/bin/buy-two-chocolates.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/bin/buy-two-chocolates.rs diff --git a/src/bin/buy-two-chocolates.rs b/src/bin/buy-two-chocolates.rs new file mode 100644 index 00000000..73927dfe --- /dev/null +++ b/src/bin/buy-two-chocolates.rs @@ -0,0 +1,26 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn buy_choco(prices: Vec, money: i32) -> i32 { + let (mut a1, mut a2) = (prices[0].min(prices[1]), prices[1].max(prices[0])); + + for &i in prices[2..].iter() { + if i <= a1 { + a2 = a1; + a1 = i + } else if i > a1 && i < a2 { + a2 = i; + } + } + + if a1 + a2 > money { + money + } else { + money - a1 - a2 + } + } +} From fd592e5c8f879ca6608d111585665aa4de727ce9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 29 Dec 2023 18:25:25 +0800 Subject: [PATCH 1165/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 255fde7b..69b32943 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 628 | 274 | 326 | 28 | +| 629 | 275 | 326 | 28 | ### 题目 @@ -493,6 +493,7 @@ |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | |2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | |2752 | 倍数求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-multiples.rs) | [leetcode](https://leetcode-cn.com/problems/sum-multiples/) | Easy | +|2756 | 购买两块巧克力 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/buy-two-chocolates.rs) | [leetcode](https://leetcode-cn.com/problems/buy-two-chocolates/) | Easy | |2767 | K 个元素的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-with-exactly-k-elements.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-with-exactly-k-elements/) | Easy | |2787 | 移动机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/movement-of-robots.rs) | [leetcode](https://leetcode-cn.com/problems/movement-of-robots/) | Medium | |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | From 3ce84b84ccb14cace62da1566ed28df393bf2d31 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 30 Dec 2023 10:00:57 +0800 Subject: [PATCH 1166/1556] src/bin/day-of-the-week.rs --- src/bin/day-of-the-week.rs | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/bin/day-of-the-week.rs diff --git a/src/bin/day-of-the-week.rs b/src/bin/day-of-the-week.rs new file mode 100644 index 00000000..88daf489 --- /dev/null +++ b/src/bin/day-of-the-week.rs @@ -0,0 +1,46 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn day_of_the_week(day: i32, month: i32, year: i32) -> String { + let mut start = 3i32; + + for i in 1970..year { + start += 365; + if i % 4 == 0 { + if i % 100 == 0 && i % 400 != 0 { + continue; + } + + start += 1; + } + } + + const MONTH: [i32; 12] = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + for i in 1..month { + start += MONTH[i as usize - 1]; + if i == 2 && year % 4 == 0 { + if year % 100 == 0 && year % 400 != 0 { + continue; + } + start += 1; + } + } + + start += day; + + match start % 7 { + 0 => "Sunday".into(), + 1 => "Monday".into(), + 2 => "Tuesday".into(), + 3 => "Wednesday".into(), + 4 => "Thursday".into(), + 5 => "Friday".into(), + 6 => "Saturday".into(), + _ => unreachable!(), + } + } +} From eb5c7de486a91b87221680d273b6c3c0b4eed254 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 30 Dec 2023 10:00:58 +0800 Subject: [PATCH 1167/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 69b32943..94e5d929 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 629 | 275 | 326 | 28 | +| 630 | 276 | 326 | 28 | ### 题目 @@ -349,6 +349,7 @@ |1263 | 掷骰子等于目标和的方法数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-dice-rolls-with-target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-dice-rolls-with-target-sum/) | Medium | |1273 | 比较字符串最小字母出现频次 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-strings-by-frequency-of-the-smallest-character.rs) | [leetcode](https://leetcode-cn.com/problems/compare-strings-by-frequency-of-the-smallest-character/) | Medium | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | +|1289 | 一周中的第几天 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/day-of-the-week.rs) | [leetcode](https://leetcode-cn.com/problems/day-of-the-week/) | Easy | |1293 | 存在连续三个奇数的数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/three-consecutive-odds.rs) | [leetcode](https://leetcode-cn.com/problems/three-consecutive-odds/) | Easy | |1295 | 收集足够苹果的最小花园周长 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-garden-perimeter-to-collect-enough-apples.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-garden-perimeter-to-collect-enough-apples/) | Medium | |1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | From 720a83fea4a5257165b3b44ea6c79ae711d1d6a2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 31 Dec 2023 20:32:55 +0800 Subject: [PATCH 1168/1556] src/bin/day-of-the-year.rs --- src/bin/day-of-the-year.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/day-of-the-year.rs diff --git a/src/bin/day-of-the-year.rs b/src/bin/day-of-the-year.rs new file mode 100644 index 00000000..e8080bfc --- /dev/null +++ b/src/bin/day-of-the-year.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn day_of_year(date: String) -> i32 { + let mut d = date.split('-'); + let year = d.next().unwrap().parse::().unwrap(); + let month = d.next().unwrap().parse::().unwrap(); + let day = d.next().unwrap().parse::().unwrap(); + + let mut result = 0; + const MONTH: [i32; 12] = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + + for i in 1..month { + result += MONTH[i as usize - 1]; + if i == 2 && year % 4 == 0 { + if year % 100 == 0 && year % 400 != 0 { + continue; + } + result += 1; + } + } + + result + day + } +} From a753b45bdaf7be4735db43fd9242a6f2aa4aae45 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 31 Dec 2023 20:32:55 +0800 Subject: [PATCH 1169/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 94e5d929..5648e576 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 630 | 276 | 326 | 28 | +| 631 | 277 | 326 | 28 | ### 题目 @@ -346,6 +346,7 @@ |1236 | 第 N 个泰波那契数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-th-tribonacci-number.rs) | [leetcode](https://leetcode-cn.com/problems/n-th-tribonacci-number/) | Easy | |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | |1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | +|1260 | 一年中的第几天 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/day-of-the-year.rs) | [leetcode](https://leetcode-cn.com/problems/day-of-the-year/) | Easy | |1263 | 掷骰子等于目标和的方法数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-dice-rolls-with-target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-dice-rolls-with-target-sum/) | Medium | |1273 | 比较字符串最小字母出现频次 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-strings-by-frequency-of-the-smallest-character.rs) | [leetcode](https://leetcode-cn.com/problems/compare-strings-by-frequency-of-the-smallest-character/) | Medium | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | From 8ab59d647a150de3b3312a468d478cdd83230e9b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 2 Jan 2024 14:00:51 +0800 Subject: [PATCH 1170/1556] src/bin/split-strings-by-separator.rs --- src/bin/split-strings-by-separator.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/split-strings-by-separator.rs diff --git a/src/bin/split-strings-by-separator.rs b/src/bin/split-strings-by-separator.rs new file mode 100644 index 00000000..e5a4f75c --- /dev/null +++ b/src/bin/split-strings-by-separator.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn split_words_by_separator(words: Vec, separator: char) -> Vec { + let mut result = vec![]; + for i in words { + result.extend( + i.split(separator) + .filter(|x| !x.is_empty()) + .map(|x| x.to_string()), + ); + } + + result + } +} From 89744a4e5ebfdcf288a8b9fe06275244b99c3dbd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 2 Jan 2024 14:00:51 +0800 Subject: [PATCH 1171/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5648e576..c39eb4d6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 631 | 277 | 326 | 28 | +| 632 | 278 | 326 | 28 | ### 题目 @@ -504,6 +504,7 @@ |2816 | 字典序最小回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographically-smallest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographically-smallest-palindrome/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |2866 | 最长奇偶子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-even-odd-subarray-with-threshold.rs) | [leetcode](https://leetcode-cn.com/problems/longest-even-odd-subarray-with-threshold/) | Easy | +|2881 | 按分隔符拆分字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-strings-by-separator.rs) | [leetcode](https://leetcode-cn.com/problems/split-strings-by-separator/) | Easy | |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | |3045 | 使数组成为递增数组的最少右移次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-right-shifts-to-sort-the-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-right-shifts-to-sort-the-array/) | Easy | From 605d2dfd42105a14bb3494a1b48d293047c71553 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Jan 2024 20:17:31 +0800 Subject: [PATCH 1172/1556] src/bin/remove-nodes-from-linked-list.rs --- src/bin/remove-nodes-from-linked-list.rs | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/bin/remove-nodes-from-linked-list.rs diff --git a/src/bin/remove-nodes-from-linked-list.rs b/src/bin/remove-nodes-from-linked-list.rs new file mode 100644 index 00000000..eb98449c --- /dev/null +++ b/src/bin/remove-nodes-from-linked-list.rs @@ -0,0 +1,46 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} + +impl Solution { + pub fn remove_nodes(head: Option>) -> Option> { + let mut head = head; + let mut stack = vec![]; + while let Some(mut x) = head.take() { + while let Some(m) = stack.pop() { + if m >= x.val { + stack.push(m); + break; + } + } + stack.push(x.val); + head = x.next.take(); + } + + let mut pre_head = ListNode { val: 0, next: None }; + let mut current = &mut pre_head.next; + + for x in stack { + current.insert(Box::new(ListNode { val: x, next: None })); + current = &mut current.as_mut().unwrap().next; + } + + pre_head.next.take() + } +} From 646b40a775bb413a6a39f93d81183cb461ed7529 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Jan 2024 20:17:32 +0800 Subject: [PATCH 1173/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c39eb4d6..ba8615f5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 632 | 278 | 326 | 28 | +| 633 | 278 | 327 | 28 | ### 题目 @@ -463,6 +463,7 @@ |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | |2571 | 找出中枢整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-pivot-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-pivot-integer/) | Easy | +|2573 | 从链表中移除节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nodes-from-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nodes-from-linked-list/) | Medium | |2575 | 分割圆的最少切割次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cuts-to-divide-a-circle.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cuts-to-divide-a-circle/) | Easy | |2580 | 回环句 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circular-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/circular-sentence/) | Easy | |2585 | 删除每行中的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-greatest-value-in-each-row.rs) | [leetcode](https://leetcode-cn.com/problems/delete-greatest-value-in-each-row/) | Easy | From 92eb9b3acc979b4cbbd75ac86e3b2f0be65801dc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 4 Jan 2024 21:35:57 +0800 Subject: [PATCH 1174/1556] src/bin/maximum-rows-covered-by-columns.rs --- src/bin/maximum-rows-covered-by-columns.rs | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/maximum-rows-covered-by-columns.rs diff --git a/src/bin/maximum-rows-covered-by-columns.rs b/src/bin/maximum-rows-covered-by-columns.rs new file mode 100644 index 00000000..23552d60 --- /dev/null +++ b/src/bin/maximum-rows-covered-by-columns.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_rows(matrix: Vec>, num_select: i32) -> i32 { + let mut v = vec![]; + for i in matrix.iter() { + let mut s = 0; + for j in 0..i.len() { + s |= i[j] << (i.len() - j - 1) as i32; + } + + v.push(s); + } + + let mut result = 0; + let mut s: i32 = (0..matrix[0].len()).fold(1, |x, y| x | (1 << y)); + + for i in 0..=s { + if i.count_ones() as i32 == num_select { + let mut r = 0; + for &v in v.iter() { + if v & i == v { + r += 1; + } + } + result = result.max(r); + } + } + + result + } +} From 0d5360f545f164caee2641971985fbbda3f25c5c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 4 Jan 2024 21:35:58 +0800 Subject: [PATCH 1175/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba8615f5..110a6db3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 633 | 278 | 327 | 28 | +| 634 | 278 | 328 | 28 | ### 题目 @@ -458,6 +458,7 @@ |2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | |2470 | 从字符串中移除星号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-stars-from-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/removing-stars-from-a-string/) | Medium | |2473 | 数位和相等数对的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs) | [leetcode](https://leetcode-cn.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | +|2482 | 被列覆盖的最多行数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-rows-covered-by-columns.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-rows-covered-by-columns/) | Medium | |2493 | 反转二叉树的奇数层 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-odd-levels-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-odd-levels-of-binary-tree/) | Medium | |2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | From d3ca1fdd7842673f6a81c3f339be806e2f54897b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Jan 2024 20:25:05 +0800 Subject: [PATCH 1176/1556] src/bin/maximum-value-after-insertion.rs --- src/bin/maximum-value-after-insertion.rs | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/bin/maximum-value-after-insertion.rs diff --git a/src/bin/maximum-value-after-insertion.rs b/src/bin/maximum-value-after-insertion.rs new file mode 100644 index 00000000..55bfe71e --- /dev/null +++ b/src/bin/maximum-value-after-insertion.rs @@ -0,0 +1,44 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_value(n: String, x: i32) -> String { + let mut r = Vec::with_capacity(n.len() + 1); + let mut n = n.as_bytes(); + let mut nega = false; + if n[0] == b'-' { + nega = true; + n = &n[1..]; + r.push(b'-'); + } + let x = x as u8 + b'0'; + let mut done = false; + for &i in n { + if done { + r.push(i); + } else { + if nega { + if x < i { + r.push(x); + done = true; + } + } else { + if x > i { + r.push(x); + done = true; + } + } + r.push(i); + } + } + + if !done { + r.push(x); + } + + unsafe { String::from_utf8_unchecked(r) } + } +} From 447ee110d6659af82752b2c501549d0f5c282705 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Jan 2024 20:25:17 +0800 Subject: [PATCH 1177/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 110a6db3..751b4ba0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 634 | 278 | 328 | 28 | +| 635 | 278 | 329 | 28 | ### 题目 @@ -428,6 +428,7 @@ |1960 | 判断句子是否为全字母句 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-the-sentence-is-pangram.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-the-sentence-is-pangram/) | Easy | |1971 | 增长的内存泄露 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/incremental-memory-leak.rs) | [leetcode](https://leetcode-cn.com/problems/incremental-memory-leak/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | +|2011 | 插入后的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-after-insertion.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-after-insertion/) | Medium | |2022 | 最大子序列交替和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-alternating-subsequence-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-alternating-subsequence-sum/) | Medium | |2032 | 字符串中的最大奇数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-odd-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-odd-number-in-string/) | Easy | |2049 | 消灭怪物的最大数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/eliminate-maximum-number-of-monsters.rs) | [leetcode](https://leetcode-cn.com/problems/eliminate-maximum-number-of-monsters/) | Medium | From ef572f10ae3d892b7ae6cea16f63fa2154f3b42c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 6 Jan 2024 13:47:31 +0800 Subject: [PATCH 1178/1556] src/bin/insert-greatest-common-divisors-in-linked-list.rs --- ...greatest-common-divisors-in-linked-list.rs | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/bin/insert-greatest-common-divisors-in-linked-list.rs diff --git a/src/bin/insert-greatest-common-divisors-in-linked-list.rs b/src/bin/insert-greatest-common-divisors-in-linked-list.rs new file mode 100644 index 00000000..e6f38ad0 --- /dev/null +++ b/src/bin/insert-greatest-common-divisors-in-linked-list.rs @@ -0,0 +1,73 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} + +impl Solution { + pub fn insert_greatest_common_divisors(head: Option>) -> Option> { + let mut h = ListNode { val: 0, next: None }; + let mut current = &mut h.next; + let mut head = head; + let mut next = head.as_mut().and_then(|x| x.next.take()); + + loop { + match (head, next) { + (Some(mut x), Some(mut y)) => { + next = y.next.take(); + let (max, min) = if x.val > y.val { + (x.val, y.val) + } else { + (y.val, x.val) + }; + + let gdc = Self::gdc(max, min); + current.insert(x); + current = &mut current.as_mut().unwrap().next; + current.insert(Box::new(ListNode::new(gdc))); + current = &mut current.as_mut().unwrap().next; + head = Some(y); + } + (Some(x), None) => { + current.insert(x); + break; + } + _ => break, + } + } + + h.next.take() + } + + /// 辗转相除法, 又名欧几里德算法(Euclidean algorithm),是求最大公约数的一种方法。方法是: + /// 用较大数除以较小数,再用出现的余数(第一余数)去除除数,再用出现的余数(第二余数)去除第一余数, + /// 如此反复,直到最后余数是0为止。那么最后的除数就是这两个数的最大公约数。 + pub fn gdc(max: i32, min: i32) -> i32 { + let r = max % min; + if r == 0 { + return min; + } + + Self::gdc(min, r) + } +} + +#[test] +fn test_gdc() { + assert_eq!(6, Solution::gdc(30, 18)); + assert_eq!(6, Solution::gdc(123456, 7890)); +} From 8f8dfb569ca4219cb4e3d0bc0154a859891bb955 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 7 Jan 2024 11:14:36 +0800 Subject: [PATCH 1179/1556] fix: leetcode url invalid --- src/http.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/http.rs b/src/http.rs index 251e46e9..1316afd9 100644 --- a/src/http.rs +++ b/src/http.rs @@ -10,7 +10,7 @@ lazy_static! { static ref RE: Regex = Regex::new(r".*?/problems/(.*?)/").unwrap(); } -const URL: &str = "https://leetcode-cn.com/graphql/"; +const URL: &str = "https://leetcode.cn/graphql/"; #[derive(Debug, Eq, PartialEq)] pub enum Difficulty { @@ -96,7 +96,7 @@ pub struct CodeSnippets { pub lang: String, #[serde(rename = "langSlug")] pub lang_slug: String, - #[serde(rename = "__typename")] + #[serde(rename = "__typename", default)] pub typename: String, } From d2ebd5c0786650b2a0dcfe730fd7b82a577d6ad4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 7 Jan 2024 13:03:50 +0800 Subject: [PATCH 1180/1556] src/bin/find-the-original-array-of-prefix-xor.rs --- .../find-the-original-array-of-prefix-xor.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/find-the-original-array-of-prefix-xor.rs diff --git a/src/bin/find-the-original-array-of-prefix-xor.rs b/src/bin/find-the-original-array-of-prefix-xor.rs new file mode 100644 index 00000000..7102561c --- /dev/null +++ b/src/bin/find-the-original-array-of-prefix-xor.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + println!("{:?}", Solution::find_array(vec![5, 2, 0, 3, 1])); +} + +struct Solution; + +impl Solution { + pub fn find_array(pref: Vec) -> Vec { + let mut arr = vec![0; pref.len()]; + arr[0] = pref[0]; + let mut x = arr[0]; + for i in 1..pref.len() { + arr[i] = x ^ pref[i]; + x ^= arr[i]; + } + + arr + } +} From c54355849e0acefe91536af12881c5db810191fb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 7 Jan 2024 13:03:51 +0800 Subject: [PATCH 1181/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 751b4ba0..03a46f22 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 635 | 278 | 329 | 28 | +| 636 | 278 | 330 | 28 | ### 题目 @@ -462,6 +462,7 @@ |2482 | 被列覆盖的最多行数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-rows-covered-by-columns.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-rows-covered-by-columns/) | Medium | |2493 | 反转二叉树的奇数层 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-odd-levels-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-odd-levels-of-binary-tree/) | Medium | |2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | +|2519 | 找出前缀异或的原始数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-original-array-of-prefix-xor.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-original-array-of-prefix-xor/) | Medium | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | |2571 | 找出中枢整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-pivot-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-pivot-integer/) | Easy | From 5ccb22d7f517f73de8b64e5e2f9118806e7e0054 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 8 Jan 2024 20:27:25 +0800 Subject: [PATCH 1182/1556] src/bin/number-of-boomerangs.rs --- src/bin/number-of-boomerangs.rs | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/bin/number-of-boomerangs.rs diff --git a/src/bin/number-of-boomerangs.rs b/src/bin/number-of-boomerangs.rs new file mode 100644 index 00000000..eb8bde4f --- /dev/null +++ b/src/bin/number-of-boomerangs.rs @@ -0,0 +1,46 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn number_of_boomerangs(points: Vec>) -> i32 { + if points.len() < 3 { + return 0; + } + + let mut x: std::collections::HashMap> = + std::collections::HashMap::new(); + + for i in 0..points.len() { + for j in 0..points.len() { + if i == j { + continue; + } + + let length = + (points[i][0] - points[j][0]).pow(2) + (points[i][1] - points[j][1]).pow(2); + + x.entry(i) + .and_modify(|m| { + m.entry(length).and_modify(|x| *x += 1).or_insert(1); + }) + .or_insert({ + let mut m = std::collections::HashMap::new(); + m.insert(length, 1); + m + }); + } + } + + let mut result = 0; + for v in x.values() { + for x in v.values() { + result += (1 + x - 1) * (x - 1); + } + } + + result + } +} From 8c763b953851f982620fb1941fcbb1886c4bc383 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 8 Jan 2024 20:27:25 +0800 Subject: [PATCH 1183/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 03a46f22..b6e77709 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 636 | 278 | 330 | 28 | +| 637 | 278 | 331 | 28 | ### 题目 @@ -239,6 +239,7 @@ |438 | 找到字符串中所有字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-anagrams-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-anagrams-in-a-string/) | Medium | |442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | |445 | 两数相加 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers-ii.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers-ii/) | Medium | +|447 | 回旋镖的数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-boomerangs.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-boomerangs/) | Medium | |448 | 找到所有数组中消失的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-numbers-disappeared-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-numbers-disappeared-in-an-array/) | Easy | |449 | 序列化和反序列化二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-bst.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-bst/) | Medium | |460 | LFU 缓存 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lfu-cache.rs) | [leetcode](https://leetcode-cn.com/problems/lfu-cache/) | Hard | From e404655356176cfcfed6a4bf39fbafec31aec6eb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 9 Jan 2024 20:34:58 +0800 Subject: [PATCH 1184/1556] src/bin/extra-characters-in-a-string.rs --- src/bin/extra-characters-in-a-string.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/extra-characters-in-a-string.rs diff --git a/src/bin/extra-characters-in-a-string.rs b/src/bin/extra-characters-in-a-string.rs new file mode 100644 index 00000000..67c6c4a9 --- /dev/null +++ b/src/bin/extra-characters-in-a-string.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_extra_char(s: String, dictionary: Vec) -> i32 { + let mut set: std::collections::HashSet<_> = dictionary.iter().map(|x| x.as_str()).collect(); + let mut dp = vec![vec![-1; s.len()]; s.len()]; + + let n = s.len(); + let mut dp = vec![0; n + 1]; + for i in 1..=n { + dp[i] = dp[i - 1] + 1; + for j in 1..=i { + if set.contains(&s[j - 1..i]) { + dp[i] = dp[i].min(dp[j - 1]); + } + } + } + dp[n] + } +} From 7233fa69a8464bca3854bb5dbea9bf0841105a95 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 9 Jan 2024 20:34:59 +0800 Subject: [PATCH 1185/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b6e77709..80203120 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 637 | 278 | 331 | 28 | +| 638 | 278 | 332 | 28 | ### 题目 @@ -500,6 +500,7 @@ |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | |2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | |2752 | 倍数求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-multiples.rs) | [leetcode](https://leetcode-cn.com/problems/sum-multiples/) | Easy | +|2755 | 字符串中的额外字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/extra-characters-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/extra-characters-in-a-string/) | Medium | |2756 | 购买两块巧克力 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/buy-two-chocolates.rs) | [leetcode](https://leetcode-cn.com/problems/buy-two-chocolates/) | Easy | |2767 | K 个元素的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-with-exactly-k-elements.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-with-exactly-k-elements/) | Easy | |2787 | 移动机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/movement-of-robots.rs) | [leetcode](https://leetcode-cn.com/problems/movement-of-robots/) | Medium | From 5026789bf57b4a02fa3b159cd731b51ef79a8240 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 10 Jan 2024 19:57:56 +0800 Subject: [PATCH 1186/1556] src/bin/minimum-string-length-after-removing-substrings.rs --- ...string-length-after-removing-substrings.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/minimum-string-length-after-removing-substrings.rs diff --git a/src/bin/minimum-string-length-after-removing-substrings.rs b/src/bin/minimum-string-length-after-removing-substrings.rs new file mode 100644 index 00000000..dd1cd470 --- /dev/null +++ b/src/bin/minimum-string-length-after-removing-substrings.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_length(s: String) -> i32 { + let mut stack = vec![]; + for &i in s.as_bytes() { + match i { + b'B' | b'D' => match stack.last() { + Some(&x) if x + 1 == i => { + stack.pop(); + } + _ => stack.push(i), + }, + _ => stack.push(i), + } + } + + stack.len() as i32 + } +} From 4f1c36f6ba0df683c5f516b20a72a69d10b7fa1d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 10 Jan 2024 19:57:56 +0800 Subject: [PATCH 1187/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 80203120..60a130f5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 638 | 278 | 332 | 28 | +| 639 | 279 | 332 | 28 | ### 题目 @@ -505,6 +505,7 @@ |2767 | K 个元素的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-with-exactly-k-elements.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-with-exactly-k-elements/) | Easy | |2787 | 移动机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/movement-of-robots.rs) | [leetcode](https://leetcode-cn.com/problems/movement-of-robots/) | Medium | |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | +|2800 | 删除子串后的字符串最小长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-string-length-after-removing-substrings.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-string-length-after-removing-substrings/) | Easy | |2802 | 求一个整数的惩罚数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-punishment-number-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-punishment-number-of-an-integer/) | Medium | |2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | |2816 | 字典序最小回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographically-smallest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographically-smallest-palindrome/) | Easy | From e02a5ed258f2871d7a4c52850b56ad124fdcb1f7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 11 Jan 2024 20:13:20 +0800 Subject: [PATCH 1188/1556] src/bin/minimum-additions-to-make-valid-string.rs --- .../minimum-additions-to-make-valid-string.rs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/bin/minimum-additions-to-make-valid-string.rs diff --git a/src/bin/minimum-additions-to-make-valid-string.rs b/src/bin/minimum-additions-to-make-valid-string.rs new file mode 100644 index 00000000..43a8318e --- /dev/null +++ b/src/bin/minimum-additions-to-make-valid-string.rs @@ -0,0 +1,50 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn add_minimum(word: String) -> i32 { + let mut result = 0; + let mut index = 0usize; + let word = word.as_bytes(); + while index < word.len() { + match word[index] { + b'a' => match (word.get(index + 1), word.get(index + 2)) { + (Some(b'b'), Some(b'c')) => index += 3, + (Some(b'b'), _) => { + index += 2; + result += 1; + } + (Some(b'c'), _) => { + index += 2; + result += 1; + } + _ => { + index += 1; + result += 2; + } + }, + b'b' => match word.get(index + 1) { + Some(b'c') => { + index += 2; + result += 1; + } + + _ => { + index += 1; + result += 2; + } + }, + b'c' => { + index += 1; + result += 2; + } + _ => unreachable!(), + } + } + + result + } +} From 583ab806e619f565441592118b271343f488e25c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 11 Jan 2024 20:13:21 +0800 Subject: [PATCH 1189/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 60a130f5..5c0ad564 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 639 | 279 | 332 | 28 | +| 640 | 279 | 333 | 28 | ### 题目 @@ -498,6 +498,7 @@ |2723 | 最长平衡子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-longest-balanced-substring-of-a-binary-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-longest-balanced-substring-of-a-binary-string/) | Easy | |2727 | 老人的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-senior-citizens.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-senior-citizens/) | Easy | |2728 | 矩阵中的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/sum-in-a-matrix/) | Medium | +|2736 | 构造有效字符串的最少插入数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-additions-to-make-valid-string.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-additions-to-make-valid-string/) | Medium | |2748 | 计算列车到站时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-delayed-arrival-time.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-delayed-arrival-time/) | Easy | |2752 | 倍数求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-multiples.rs) | [leetcode](https://leetcode-cn.com/problems/sum-multiples/) | Easy | |2755 | 字符串中的额外字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/extra-characters-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/extra-characters-in-a-string/) | Medium | From 83fa5af77f471b6a8d689966e100eda6ddd423ca Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 12 Jan 2024 18:47:04 +0800 Subject: [PATCH 1190/1556] src/bin/count-common-words-with-one-occurrence.rs --- .../count-common-words-with-one-occurrence.rs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/count-common-words-with-one-occurrence.rs diff --git a/src/bin/count-common-words-with-one-occurrence.rs b/src/bin/count-common-words-with-one-occurrence.rs new file mode 100644 index 00000000..1ae5a394 --- /dev/null +++ b/src/bin/count-common-words-with-one-occurrence.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_words(words1: Vec, words2: Vec) -> i32 { + let mut hash1 = std::collections::HashMap::new(); + let mut hash2 = std::collections::HashMap::new(); + + for i in words1 { + hash1.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + + for i in words2 { + hash2.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + + let mut result = 0; + for (key, val) in hash1 { + if val != 1 { + continue; + } + + if let Some(x) = hash2.get(&key) { + if *x == 1 { + result += 1; + } + } + } + + result + } +} From b79102bc8a5121b919eb30bb1e54edeb2c81c237 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 12 Jan 2024 18:47:05 +0800 Subject: [PATCH 1191/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c0ad564..19ae19e8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 640 | 279 | 333 | 28 | +| 641 | 280 | 333 | 28 | ### 题目 @@ -441,6 +441,7 @@ |2161 | 股票价格波动 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/stock-price-fluctuation.rs) | [leetcode](https://leetcode-cn.com/problems/stock-price-fluctuation/) | Medium | |2168 | 检查句子中的数字是否递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-numbers-are-ascending-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-numbers-are-ascending-in-a-sentence/) | Easy | |2177 | 检查两个字符串是否几乎相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-whether-two-strings-are-almost-equivalent.rs) | [leetcode](https://leetcode-cn.com/problems/check-whether-two-strings-are-almost-equivalent/) | Easy | +|2190 | 统计出现过一次的公共字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-common-words-with-one-occurrence.rs) | [leetcode](https://leetcode-cn.com/problems/count-common-words-with-one-occurrence/) | Easy | |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | |2226 | 环和杆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rings-and-rods.rs) | [leetcode](https://leetcode-cn.com/problems/rings-and-rods/) | Easy | |2233 | 股票平滑下跌阶段的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-smooth-descent-periods-of-a-stock.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-smooth-descent-periods-of-a-stock/) | Medium | From 9f9455ef4c7c515289222c413b9c199d542f2c1e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 13 Jan 2024 10:11:42 +0800 Subject: [PATCH 1192/1556] src/bin/construct-string-with-repeat-limit.rs --- src/bin/construct-string-with-repeat-limit.rs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/bin/construct-string-with-repeat-limit.rs diff --git a/src/bin/construct-string-with-repeat-limit.rs b/src/bin/construct-string-with-repeat-limit.rs new file mode 100644 index 00000000..f463b4fa --- /dev/null +++ b/src/bin/construct-string-with-repeat-limit.rs @@ -0,0 +1,55 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn repeat_limited_string(s: String, repeat_limit: i32) -> String { + let mut count = [0; 26]; + + for i in s.as_bytes() { + count[(*i - b'a') as usize] += 1; + } + + let mut result = vec![]; + 'L: loop { + for i in (0..26).rev() { + if count[i] == 0 { + if i == 0 { + break 'L; + } + continue; + } + + if count[i] <= repeat_limit { + for j in 0..count[i] { + result.push(i as u8 + b'a'); + } + count[i] = 0; + continue 'L; + } else { + for j in 0..repeat_limit { + result.push(i as u8 + b'a'); + } + count[i] -= repeat_limit; + let mut flag = false; + for j in (0..i).rev() { + if count[j] != 0 { + result.push(j as u8 + b'a'); + count[j] -= 1; + flag = true; + continue 'L; + } + } + + if !flag { + break 'L; + } + } + } + } + + unsafe { String::from_utf8_unchecked(result) } + } +} From 0ad53e60d7b2f8bc7bdf828247e9a86a55b27b6e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 13 Jan 2024 10:11:43 +0800 Subject: [PATCH 1193/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 19ae19e8..c7ec0e93 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 641 | 280 | 333 | 28 | +| 642 | 280 | 334 | 28 | ### 题目 @@ -450,6 +450,7 @@ |2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | +|2300 | 构造限制重复的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-string-with-repeat-limit.rs) | [leetcode](https://leetcode-cn.com/problems/construct-string-with-repeat-limit/) | Medium | |2310 | 将数组和减半的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-halve-array-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-halve-array-sum/) | Medium | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |2346 | 字符串中最大的 3 位相同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-3-same-digit-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-3-same-digit-number-in-string/) | Easy | From a20a8a2f2f39433751f0fe8789121787d3bdc7d4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 14 Jan 2024 22:34:44 +0800 Subject: [PATCH 1194/1556] src/bin/linked-list-in-binary-tree.rs --- src/bin/linked-list-in-binary-tree.rs | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/bin/linked-list-in-binary-tree.rs diff --git a/src/bin/linked-list-in-binary-tree.rs b/src/bin/linked-list-in-binary-tree.rs new file mode 100644 index 00000000..e859a0ad --- /dev/null +++ b/src/bin/linked-list-in-binary-tree.rs @@ -0,0 +1,74 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +impl Solution { + pub fn is_sub_path(head: Option>, root: Option>>) -> bool { + if root.is_none() { + return false; + } + + Self::dfs(head.clone(), root.clone()) + || Self::is_sub_path( + head.clone(), + root.clone().and_then(|x| x.borrow().left.clone()), + ) + || Self::is_sub_path( + head.clone(), + root.clone().and_then(|x| x.borrow().right.clone()), + ) + } + + fn dfs(head: Option>, root: Option>>) -> bool { + match (head.clone(), root.clone()) { + (Some(h), Some(r)) => { + if h.val != r.borrow().val { + return false; + } + + Self::dfs(h.next.clone(), r.borrow().left.clone()) + || Self::dfs(h.next.clone(), r.borrow().right.clone()) + } + (Some(h), None) => false, + _ => true, + } + } +} From b1bed1aa553e62eac41740fd4fe501f72e5460ad Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 14 Jan 2024 22:34:45 +0800 Subject: [PATCH 1195/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c7ec0e93..98fc950a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 642 | 280 | 334 | 28 | +| 643 | 280 | 335 | 28 | ### 题目 @@ -384,6 +384,7 @@ |1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | |1472 | 上升下降字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increasing-decreasing-string.rs) | [leetcode](https://leetcode-cn.com/problems/increasing-decreasing-string/) | Easy | |1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | +|1484 | 二叉树中的链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/linked-list-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/linked-list-in-binary-tree/) | Medium | |1491 | 二进制字符串前缀一致的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-times-binary-string-is-prefix-aligned.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-times-binary-string-is-prefix-aligned/) | Medium | |1501 | 圆和矩形是否有重叠 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circle-and-rectangle-overlapping.rs) | [leetcode](https://leetcode-cn.com/problems/circle-and-rectangle-overlapping/) | Medium | |1503 | 做菜顺序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reducing-dishes.rs) | [leetcode](https://leetcode-cn.com/problems/reducing-dishes/) | Hard | From 772b18979e71cb1086b9fd72f3f83b3c94fb2170 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 15 Jan 2024 20:41:03 +0800 Subject: [PATCH 1196/1556] src/bin/design-authentication-manager.rs --- src/bin/design-authentication-manager.rs | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/bin/design-authentication-manager.rs diff --git a/src/bin/design-authentication-manager.rs b/src/bin/design-authentication-manager.rs new file mode 100644 index 00000000..68968b35 --- /dev/null +++ b/src/bin/design-authentication-manager.rs @@ -0,0 +1,50 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +struct AuthenticationManager { + storage: std::collections::HashMap, + ttl: i32, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +/** + * Your AuthenticationManager object will be instantiated and called as such: + * let obj = AuthenticationManager::new(timeToLive); + * obj.generate(tokenId, currentTime); + * obj.renew(tokenId, currentTime); + * let ret_3: i32 = obj.count_unexpired_tokens(currentTime); + */ +impl AuthenticationManager { + fn new(timeToLive: i32) -> Self { + Self { + ttl: timeToLive, + storage: std::collections::HashMap::new(), + } + } + + fn generate(&mut self, token_id: String, current_time: i32) { + self.storage.insert(token_id, current_time); + } + + fn renew(&mut self, token_id: String, current_time: i32) { + match self.storage.remove(&token_id) { + Some(x) if x + self.ttl > current_time => { + self.storage.insert(token_id, current_time); + } + _ => {} + } + } + + fn count_unexpired_tokens(&self, current_time: i32) -> i32 { + self.storage + .values() + .filter(|x| *x + self.ttl > current_time) + .count() as i32 + } +} From f23aead0d225170339ee48d7d4e57084ebabe9b6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 15 Jan 2024 20:41:04 +0800 Subject: [PATCH 1197/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 98fc950a..fe1004a5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 643 | 280 | 335 | 28 | +| 644 | 280 | 336 | 28 | ### 题目 @@ -423,6 +423,7 @@ |1884 | 生成交替二进制字符串的最少操作数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-changes-to-make-alternating-binary-string.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-changes-to-make-alternating-binary-string/) | Easy | |1894 | 交替合并字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-strings-alternately.rs) | [leetcode](https://leetcode-cn.com/problems/merge-strings-alternately/) | Easy | |1899 | 统计匹配检索规则的物品数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-items-matching-a-rule.rs) | [leetcode](https://leetcode-cn.com/problems/count-items-matching-a-rule/) | Easy | +|1905 | 设计一个验证系统 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-authentication-manager.rs) | [leetcode](https://leetcode-cn.com/problems/design-authentication-manager/) | Medium | |1929 | 有界数组中指定下标处的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-at-a-given-index-in-a-bounded-array/) | Medium | |1938 | 最少操作使数组递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-make-the-array-increasing.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-increasing/) | Easy | |1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | From f6946c1efc2a2bfed05919934c7590bc090250db Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 16 Jan 2024 20:41:11 +0800 Subject: [PATCH 1198/1556] src/bin/minimize-result-by-adding-parentheses-to-expression.rs --- ...ult-by-adding-parentheses-to-expression.rs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/bin/minimize-result-by-adding-parentheses-to-expression.rs diff --git a/src/bin/minimize-result-by-adding-parentheses-to-expression.rs b/src/bin/minimize-result-by-adding-parentheses-to-expression.rs new file mode 100644 index 00000000..2767b9b5 --- /dev/null +++ b/src/bin/minimize-result-by-adding-parentheses-to-expression.rs @@ -0,0 +1,66 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!( + Solution::minimize_result("12+34".to_string()), + "1(2+3)4".to_string() + ); +} + +struct Solution; + +impl Solution { + pub fn minimize_result(expression: String) -> String { + let mut expression = expression.split('+'); + let left = expression.next().unwrap(); + let right = expression.next().unwrap(); + + let mut left_index = 0; + let mut right_index = 0; + let mut min = i32::MAX; + + for i in 0..left.len() { + let l1 = if i == 0 { + 1 + } else { + left[..i].parse::().unwrap() + }; + + let l2 = if i < left.len() { + left[i..].parse::().unwrap() + } else { + 1 + }; + + for j in 1..=right.len() { + let l3 = if j == 0 { + 1 + } else { + right[..j].parse::().unwrap() + }; + + let l4 = if j < right.len() { + right[j..].parse::().unwrap() + } else { + 1 + }; + + let c = l1 * (l2 + l3) * l4; + + if c < min { + left_index = i; + right_index = j; + min = c; + } + } + } + + format!( + "{}({}+{}){}", + &left[..left_index], + &left[left_index..], + &right[..right_index], + &right[right_index..] + ) + } +} From f46db64b5941b39d90628c9a9ac4d3a98b833374 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 16 Jan 2024 20:41:12 +0800 Subject: [PATCH 1199/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fe1004a5..c20aee38 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 644 | 280 | 336 | 28 | +| 645 | 280 | 337 | 28 | ### 题目 @@ -455,6 +455,7 @@ |2300 | 构造限制重复的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-string-with-repeat-limit.rs) | [leetcode](https://leetcode-cn.com/problems/construct-string-with-repeat-limit/) | Medium | |2310 | 将数组和减半的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-halve-array-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-halve-array-sum/) | Medium | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | +|2328 | 向表达式添加括号后的最小结果 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimize-result-by-adding-parentheses-to-expression.rs) | [leetcode](https://leetcode-cn.com/problems/minimize-result-by-adding-parentheses-to-expression/) | Medium | |2346 | 字符串中最大的 3 位相同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-3-same-digit-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-3-same-digit-number-in-string/) | Easy | |2351 | 买钢笔和铅笔的方案数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-ways-to-buy-pens-and-pencils.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-ways-to-buy-pens-and-pencils/) | Medium | |2384 | 判断根结点是否等于子结点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/root-equals-sum-of-children.rs) | [leetcode](https://leetcode-cn.com/problems/root-equals-sum-of-children/) | Easy | From a43611cdb16e1b061c3178a314b5bd5212cc670b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 17 Jan 2024 19:48:19 +0800 Subject: [PATCH 1200/1556] src/bin/find-maximum-number-of-string-pairs.rs --- .../find-maximum-number-of-string-pairs.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/find-maximum-number-of-string-pairs.rs diff --git a/src/bin/find-maximum-number-of-string-pairs.rs b/src/bin/find-maximum-number-of-string-pairs.rs new file mode 100644 index 00000000..b404289d --- /dev/null +++ b/src/bin/find-maximum-number-of-string-pairs.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_number_of_string_pairs(words: Vec) -> i32 { + use std::iter::FromIterator; + let mut hash = std::collections::HashMap::new(); + let mut result = 0; + + for mut i in words { + let reverse = String::from_iter(i.chars().into_iter().rev()); + let count = hash.remove(&reverse).unwrap_or(0); + match count { + x if x > 1 => { + result += 1; + hash.insert(reverse, count - 1); + } + + 1 => result += 1, + 0 => { + hash.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + _ => unreachable!(), + } + } + + result + } +} From 70063275c6324bfa0d8e703bd56f5c5c84ba5273 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 17 Jan 2024 19:48:19 +0800 Subject: [PATCH 1201/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c20aee38..e94218a9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 645 | 280 | 337 | 28 | +| 646 | 281 | 337 | 28 | ### 题目 @@ -516,6 +516,7 @@ |2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | |2816 | 字典序最小回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographically-smallest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographically-smallest-palindrome/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | +|2847 | 最大字符串配对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-maximum-number-of-string-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/find-maximum-number-of-string-pairs/) | Easy | |2866 | 最长奇偶子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-even-odd-subarray-with-threshold.rs) | [leetcode](https://leetcode-cn.com/problems/longest-even-odd-subarray-with-threshold/) | Easy | |2881 | 按分隔符拆分字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-strings-by-separator.rs) | [leetcode](https://leetcode-cn.com/problems/split-strings-by-separator/) | Easy | |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | From 74c43ad2f5bcf8b3ac492f756f93cc634c79439b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Jan 2024 19:58:48 +0800 Subject: [PATCH 1202/1556] src/bin/removing-minimum-number-of-magic-beans.rs --- .../removing-minimum-number-of-magic-beans.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/bin/removing-minimum-number-of-magic-beans.rs diff --git a/src/bin/removing-minimum-number-of-magic-beans.rs b/src/bin/removing-minimum-number-of-magic-beans.rs new file mode 100644 index 00000000..37e12c90 --- /dev/null +++ b/src/bin/removing-minimum-number-of-magic-beans.rs @@ -0,0 +1,18 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_removal(beans: Vec) -> i64 { + let mut beans = beans; + beans.sort_unstable(); + let sum: i64 = beans.iter().map(|x| *x as i64).sum(); + let mut r = i64::MAX; + for i in 0..beans.len() { + r = r.min(sum - (beans.len() - i) as i64 * (beans[i] as i64)) + } + r + } +} From b30e94ce7937f307af29a12476f25a5b7003d0ff Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Jan 2024 19:58:49 +0800 Subject: [PATCH 1203/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e94218a9..5fc41d83 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 646 | 281 | 337 | 28 | +| 647 | 281 | 338 | 28 | ### 题目 @@ -451,6 +451,7 @@ |2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | |2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | +|2290 | 拿出最少数目的魔法豆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-minimum-number-of-magic-beans.rs) | [leetcode](https://leetcode-cn.com/problems/removing-minimum-number-of-magic-beans/) | Medium | |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | |2300 | 构造限制重复的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-string-with-repeat-limit.rs) | [leetcode](https://leetcode-cn.com/problems/construct-string-with-repeat-limit/) | Medium | |2310 | 将数组和减半的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-halve-array-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-halve-array-sum/) | Medium | From 8347a57bc976586a19edc2f57ae1b288615ed693 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 19 Jan 2024 20:27:23 +0800 Subject: [PATCH 1204/1556] src/bin/add-without-plus-lcci.rs --- src/bin/add-without-plus-lcci.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/bin/add-without-plus-lcci.rs diff --git a/src/bin/add-without-plus-lcci.rs b/src/bin/add-without-plus-lcci.rs new file mode 100644 index 00000000..ea98068c --- /dev/null +++ b/src/bin/add-without-plus-lcci.rs @@ -0,0 +1,16 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn add(mut a: i32, mut b: i32) -> i32 { + while b != 0 { + let mut carry = (a & b) << 1 as u32; + a ^= b; + b = carry; + } + a + } +} From e328fbbecc75a62914c9b7fbc4624c67c007e89a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 19 Jan 2024 20:27:24 +0800 Subject: [PATCH 1205/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5fc41d83..7098da26 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 647 | 281 | 338 | 28 | +| 648 | 282 | 338 | 28 | ### 题目 @@ -608,6 +608,7 @@ |100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | |1000021 | 最小K个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-k-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-k-lcci/) | Medium | |1000022 | 最长单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-word-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/longest-word-lcci/) | Medium | +|1000025 | 不用加号的加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-without-plus-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/add-without-plus-lcci/) | Easy | |1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | |1000228 | 整数除法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xoh6Oh.rs) | [leetcode](https://leetcode-cn.com/problems/xoh6Oh/) | Easy | From 0486f3ea00e02373fc860de3392e5857d5e02036 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 21 Jan 2024 22:18:59 +0800 Subject: [PATCH 1206/1556] src/bin/path-sum-iii.rs --- src/bin/path-sum-iii.rs | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/bin/path-sum-iii.rs diff --git a/src/bin/path-sum-iii.rs b/src/bin/path-sum-iii.rs new file mode 100644 index 00000000..16f58d4f --- /dev/null +++ b/src/bin/path-sum-iii.rs @@ -0,0 +1,70 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +impl Solution { + pub fn path_sum(root: Option>>, target_sum: i32) -> i32 { + if root.is_none() { + return 0; + } + let mut result = 0; + + let mut stack = vec![root]; + while let Some(x) = stack.pop() { + let left = x.clone().unwrap().borrow().left.clone(); + if left.is_some() { + stack.push(left); + } + + let right = x.clone().unwrap().borrow().right.clone(); + if right.is_some() { + stack.push(right); + } + + Self::dfs(x, target_sum as i64, 0, &mut result); + } + + result + } + + fn dfs(root: Option>>, target_sum: i64, current: i64, result: &mut i32) { + if root.is_none() { + return; + } + + let v = root.clone().unwrap().borrow().val as i64; + if v + current == target_sum { + *result += 1; + } + + let left = root.clone().unwrap().borrow().left.clone(); + let right = root.clone().unwrap().borrow().right.clone(); + + Self::dfs(left, target_sum, current + v, result); + Self::dfs(right, target_sum, current + v, result); + } +} From fee86401e7043a70b38d473fb1a52c91a6eb3943 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 21 Jan 2024 22:19:00 +0800 Subject: [PATCH 1207/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7098da26..b65d7f8e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 648 | 282 | 338 | 28 | +| 649 | 282 | 339 | 28 | ### 题目 @@ -236,6 +236,7 @@ |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | |434 | 字符串中的单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-segments-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-segments-in-a-string/) | Easy | +|437 | 路径总和 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/path-sum-iii.rs) | [leetcode](https://leetcode-cn.com/problems/path-sum-iii/) | Medium | |438 | 找到字符串中所有字母异位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-anagrams-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-anagrams-in-a-string/) | Medium | |442 | 数组中重复的数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-duplicates-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-duplicates-in-an-array/) | Medium | |445 | 两数相加 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-two-numbers-ii.rs) | [leetcode](https://leetcode-cn.com/problems/add-two-numbers-ii/) | Medium | From ad1a6809533d67be07f765b3a7e7c69814109f27 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 22 Jan 2024 20:07:34 +0800 Subject: [PATCH 1208/1556] src/bin/maximum-swap.rs --- src/bin/maximum-swap.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/maximum-swap.rs diff --git a/src/bin/maximum-swap.rs b/src/bin/maximum-swap.rs new file mode 100644 index 00000000..1e94b6e7 --- /dev/null +++ b/src/bin/maximum-swap.rs @@ -0,0 +1,31 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_swap(num: i32) -> i32 { + let mut s: Vec = num.to_string().as_bytes().into_iter().map(|x| *x).collect(); + let n = s.len(); + let mut max_idx = n - 1; + let mut p = n; + let mut q = 0; + for i in (0..n - 1).rev() { + if s[i] > s[max_idx] { + // s[i] 是目前最大数字 + max_idx = i; + } else if s[i] < s[max_idx] { + // s[i] 右边有比它大的 + p = i; + q = max_idx; // 更新 p 和 q + } + } + if p == n { + // 这意味着 s 是降序的 + return num; + } + s.swap(p, q); // 交换 s[p] 和 s[q] + unsafe { String::from_utf8_unchecked(s) }.parse().unwrap() + } +} From 242799995c8b148fd021ce7dc347275d8cd4fea2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 22 Jan 2024 20:07:34 +0800 Subject: [PATCH 1209/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b65d7f8e..5bc78e7f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 649 | 282 | 339 | 28 | +| 650 | 282 | 340 | 28 | ### 题目 @@ -284,6 +284,7 @@ |653 | 两数之和 IV - 输入 BST | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-iv-input-is-a-bst.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-iv-input-is-a-bst/) | Easy | |657 | 机器人能否返回原点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-return-to-origin.rs) | [leetcode](https://leetcode-cn.com/problems/robot-return-to-origin/) | Easy | |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | +|670 | 最大交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-swap.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-swap/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | |718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | |722 | 删除注释 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-comments.rs) | [leetcode](https://leetcode-cn.com/problems/remove-comments/) | Medium | From 123465d2b8963c01ee0351242b31e946e0b0c2bb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 23 Jan 2024 09:01:02 +0800 Subject: [PATCH 1210/1556] src/bin/longest-alternating-subarray.rs --- src/bin/longest-alternating-subarray.rs | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bin/longest-alternating-subarray.rs diff --git a/src/bin/longest-alternating-subarray.rs b/src/bin/longest-alternating-subarray.rs new file mode 100644 index 00000000..eb92e7cd --- /dev/null +++ b/src/bin/longest-alternating-subarray.rs @@ -0,0 +1,37 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::alternating_subarray(vec![2, 3, 4, 3, 4]), 4); +} + +struct Solution; + +impl Solution { + pub fn alternating_subarray(nums: Vec) -> i32 { + let mut result = 1; + let mut r = 0; + let mut one = 1; // 1为1 + for i in 1..nums.len() { + if nums[i] - nums[i - 1] == one { + result += 1; + one *= -1; + } else { + if nums[i] - nums[i - 1] == 1 { + result = 2; + one = -1; + } else { + result = 1; + one = 1; + } + } + + r = r.max(result); + } + + if r == 0 || r == 1 { + -1 + } else { + r + } + } +} From ec4389e4c7269f9dc94e6a96b52a77f1b4271d54 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 23 Jan 2024 09:01:03 +0800 Subject: [PATCH 1211/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5bc78e7f..0c47f71c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 650 | 282 | 340 | 28 | +| 651 | 283 | 340 | 28 | ### 题目 @@ -521,6 +521,7 @@ |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |2847 | 最大字符串配对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-maximum-number-of-string-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/find-maximum-number-of-string-pairs/) | Easy | |2866 | 最长奇偶子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-even-odd-subarray-with-threshold.rs) | [leetcode](https://leetcode-cn.com/problems/longest-even-odd-subarray-with-threshold/) | Easy | +|2870 | 最长交替子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-alternating-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/longest-alternating-subarray/) | Easy | |2881 | 按分隔符拆分字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-strings-by-separator.rs) | [leetcode](https://leetcode-cn.com/problems/split-strings-by-separator/) | Easy | |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | From 1638bd82b7988a0a24326d88943815aa0e6aa827 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 24 Jan 2024 20:12:21 +0800 Subject: [PATCH 1212/1556] src/bin/minimize-xor.rs --- src/bin/minimize-xor.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/minimize-xor.rs diff --git a/src/bin/minimize-xor.rs b/src/bin/minimize-xor.rs new file mode 100644 index 00000000..8ec5a13e --- /dev/null +++ b/src/bin/minimize-xor.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimize_xor(mut num1: i32, num2: i32) -> i32 { + let mut c1 = num1.count_ones(); + let mut c2 = num2.count_ones(); + while c2 < c1 { + num1 &= num1 - 1; + c2 += 1; + } + while c2 > c1 { + num1 |= num1 + 1; + c2 -= 1 + } + num1 + } +} From b633466d0332a3cb2772792274f66e669872f459 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 24 Jan 2024 20:12:22 +0800 Subject: [PATCH 1213/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c47f71c..3e2c2b9f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 651 | 283 | 340 | 28 | +| 652 | 283 | 341 | 28 | ### 题目 @@ -470,6 +470,7 @@ |2473 | 数位和相等数对的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs) | [leetcode](https://leetcode-cn.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | |2482 | 被列覆盖的最多行数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-rows-covered-by-columns.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-rows-covered-by-columns/) | Medium | |2493 | 反转二叉树的奇数层 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-odd-levels-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-odd-levels-of-binary-tree/) | Medium | +|2509 | 最小异或 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimize-xor.rs) | [leetcode](https://leetcode-cn.com/problems/minimize-xor/) | Medium | |2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | |2519 | 找出前缀异或的原始数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-original-array-of-prefix-xor.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-original-array-of-prefix-xor/) | Medium | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | From 296bc162c00e14fd63b43c8c94cd50d12b52889c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 25 Jan 2024 19:50:43 +0800 Subject: [PATCH 1214/1556] src/bin/sum-of-values-at-indices-with-k-set-bits.rs --- ...um-of-values-at-indices-with-k-set-bits.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/sum-of-values-at-indices-with-k-set-bits.rs diff --git a/src/bin/sum-of-values-at-indices-with-k-set-bits.rs b/src/bin/sum-of-values-at-indices-with-k-set-bits.rs new file mode 100644 index 00000000..94dc044f --- /dev/null +++ b/src/bin/sum-of-values-at-indices-with-k-set-bits.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!( + Solution::sum_indices_with_k_set_bits(vec![5, 10, 1, 5, 2], 1), + 13 + ); +} + +struct Solution; + +impl Solution { + pub fn sum_indices_with_k_set_bits(nums: Vec, k: i32) -> i32 { + nums.into_iter() + .enumerate() + .filter(|(x, _)| x.count_ones() as i32 == k) + .map(|(_, x)| x) + .sum() + } +} From f48ff81f402d02260a56d26e32dc0a90ee45ed2f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 25 Jan 2024 19:50:44 +0800 Subject: [PATCH 1215/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e2c2b9f..6d8b939d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 652 | 283 | 341 | 28 | +| 653 | 284 | 341 | 28 | ### 题目 @@ -527,6 +527,7 @@ |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | |3045 | 使数组成为递增数组的最少右移次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-right-shifts-to-sort-the-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-right-shifts-to-sort-the-array/) | Easy | +|3093 | 计算 K 置位下标对应元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-values-at-indices-with-k-set-bits.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-values-at-indices-with-k-set-bits/) | Easy | |3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | |3152 | 有序三元组中的最大值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-an-ordered-triplet-ii.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-an-ordered-triplet-ii/) | Medium | |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | From 1286b65078388660d1594d85352221b7a264e9db Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 26 Jan 2024 19:41:54 +0800 Subject: [PATCH 1216/1556] src/bin/Ju9Xwi.rs --- src/bin/Ju9Xwi.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/Ju9Xwi.rs diff --git a/src/bin/Ju9Xwi.rs b/src/bin/Ju9Xwi.rs new file mode 100644 index 00000000..f2d5e403 --- /dev/null +++ b/src/bin/Ju9Xwi.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn least_minutes(n: i32) -> i32 { + if n <= 1 { + return 1; + } + + let mut x = 1; + let mut r = 0; + for i in 1.. { + x *= 2; + r = i as i32; + if x >= n { + break; + } + } + + r + 1 + } +} From 9f8698a5e1edf6899b0a16d51fe66306574c6029 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 26 Jan 2024 19:41:55 +0800 Subject: [PATCH 1217/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d8b939d..1126327a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 653 | 284 | 341 | 28 | +| 654 | 285 | 341 | 28 | ### 题目 @@ -616,6 +616,7 @@ |1000025 | 不用加号的加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-without-plus-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/add-without-plus-lcci/) | Easy | |1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | +|1000225 | 下载插件 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/Ju9Xwi.rs) | [leetcode](https://leetcode-cn.com/problems/Ju9Xwi/) | Easy | |1000228 | 整数除法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xoh6Oh.rs) | [leetcode](https://leetcode-cn.com/problems/xoh6Oh/) | Easy | |1000230 | 前 n 个数字二进制中 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/w3tCBm.rs) | [leetcode](https://leetcode-cn.com/problems/w3tCBm/) | Easy | |1000231 | 二进制加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/JFETK5.rs) | [leetcode](https://leetcode-cn.com/problems/JFETK5/) | Easy | From 992650b4581376916c2e66623ca1e958eec34044 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 27 Jan 2024 14:10:20 +0800 Subject: [PATCH 1218/1556] src/bin/maximum-number-of-alloys.rs --- src/bin/maximum-number-of-alloys.rs | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/bin/maximum-number-of-alloys.rs diff --git a/src/bin/maximum-number-of-alloys.rs b/src/bin/maximum-number-of-alloys.rs new file mode 100644 index 00000000..c460daf4 --- /dev/null +++ b/src/bin/maximum-number-of-alloys.rs @@ -0,0 +1,53 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_number_of_alloys( + n: i32, + k: i32, + budget: i32, + composition: Vec>, + stock: Vec, + cost: Vec, + ) -> i32 { + (0..k as usize) + .map(|i| { + // 已有的能制造多少 + let mut x = (0..n as usize) + .map(|x| stock[x] / composition[i][x]) + .min() + .unwrap(); + + let mut total_cost = 0; // 购买的总消费 + loop { + let mut p = 0; + + for m in 0..n as usize as usize { + // 表示剩下已有的不够造了,因此需要去买 + if stock[m] - x * composition[i][m] <= 0 { + p += composition[i][m] * cost[m]; + } else { + if stock[m] - x * composition[i][m] < composition[i][m] { + p += (composition[i][m] - stock[m] + x * composition[i][m]) + * cost[m]; + } + } + } + + if p + total_cost <= budget { + x += 1; + total_cost += p; + } else { + break; + } + } + + x + }) + .max() + .unwrap() + } +} From 99b4440e55999bdfdff030fc1c8e0a7935126bb1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 27 Jan 2024 14:10:20 +0800 Subject: [PATCH 1219/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1126327a..e19cbef3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 654 | 285 | 341 | 28 | +| 655 | 285 | 342 | 28 | ### 题目 @@ -529,6 +529,7 @@ |3045 | 使数组成为递增数组的最少右移次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-right-shifts-to-sort-the-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-right-shifts-to-sort-the-array/) | Easy | |3093 | 计算 K 置位下标对应元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-values-at-indices-with-k-set-bits.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-values-at-indices-with-k-set-bits/) | Easy | |3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | +|3095 | 最大合金数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-alloys.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-alloys/) | Medium | |3152 | 有序三元组中的最大值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-an-ordered-triplet-ii.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-an-ordered-triplet-ii/) | Medium | |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | From 20611c3d591a5ed3cdbff86a1b7de6e54490668a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 28 Jan 2024 13:35:07 +0800 Subject: [PATCH 1220/1556] src/bin/water-and-jug-problem.rs --- src/bin/water-and-jug-problem.rs | 91 ++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/bin/water-and-jug-problem.rs diff --git a/src/bin/water-and-jug-problem.rs b/src/bin/water-and-jug-problem.rs new file mode 100644 index 00000000..984e72ee --- /dev/null +++ b/src/bin/water-and-jug-problem.rs @@ -0,0 +1,91 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn can_measure_water(jug1_capacity: i32, jug2_capacity: i32, target_capacity: i32) -> bool { + let mut set = std::collections::HashSet::<(i32, i32)>::new(); + + Self::dfs( + jug1_capacity, + jug2_capacity, + target_capacity, + 0, + 0, + &mut set, + ) + } + + fn dfs( + jug1_capacity: i32, + jug2_capacity: i32, + target_capacity: i32, + current_1: i32, + current_2: i32, + set: &mut std::collections::HashSet<(i32, i32)>, + ) -> bool { + if set.contains(&(current_1, current_2)) { + return false; + } + set.insert((current_1, current_2)); + + if current_1 == target_capacity + || current_2 == target_capacity + || current_1 + current_2 == target_capacity + { + return true; + } + + // 1清空 + // 2清空 + // 1装满 + // 2装满 + // 1到给2 + // 2到给1 + Self::dfs( + jug1_capacity, + jug2_capacity, + target_capacity, + 0, + current_2, + set, + ) || Self::dfs( + jug1_capacity, + jug2_capacity, + target_capacity, + current_1, + 0, + set, + ) || Self::dfs( + jug1_capacity, + jug2_capacity, + target_capacity, + jug1_capacity, + current_2, + set, + ) || Self::dfs( + jug1_capacity, + jug2_capacity, + target_capacity, + current_1, + jug2_capacity, + set, + ) || Self::dfs( + jug1_capacity, + jug2_capacity, + target_capacity, + current_1 - (jug2_capacity - current_2).max(0).min(current_1), + current_2 + (jug2_capacity - current_2).max(0).min(current_1), + set, + ) || Self::dfs( + jug1_capacity, + jug2_capacity, + target_capacity, + current_1 + (jug1_capacity - current_1).max(0).min(jug2_capacity), + jug2_capacity - (jug1_capacity - current_1).max(0).min(jug2_capacity), + set, + ) + } +} From b26f64082b79a2d006a46f1dbcabe809ab0feaa3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 28 Jan 2024 13:35:07 +0800 Subject: [PATCH 1221/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e19cbef3..fb686196 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 655 | 285 | 342 | 28 | +| 656 | 285 | 343 | 28 | ### 题目 @@ -207,6 +207,7 @@ |350 | 两个数组的交集 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/intersection-of-two-arrays-ii.rs) | [leetcode](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/) | Easy | |355 | 设计推特 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-twitter.rs) | [leetcode](https://leetcode-cn.com/problems/design-twitter/) | Medium | |357 | 统计各位数字都不同的数字个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-numbers-with-unique-digits.rs) | [leetcode](https://leetcode-cn.com/problems/count-numbers-with-unique-digits/) | Medium | +|365 | 水壶问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-and-jug-problem.rs) | [leetcode](https://leetcode-cn.com/problems/water-and-jug-problem/) | Medium | |367 | 有效的完全平方数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/valid-perfect-square.rs) | [leetcode](https://leetcode-cn.com/problems/valid-perfect-square/) | Easy | |371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | From 12c4efe64cccec31d8d813cef63510e2ceb9fb02 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 29 Jan 2024 20:31:23 +0800 Subject: [PATCH 1222/1556] src/bin/check-if-all-as-appears-before-all-bs.rs --- .../check-if-all-as-appears-before-all-bs.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/check-if-all-as-appears-before-all-bs.rs diff --git a/src/bin/check-if-all-as-appears-before-all-bs.rs b/src/bin/check-if-all-as-appears-before-all-bs.rs new file mode 100644 index 00000000..a8ec3f91 --- /dev/null +++ b/src/bin/check-if-all-as-appears-before-all-bs.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn check_string(s: String) -> bool { + let mut has_b = false; + for &i in s.as_bytes() { + if i == b'b' { + has_b = true; + } else if i == b'a' && has_b { + return false; + } + } + + true + } +} From 45ba1aaa9aded6ed8f5da9a06cac5bcfc3058ef6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 29 Jan 2024 20:31:24 +0800 Subject: [PATCH 1223/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fb686196..22778635 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 656 | 285 | 343 | 28 | +| 657 | 286 | 343 | 28 | ### 题目 @@ -452,6 +452,7 @@ |2233 | 股票平滑下跌阶段的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-smooth-descent-periods-of-a-stock.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-smooth-descent-periods-of-a-stock/) | Medium | |2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | |2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | +|2243 | 检查是否所有 A 都在 B 之前 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-all-as-appears-before-all-bs.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-all-as-appears-before-all-bs/) | Easy | |2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | |2290 | 拿出最少数目的魔法豆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-minimum-number-of-magic-beans.rs) | [leetcode](https://leetcode-cn.com/problems/removing-minimum-number-of-magic-beans/) | Medium | From cb836551c173133d9db881b35746c9eed37b76b3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 30 Jan 2024 20:07:02 +0800 Subject: [PATCH 1224/1556] src/bin/minimum-seconds-to-equalize-a-circular-array.rs --- ...um-seconds-to-equalize-a-circular-array.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/minimum-seconds-to-equalize-a-circular-array.rs diff --git a/src/bin/minimum-seconds-to-equalize-a-circular-array.rs b/src/bin/minimum-seconds-to-equalize-a-circular-array.rs new file mode 100644 index 00000000..9334ca49 --- /dev/null +++ b/src/bin/minimum-seconds-to-equalize-a-circular-array.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_seconds(nums: Vec) -> i32 { + let n = nums.len(); + let mut hash = std::collections::HashMap::>::new(); + for (index, value) in nums.into_iter().enumerate() { + hash.entry(value) + .and_modify(|x| x.push(index)) + .or_insert(vec![index]); + } + + let mut result = n; + for (k, v) in hash { + let mut mx = v[0] + n - *v.last().unwrap(); + for i in 1..v.len() { + mx = mx.max(v[i] - v[i - 1]); + } + + result = result.min(mx / 2); + } + + result as i32 + } +} From 26f0c2e9c8e1b7e85e9c2a4a5b153fda019900e2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 30 Jan 2024 20:07:02 +0800 Subject: [PATCH 1225/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 22778635..de903da1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 657 | 286 | 343 | 28 | +| 658 | 286 | 344 | 28 | ### 题目 @@ -527,6 +527,7 @@ |2870 | 最长交替子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-alternating-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/longest-alternating-subarray/) | Easy | |2881 | 按分隔符拆分字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-strings-by-separator.rs) | [leetcode](https://leetcode-cn.com/problems/split-strings-by-separator/) | Easy | |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | +|2920 | 使循环数组所有元素相等的最少秒数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-seconds-to-equalize-a-circular-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-seconds-to-equalize-a-circular-array/) | Medium | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | |3045 | 使数组成为递增数组的最少右移次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-right-shifts-to-sort-the-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-right-shifts-to-sort-the-array/) | Easy | |3093 | 计算 K 置位下标对应元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-values-at-indices-with-k-set-bits.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-values-at-indices-with-k-set-bits/) | Easy | From d53f0eaf8406e65da3ac8f39d2661985dd2c502a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 31 Jan 2024 19:50:39 +0800 Subject: [PATCH 1226/1556] src/bin/find-the-distinct-difference-array.rs --- src/bin/find-the-distinct-difference-array.rs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/find-the-distinct-difference-array.rs diff --git a/src/bin/find-the-distinct-difference-array.rs b/src/bin/find-the-distinct-difference-array.rs new file mode 100644 index 00000000..74bd06b2 --- /dev/null +++ b/src/bin/find-the-distinct-difference-array.rs @@ -0,0 +1,31 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn distinct_difference_array(nums: Vec) -> Vec { + let mut count = std::collections::HashMap::new(); + for &i in nums.iter() { + count.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + + let mut result = Vec::with_capacity(nums.len()); + let mut set = std::collections::HashSet::new(); + + for i in nums { + set.insert(i); + let c = count[&i]; + if c == 1 { + count.remove(&i); + } else { + count.insert(i, c - 1); + } + + result.push((set.len() - count.len()) as i32); + } + + result + } +} From 3b56125aa2bcd320e55cca9199e580b47d195984 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 31 Jan 2024 19:50:40 +0800 Subject: [PATCH 1227/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index de903da1..65fd6492 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 658 | 286 | 344 | 28 | +| 659 | 287 | 344 | 28 | ### 题目 @@ -515,6 +515,7 @@ |2755 | 字符串中的额外字符 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/extra-characters-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/extra-characters-in-a-string/) | Medium | |2756 | 购买两块巧克力 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/buy-two-chocolates.rs) | [leetcode](https://leetcode-cn.com/problems/buy-two-chocolates/) | Easy | |2767 | K 个元素的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-with-exactly-k-elements.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-with-exactly-k-elements/) | Easy | +|2777 | 找出不同元素数目差数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-distinct-difference-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-distinct-difference-array/) | Easy | |2787 | 移动机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/movement-of-robots.rs) | [leetcode](https://leetcode-cn.com/problems/movement-of-robots/) | Medium | |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | |2800 | 删除子串后的字符串最小长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-string-length-after-removing-substrings.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-string-length-after-removing-substrings/) | Easy | From e6fd0971dc5eea567b04d81f026a117266a1e4d0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 1 Feb 2024 20:46:26 +0800 Subject: [PATCH 1228/1556] src/bin/maximum-difference-between-node-and-ancestor.rs --- ...um-difference-between-node-and-ancestor.rs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/bin/maximum-difference-between-node-and-ancestor.rs diff --git a/src/bin/maximum-difference-between-node-and-ancestor.rs b/src/bin/maximum-difference-between-node-and-ancestor.rs new file mode 100644 index 00000000..a581b7eb --- /dev/null +++ b/src/bin/maximum-difference-between-node-and-ancestor.rs @@ -0,0 +1,56 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +impl Solution { + pub fn max_ancestor_diff(root: Option>>) -> i32 { + let root = root.unwrap(); + let root_val = root.borrow().val; + let left = root.borrow_mut().left.take(); + let right = root.borrow_mut().right.take(); + Self::dfs(left, root_val, root_val).max(Self::dfs(right, root_val, root_val)) + } + + pub fn dfs(root: Option>>, max_parent: i32, min_parent: i32) -> i32 { + if root.is_none() { + return 0; + } + + let root = root.unwrap(); + let v = (max_parent - root.borrow().val) + .abs() + .max((min_parent - root.borrow().val).abs()); + + let max_parent = max_parent.max(root.borrow().val); + let min_parent = min_parent.min(root.borrow().val); + + let left = root.borrow_mut().left.take(); + let right = root.borrow_mut().right.take(); + + v.max(Self::dfs(left, max_parent, min_parent).max(Self::dfs(right, max_parent, min_parent))) + } +} From 6a111e57fa154d8fef5234635b88de81a41040c8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 1 Feb 2024 20:46:26 +0800 Subject: [PATCH 1229/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 65fd6492..05f92ce5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 659 | 287 | 344 | 28 | +| 660 | 287 | 345 | 28 | ### 题目 @@ -339,6 +339,7 @@ |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | |1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | |1079 | 从根到叶的二进制数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-root-to-leaf-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-root-to-leaf-binary-numbers/) | Easy | +|1092 | 节点与其祖先之间的最大差值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-difference-between-node-and-ancestor.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-difference-between-node-and-ancestor/) | Medium | |1114 | 从二叉搜索树到更大和树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-to-greater-sum-tree.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree/) | Medium | |1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | From 62cff57d12186018fb31cae62d0bccdc6171d00c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 2 Feb 2024 21:05:02 +0800 Subject: [PATCH 1230/1556] src/bin/stone-game-vi.rs --- src/bin/stone-game-vi.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/stone-game-vi.rs diff --git a/src/bin/stone-game-vi.rs b/src/bin/stone-game-vi.rs new file mode 100644 index 00000000..34ce3778 --- /dev/null +++ b/src/bin/stone-game-vi.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn stone_game_vi(alice_values: Vec, bob_values: Vec) -> i32 { + let mut x: Vec<_> = alice_values + .into_iter() + .zip(bob_values.into_iter()) + .map(|(x, y)| (x + y, x, y)) + .collect(); + + x.sort_unstable_by(|x, y| x.cmp(y).reverse()); + + let (mut a_score, mut b_score) = (0, 0); + for i in 0..x.len() { + if i % 2 == 0 { + a_score += x[i].1; + } else { + b_score += x[i].2; + } + } + + match a_score.cmp(&b_score) { + std::cmp::Ordering::Equal => 0, + std::cmp::Ordering::Greater => 1, + std::cmp::Ordering::Less => -1, + } + } +} From aed0de5e688b687e427f4cbe55d0a1f59bf226b0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 2 Feb 2024 21:05:02 +0800 Subject: [PATCH 1231/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 05f92ce5..6275446f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 660 | 287 | 345 | 28 | +| 661 | 287 | 346 | 28 | ### 题目 @@ -416,6 +416,7 @@ |1767 | 设计前中后队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-front-middle-back-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-front-middle-back-queue/) | Medium | |1777 | 确定两个字符串是否接近 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/determine-if-two-strings-are-close.rs) | [leetcode](https://leetcode-cn.com/problems/determine-if-two-strings-are-close/) | Medium | |1782 | 具有给定数值的最小字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-string-with-a-given-numeric-value.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-string-with-a-given-numeric-value/) | Medium | +|1788 | 石子游戏 VI | [src](https://github.com/rustors/leetcode/blob/main/src/bin/stone-game-vi.rs) | [leetcode](https://leetcode-cn.com/problems/stone-game-vi/) | Medium | |1791 | 最富有客户的资产总量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/richest-customer-wealth.rs) | [leetcode](https://leetcode-cn.com/problems/richest-customer-wealth/) | Easy | |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | From 8664de2cf4eb00a668effb6fd33f0c4dccb3cd05 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 4 Feb 2024 19:51:32 +0800 Subject: [PATCH 1232/1556] src/bin/type-of-triangle-ii.rs --- src/bin/type-of-triangle-ii.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/type-of-triangle-ii.rs diff --git a/src/bin/type-of-triangle-ii.rs b/src/bin/type-of-triangle-ii.rs new file mode 100644 index 00000000..f96fc2ba --- /dev/null +++ b/src/bin/type-of-triangle-ii.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn triangle_type(nums: Vec) -> String { + let mut nums = nums; + nums.sort_unstable(); + + if nums[0] + nums[1] <= nums[2] { + return "none".into(); + } + + if nums[0] == nums[1] && nums[1] == nums[2] { + "equilateral".into() + } else if nums[0] == nums[1] || nums[1] == nums[2] { + "isosceles".into() + } else { + "scalene".into() + } + } +} From 11034ce0c646bf79185a1ff128eeeb9238cced31 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 5 Feb 2024 20:55:39 +0800 Subject: [PATCH 1233/1556] src/bin/jump-game-vi.rs --- src/bin/jump-game-vi.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bin/jump-game-vi.rs diff --git a/src/bin/jump-game-vi.rs b/src/bin/jump-game-vi.rs new file mode 100644 index 00000000..23f4c98c --- /dev/null +++ b/src/bin/jump-game-vi.rs @@ -0,0 +1,40 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::max_result(vec![1, -1, -2, 4, -7, 3], 2), 7); +} + +struct Solution; + +impl Solution { + /// 使用单调递减栈stack。栈维护单调nums单调递减的数据下标。 + /// 因为stack单调递减,因此遍历到nums[i]时,只要stack.pop()的下标满足跳k步到i,则i的最大值只为nums[i] + nums[stack.pop_front()], + /// 然后弹出stack后面比nums[i]小的元素,最后把i插入stack中即可。 + pub fn max_result(nums: Vec, k: i32) -> i32 { + use std::collections::VecDeque; + let mut stack = VecDeque::new(); + stack.push_back(0usize); + let mut nums = nums; + + for i in 1..nums.len() { + while let Some(x) = stack.pop_front() { + if x + k as usize >= i { + nums[i] += nums[x]; + stack.push_front(x); + break; + } + } + + while let Some(index) = stack.pop_back() { + if nums[index] > nums[i] { + stack.push_back(index); + break; + } + } + + stack.push_back(i); + } + + nums.pop().unwrap() + } +} From 23d2a31c947abca73f935853697088c319aacd95 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 5 Feb 2024 20:55:39 +0800 Subject: [PATCH 1234/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6275446f..94d217dc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 661 | 287 | 346 | 28 | +| 662 | 287 | 347 | 28 | ### 题目 @@ -421,6 +421,7 @@ |1797 | 设计 Goal 解析器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/goal-parser-interpretation.rs) | [leetcode](https://leetcode-cn.com/problems/goal-parser-interpretation/) | Easy | |1806 | 比赛中的配对次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-of-matches-in-tournament.rs) | [leetcode](https://leetcode-cn.com/problems/count-of-matches-in-tournament/) | Easy | |1807 | 十-二进制数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partitioning-into-minimum-number-of-deci-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/) | Medium | +|1814 | 跳跃游戏 VI | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-vi.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-vi/) | Medium | |1817 | 计算力扣银行的钱 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-money-in-leetcode-bank.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-money-in-leetcode-bank/) | Easy | |1829 | 卡车上的最大单元数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-units-on-a-truck.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-units-on-a-truck/) | Easy | |1849 | 任意子数组和的绝对值的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-absolute-sum-of-any-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | From 70381409d76043e2c199feb63a2b399217ba6fc1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 6 Feb 2024 21:12:37 +0800 Subject: [PATCH 1235/1556] src/bin/p0NxJO.rs --- src/bin/p0NxJO.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/bin/p0NxJO.rs diff --git a/src/bin/p0NxJO.rs b/src/bin/p0NxJO.rs new file mode 100644 index 00000000..1e8c241e --- /dev/null +++ b/src/bin/p0NxJO.rs @@ -0,0 +1,42 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 使用heap保存前面出现的负数,然后记录所有的血量之和,当血量为负数时,说明到此位置的生时候需要调整。 + /// 我们弹出heap中血量最小的(也就是减去血量最多的),然后放到末尾,这时血量之和应该把此血量减去的加上,如果为正数,停止调整。 + pub fn magic_tower(nums: Vec) -> i32 { + use std::cmp::Reverse; + + let mut heap = std::collections::BinaryHeap::new(); + let mut total = 1i64; // 初始血量为1 + let mut num = 0; + let mut total_sum = 0i64; + for i in nums { + total_sum += i as i64; + if i < 0 { + heap.push(Reverse(i)); + } + + total += i as i64; + + if total <= 0 { + while let Some(Reverse(x)) = heap.pop() { + num += 1; + total += -x as i64; + if total > 0 { + break; + } + } + } + } + + if total_sum >= 0 { + num + } else { + -1 + } + } +} From 6e9de7fc5dd1da0081601b9fce13c60a4ef26908 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 6 Feb 2024 21:12:38 +0800 Subject: [PATCH 1236/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 94d217dc..9ce45733 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 662 | 287 | 347 | 28 | +| 663 | 287 | 348 | 28 | ### 题目 @@ -624,6 +624,7 @@ |1000025 | 不用加号的加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-without-plus-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/add-without-plus-lcci/) | Easy | |1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | +|1000224 | 魔塔游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/p0NxJO.rs) | [leetcode](https://leetcode-cn.com/problems/p0NxJO/) | Medium | |1000225 | 下载插件 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/Ju9Xwi.rs) | [leetcode](https://leetcode-cn.com/problems/Ju9Xwi/) | Easy | |1000228 | 整数除法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xoh6Oh.rs) | [leetcode](https://leetcode-cn.com/problems/xoh6Oh/) | Easy | |1000230 | 前 n 个数字二进制中 1 的个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/w3tCBm.rs) | [leetcode](https://leetcode-cn.com/problems/w3tCBm/) | Easy | From 810864c0cbff9cb4f5dff4ef36c811e857bc3e80 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 8 Feb 2024 22:07:06 +0800 Subject: [PATCH 1237/1556] src/bin/cousins-in-binary-tree.rs --- src/bin/cousins-in-binary-tree.rs | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/bin/cousins-in-binary-tree.rs diff --git a/src/bin/cousins-in-binary-tree.rs b/src/bin/cousins-in-binary-tree.rs new file mode 100644 index 00000000..e6b9c189 --- /dev/null +++ b/src/bin/cousins-in-binary-tree.rs @@ -0,0 +1,75 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +impl Solution { + pub fn is_cousins(root: Option>>, x: i32, y: i32) -> bool { + let mut stack = vec![root]; + while !stack.is_empty() { + let mut new_stack = vec![]; + let mut exists = false; + while let Some(Some(p)) = stack.pop() { + let left = p.borrow_mut().left.take(); + let right = p.borrow_mut().right.take(); + let mut e = false; + if left.is_some() { + let v = left.as_ref().unwrap().borrow().val; + if v == x || v == y { + if exists { + return true; + } + exists = true; + e = true; + } + + new_stack.push(left); + } + + if right.is_some() { + let v = right.as_ref().unwrap().borrow().val; + if v == x || v == y { + if e { + return false; + } + + if exists { + return true; + } + + exists = true; + } + + new_stack.push(right); + } + } + + stack = new_stack; + } + + false + } +} From 78e0a914835fe0d5a05dac8695673d5586896cfb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 8 Feb 2024 22:07:08 +0800 Subject: [PATCH 1238/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ce45733..5ab6004f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 663 | 287 | 348 | 28 | +| 664 | 288 | 348 | 28 | ### 题目 @@ -334,6 +334,7 @@ |1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | |1010 | 强整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powerful-integers.rs) | [leetcode](https://leetcode-cn.com/problems/powerful-integers/) | Medium | |1021 | 在二叉树中分配硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-coins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-coins-in-binary-tree/) | Medium | +|1035 | 二叉树的堂兄弟节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cousins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/cousins-in-binary-tree/) | Easy | |1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | |1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | From 7b231309f23d2f6d4171dac6d834904c378204ab Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 12 Feb 2024 14:36:44 +0800 Subject: [PATCH 1239/1556] src/bin/short-encoding-of-words.rs --- src/bin/short-encoding-of-words.rs | 93 ++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/bin/short-encoding-of-words.rs diff --git a/src/bin/short-encoding-of-words.rs b/src/bin/short-encoding-of-words.rs new file mode 100644 index 00000000..918281de --- /dev/null +++ b/src/bin/short-encoding-of-words.rs @@ -0,0 +1,93 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::fmt::Debug; + +fn main() { + assert_eq!( + Solution::minimum_length_encoding(vec![ + "time".to_string(), + "me".to_string(), + "bell".to_string(), + ], ), + 10 + ); + + assert_eq!(Solution::minimum_length_encoding(vec!["t".to_string()]), 2); + assert_eq!( + Solution::minimum_length_encoding(vec![ + "time".to_string(), + "atime".to_string(), + "btime".to_string(), + ]), + 12 + ); + assert_eq!( + Solution::minimum_length_encoding(vec!["me".to_string(), "time".to_string()]), + 5 + ); +} + +struct Solution; + +impl Solution { + pub fn minimum_length_encoding(words: Vec) -> i32 { + let mut words = words; + words.sort_unstable_by(|x, y| x.len().cmp(&y.len()).reverse()); + let mut set = std::collections::HashSet::::new(); + + 'L: for i in words { + for j in set.iter() { + if j.ends_with(i.as_str()) { + continue 'L; + } + } + + set.insert(i); + } + + set.iter().map(|x| x.len() as i32).sum::() + set.len() as i32 + } + + /// tire tree 字典树 + // pub fn minimum_length_encoding(words: Vec) -> i32 { + // struct TireTree { + // nodes: std::collections::HashMap, + // } + // + // impl TireTree { + // fn new() -> Self { + // TireTree { + // nodes: std::collections::HashMap::new(), + // } + // } + // + // // 如果为true则表示插入了新的 + // fn insert(&mut self, word: &str) -> bool { + // if word.is_empty() { + // return false; + // } + // + // let k = word.as_bytes()[word.len() - 1]; + // + // if let Some(n) = self.nodes.get_mut(&k) { + // n.insert(&word[..word.len() - 1]) + // } else { + // let mut n = TireTree::new(); + // let x = n.insert(&word[..word.len() - 1]); + // self.nodes.insert(k, n); + // true + // } + // } + // } + // + // let mut tree = TireTree::new(); + // let mut result = 0; + // for i in words.iter() { + // if tree.insert(i.as_str()) { + // result += i.len() as i32 + 1; + // } + // } + // + // result + // } +} From cde7d4d791117798839c521750f5b2672071e1c2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 12 Feb 2024 14:36:44 +0800 Subject: [PATCH 1240/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ab6004f..5ea64cf8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 664 | 288 | 348 | 28 | +| 665 | 288 | 349 | 28 | ### 题目 @@ -300,6 +300,7 @@ |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | |834 | 模糊坐标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ambiguous-coordinates.rs) | [leetcode](https://leetcode-cn.com/problems/ambiguous-coordinates/) | Medium | +|839 | 单词的压缩编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/short-encoding-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/short-encoding-of-words/) | Medium | |842 | 翻转卡片游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/card-flipping-game.rs) | [leetcode](https://leetcode-cn.com/problems/card-flipping-game/) | Medium | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | From 01f054b38174b673af7b4f154d27c5c7b6257a9f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 13 Feb 2024 22:25:03 +0800 Subject: [PATCH 1241/1556] src/bin/sum-of-digits-in-base-k.rs --- src/bin/sum-of-digits-in-base-k.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/bin/sum-of-digits-in-base-k.rs diff --git a/src/bin/sum-of-digits-in-base-k.rs b/src/bin/sum-of-digits-in-base-k.rs new file mode 100644 index 00000000..f28fe372 --- /dev/null +++ b/src/bin/sum-of-digits-in-base-k.rs @@ -0,0 +1,19 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn sum_base(n: i32, k: i32) -> i32 { + let mut sum = 0; + let mut n = n; + + while n > 0 { + sum += n % k; + n = n / k; + } + + sum + } +} From b88c9a524d60907fe79d018f33db0ae1db5b7b8c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 13 Feb 2024 22:25:05 +0800 Subject: [PATCH 1242/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ea64cf8..2ca1cb17 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 665 | 288 | 349 | 28 | +| 666 | 289 | 349 | 28 | ### 题目 @@ -437,6 +437,7 @@ |1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | |1952 | 最少侧跳次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sideway-jumps.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sideway-jumps/) | Medium | |1960 | 判断句子是否为全字母句 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-the-sentence-is-pangram.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-the-sentence-is-pangram/) | Easy | +|1965 | K 进制表示下的各位数字总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-digits-in-base-k.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-digits-in-base-k/) | Easy | |1971 | 增长的内存泄露 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/incremental-memory-leak.rs) | [leetcode](https://leetcode-cn.com/problems/incremental-memory-leak/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | |2011 | 插入后的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-after-insertion.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-after-insertion/) | Medium | From db88b715783da475236b82cf762fc758e25e0c52 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 14 Feb 2024 23:57:13 +0800 Subject: [PATCH 1243/1556] src/bin/finding-3-digit-even-numbers.rs --- src/bin/finding-3-digit-even-numbers.rs | 62 +++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/bin/finding-3-digit-even-numbers.rs diff --git a/src/bin/finding-3-digit-even-numbers.rs b/src/bin/finding-3-digit-even-numbers.rs new file mode 100644 index 00000000..6fec6c62 --- /dev/null +++ b/src/bin/finding-3-digit-even-numbers.rs @@ -0,0 +1,62 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 枚举100-999的数据 + pub fn find_even_numbers(digits: Vec) -> Vec { + let mut hash = std::collections::HashMap::new(); + + for i in digits { + hash.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + let mut result = vec![]; + for j in 100..=999 { + if j % 2 == 1 { + continue; + } + + let x = j / 100; + let y = j / 10 % 10; + let z = j % 10; + + if x != y && y != z && x != z { + if hash.contains_key(&x) && hash.contains_key(&y) && hash.contains_key(&z) { + result.push(j); + } + } else if x == y && y != z { + match (hash.get(&x), hash.get(&z)) { + (Some(m), Some(_)) if *m >= 2 => { + result.push(j); + } + _ => {} + } + } else if x == z && z != y { + match (hash.get(&x), hash.get(&y)) { + (Some(m), Some(_)) if *m >= 2 => { + result.push(j); + } + _ => {} + } + } else if y == z && z != x { + match (hash.get(&z), hash.get(&x)) { + (Some(m), Some(_)) if *m >= 2 => { + result.push(j); + } + _ => {} + } + } else { + match hash.get(&x) { + Some(m) if *m >= 3 => { + result.push(j); + } + _ => {} + } + } + } + + result + } +} From e218a1e0cbb3fdca8e56e14ac8e3b06d6749a12d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 14 Feb 2024 23:57:14 +0800 Subject: [PATCH 1244/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ca1cb17..24323639 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 666 | 289 | 349 | 28 | +| 667 | 290 | 349 | 28 | ### 题目 @@ -454,6 +454,7 @@ |2177 | 检查两个字符串是否几乎相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-whether-two-strings-are-almost-equivalent.rs) | [leetcode](https://leetcode-cn.com/problems/check-whether-two-strings-are-almost-equivalent/) | Easy | |2190 | 统计出现过一次的公共字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-common-words-with-one-occurrence.rs) | [leetcode](https://leetcode-cn.com/problems/count-common-words-with-one-occurrence/) | Easy | |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | +|2215 | 找出 3 位偶数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/finding-3-digit-even-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/finding-3-digit-even-numbers/) | Easy | |2226 | 环和杆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rings-and-rods.rs) | [leetcode](https://leetcode-cn.com/problems/rings-and-rods/) | Easy | |2233 | 股票平滑下跌阶段的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-smooth-descent-periods-of-a-stock.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-smooth-descent-periods-of-a-stock/) | Medium | |2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | From a5c77df45c4880ca95df2ede8f461e97e37c7799 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 15 Feb 2024 11:00:56 +0800 Subject: [PATCH 1245/1556] src/bin/g5c51o.rs --- src/bin/g5c51o.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/g5c51o.rs diff --git a/src/bin/g5c51o.rs b/src/bin/g5c51o.rs new file mode 100644 index 00000000..7d2b2503 --- /dev/null +++ b/src/bin/g5c51o.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn top_k_frequent(nums: Vec, k: i32) -> Vec { + use std::cmp::Reverse; + + let mut hash = std::collections::HashMap::new(); + for i in nums { + hash.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + + hash.into_iter() + .map(|(x, y)| (Reverse(y), x)) + .collect::>() + .into_iter() + .take(k as usize) + .map(|x| x.1) + .collect() + } +} From 48573880884a5c5fa4f37091e990ac06ddc2f77b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 15 Feb 2024 11:00:56 +0800 Subject: [PATCH 1246/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 24323639..95db6630 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 667 | 290 | 349 | 28 | +| 668 | 290 | 350 | 28 | ### 题目 @@ -672,6 +672,7 @@ |1000311 | 展平二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/NYBBNL.rs) | [leetcode](https://leetcode-cn.com/problems/NYBBNL/) | Easy | |1000319 | 二叉搜索树中两个节点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/opLdQZ.rs) | [leetcode](https://leetcode-cn.com/problems/opLdQZ/) | Easy | |1000321 | 值和下标之差都在给定的范围内 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WqeDu.rs) | [leetcode](https://leetcode-cn.com/problems/7WqeDu/) | Medium | +|1000324 | 前 K 个高频元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/g5c51o.rs) | [leetcode](https://leetcode-cn.com/problems/g5c51o/) | Medium | |1000333 | 山峰数组的顶部 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/B1IidL.rs) | [leetcode](https://leetcode-cn.com/problems/B1IidL/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | |1000433 | 宝石补给 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WHnhjV.rs) | [leetcode](https://leetcode-cn.com/problems/WHnhjV/) | Easy | From f2fb30fab0af5c3d80c914cb598621b01d527d21 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 17 Feb 2024 14:04:26 +0800 Subject: [PATCH 1247/1556] src/bin/surface-area-of-3d-shapes.rs --- src/bin/surface-area-of-3d-shapes.rs | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/bin/surface-area-of-3d-shapes.rs diff --git a/src/bin/surface-area-of-3d-shapes.rs b/src/bin/surface-area-of-3d-shapes.rs new file mode 100644 index 00000000..a2f894eb --- /dev/null +++ b/src/bin/surface-area-of-3d-shapes.rs @@ -0,0 +1,53 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn surface_area(grid: Vec>) -> i32 { + let mut result = 0; + + for i in 0..grid.len() { + for j in 0..grid[0].len() { + if grid[i][j] != 0 { + result += 2; + } + + if i == 0 { + result += grid[i][j]; + } else { + if grid[i - 1][j] < grid[i][j] { + result += grid[i][j] - grid[i - 1][j]; + } + } + + if i == grid.len() - 1 { + result += grid[i][j]; + } else { + if grid[i + 1][j] < grid[i][j] { + result += grid[i][j] - grid[i + 1][j] + } + } + + if j == 0 { + result += grid[i][j]; + } else { + if grid[i][j - 1] < grid[i][j] { + result += grid[i][j] - grid[i][j - 1]; + } + } + + if j == grid[0].len() - 1 { + result += grid[i][j]; + } else { + if grid[i][j + 1] < grid[i][j] { + result += grid[i][j] - grid[i][j + 1]; + } + } + } + } + + result + } +} From b84ad80dcf022967a5e499db235de694da48cf6d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 17 Feb 2024 14:04:27 +0800 Subject: [PATCH 1248/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 95db6630..9edde437 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 668 | 290 | 350 | 28 | +| 669 | 291 | 350 | 28 | ### 题目 @@ -317,6 +317,7 @@ |921 | 螺旋矩阵 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/spiral-matrix-iii.rs) | [leetcode](https://leetcode-cn.com/problems/spiral-matrix-iii/) | Medium | |924 | 公平的糖果交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | |925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | +|928 | 三维形体的表面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/surface-area-of-3d-shapes.rs) | [leetcode](https://leetcode-cn.com/problems/surface-area-of-3d-shapes/) | Easy | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | |937 | 股票价格跨度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-stock-span.rs) | [leetcode](https://leetcode-cn.com/problems/online-stock-span/) | Medium | From 8e35904267fc7b6bd413a7b2add83b07f2169614 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 18 Feb 2024 21:16:22 +0800 Subject: [PATCH 1249/1556] src/bin/linked-list-components.rs --- src/bin/linked-list-components.rs | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/bin/linked-list-components.rs diff --git a/src/bin/linked-list-components.rs b/src/bin/linked-list-components.rs new file mode 100644 index 00000000..c254da68 --- /dev/null +++ b/src/bin/linked-list-components.rs @@ -0,0 +1,43 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} + +impl Solution { + pub fn num_components(head: Option>, nums: Vec) -> i32 { + let set = nums.into_iter().collect::>(); + let mut head = head; + let mut result = 0; + let mut flag = false; + while head.is_some() { + let v = head.as_ref().unwrap().val; + if set.contains(&v) { + if !flag { + result += 1; + flag = true; + } + } else { + flag = false; + } + + head = head.as_mut().unwrap().next.take(); + } + + result + } +} From 3fdf09f7950a734422dc02ffbc7b2ef6d9f6296b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 18 Feb 2024 21:16:22 +0800 Subject: [PATCH 1250/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9edde437..7ff520b8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 669 | 291 | 350 | 28 | +| 670 | 291 | 351 | 28 | ### 题目 @@ -300,6 +300,7 @@ |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | |834 | 模糊坐标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ambiguous-coordinates.rs) | [leetcode](https://leetcode-cn.com/problems/ambiguous-coordinates/) | Medium | +|835 | 链表组件 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/linked-list-components.rs) | [leetcode](https://leetcode-cn.com/problems/linked-list-components/) | Medium | |839 | 单词的压缩编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/short-encoding-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/short-encoding-of-words/) | Medium | |842 | 翻转卡片游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/card-flipping-game.rs) | [leetcode](https://leetcode-cn.com/problems/card-flipping-game/) | Medium | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | From 653b59bc671d1130dd69a133a1e35d8773d393f3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 19 Feb 2024 21:15:35 +0800 Subject: [PATCH 1251/1556] src/bin/third-maximum-number.rs --- src/bin/third-maximum-number.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/third-maximum-number.rs diff --git a/src/bin/third-maximum-number.rs b/src/bin/third-maximum-number.rs new file mode 100644 index 00000000..df5c0a13 --- /dev/null +++ b/src/bin/third-maximum-number.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn third_max(nums: Vec) -> i32 { + let (mut a, mut b, mut c) = (None, None, None); + for i in nums { + if a.is_none() || Some(i) > a { + c = b; + b = a; + a = Some(i); + } else if (b.is_none() || Some(i) > b) && Some(i) != a { + c = b; + b = Some(i); + } else if (c.is_none() || Some(i) > c) && Some(i) != b && Some(i) != a { + c = Some(i); + } + } + + c.unwrap_or(a.unwrap()) + } +} From 5e4ce0d595fb7b884f11196f594bf123738daff3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 19 Feb 2024 21:15:36 +0800 Subject: [PATCH 1252/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ff520b8..cbafcaf6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 670 | 291 | 351 | 28 | +| 671 | 292 | 351 | 28 | ### 题目 @@ -233,6 +233,7 @@ |409 | 最长回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindrome/) | Easy | |412 | Fizz Buzz | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fizz-buzz.rs) | [leetcode](https://leetcode-cn.com/problems/fizz-buzz/) | Easy | |413 | 等差数列划分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/arithmetic-slices.rs) | [leetcode](https://leetcode-cn.com/problems/arithmetic-slices/) | Medium | +|414 | 第三大的数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/third-maximum-number.rs) | [leetcode](https://leetcode-cn.com/problems/third-maximum-number/) | Easy | |415 | 字符串相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-strings.rs) | [leetcode](https://leetcode-cn.com/problems/add-strings/) | Easy | |419 | 甲板上的战舰 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/battleships-in-a-board.rs) | [leetcode](https://leetcode-cn.com/problems/battleships-in-a-board/) | Medium | |423 | 从英文中重建数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-original-digits-from-english.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-original-digits-from-english/) | Medium | From c76f745b3c91c11f9f4fe40df27be3142ba5a8cb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 20 Feb 2024 20:47:23 +0800 Subject: [PATCH 1253/1556] src/bin/rotting-oranges.rs --- src/bin/rotting-oranges.rs | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/bin/rotting-oranges.rs diff --git a/src/bin/rotting-oranges.rs b/src/bin/rotting-oranges.rs new file mode 100644 index 00000000..9c65cd97 --- /dev/null +++ b/src/bin/rotting-oranges.rs @@ -0,0 +1,64 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn oranges_rotting(grid: Vec>) -> i32 { + let mut hash = std::collections::HashSet::new(); + let mut stack = vec![]; + for i in 0..grid.len() { + for j in 0..grid[0].len() { + match grid[i][j] { + 1 => { + hash.insert((i, j)); + } + 2 => stack.push((i, j)), + _ => {} + } + } + } + + let mut result = 0; + while !stack.is_empty() { + let mut new_stack = vec![]; + let len = hash.len(); + while let Some((x, y)) = stack.pop() { + if x > 0 { + if hash.contains(&(x - 1, y)) { + new_stack.push((x - 1, y)); + hash.remove(&(x - 1, y)); + } + } + + if y > 0 { + if hash.contains(&(x, y - 1)) { + new_stack.push((x, y - 1)); + hash.remove(&(x, y - 1)); + } + } + + if hash.contains(&(x + 1, y)) { + new_stack.push((x + 1, y)); + hash.remove(&(x + 1, y)); + } + + if hash.contains(&(x, y + 1)) { + new_stack.push((x, y + 1)); + hash.remove(&(x, y + 1)); + } + } + if hash.len() != len { + result += 1; + } + stack = new_stack; + } + + if hash.is_empty() { + result + } else { + -1 + } + } +} From 1ae0285dcb0f9af5c8f3a76c0d864f4d9ccc30a5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 20 Feb 2024 20:47:23 +0800 Subject: [PATCH 1254/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cbafcaf6..600248e4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 671 | 292 | 351 | 28 | +| 672 | 292 | 352 | 28 | ### 题目 @@ -339,6 +339,7 @@ |1010 | 强整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powerful-integers.rs) | [leetcode](https://leetcode-cn.com/problems/powerful-integers/) | Medium | |1021 | 在二叉树中分配硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-coins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-coins-in-binary-tree/) | Medium | |1035 | 二叉树的堂兄弟节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cousins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/cousins-in-binary-tree/) | Easy | +|1036 | 腐烂的橘子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotting-oranges.rs) | [leetcode](https://leetcode-cn.com/problems/rotting-oranges/) | Medium | |1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | |1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | From feef65806be53efb3e416db7f4f56ec966ce03a0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 21 Feb 2024 21:09:39 +0800 Subject: [PATCH 1255/1556] src/bin/OrIXps.rs --- src/bin/OrIXps.rs | 134 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/bin/OrIXps.rs diff --git a/src/bin/OrIXps.rs b/src/bin/OrIXps.rs new file mode 100644 index 00000000..ae2a4985 --- /dev/null +++ b/src/bin/OrIXps.rs @@ -0,0 +1,134 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + let mut lru = LRUCache::new(2); + lru.put(1, 1); + // println!("{:?}", lru.list); + + lru.put(2, 2); + // println!("{:?}", lru.list); + assert_eq!(lru.get(1), 1); + // println!("{:?}", lru.list); + lru.put(3, 3); + assert_eq!(lru.get(2), -1); + lru.put(4, 4); + assert_eq!(lru.get(1), -1); + assert_eq!(lru.get(3), 3); + assert_eq!(lru.get(4), 4); +} + +struct Solution; + +#[derive(Debug)] +struct LinkedList { + head: Option>>, + tail: Option>>, +} + +impl LinkedList { + fn new() -> Self { + Self { + head: None, + tail: None, + } + } + + fn take(&mut self, node: std::rc::Rc>) { + let pre = node.borrow_mut().pre.take(); + let next = node.borrow_mut().next.take(); + + pre.clone().map(|x| x.borrow_mut().next = next.clone()); + next.clone().map(|x| x.borrow_mut().pre = pre.clone()); + + if next.is_none() { + self.tail = pre.clone(); + } + + if pre.is_none() { + self.head = next.clone(); + } + } + + fn push(&mut self, node: std::rc::Rc>) { + let head = self.head.take(); + node.borrow_mut().next = head.clone(); + + head.map(|x| x.borrow_mut().pre = Some(node.clone())); + self.head = Some(node.clone()); + + if self.tail.is_none() { + self.tail = self.head.clone(); + } + } +} + +#[derive(Debug)] +struct Node { + key: i32, + val: i32, + pre: Option>>, + next: Option>>, +} + +struct LRUCache { + capacity: usize, + map: std::collections::HashMap>>, + list: LinkedList, +} + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ + +/** + * Your LRUCache object will be instantiated and called as such: + * let obj = LRUCache::new(capacity); + * let ret_1: i32 = obj.get(key); + * obj.put(key, value); + */ + +impl LRUCache { + fn new(capacity: i32) -> Self { + Self { + capacity: capacity as usize, + map: std::collections::HashMap::new(), + list: LinkedList::new(), + } + } + + fn get(&mut self, key: i32) -> i32 { + if let Some(x) = self.map.get(&key) { + self.list.take(x.clone()); + self.list.push(x.clone()); + x.borrow().val + } else { + -1 + } + } + + fn put(&mut self, key: i32, value: i32) { + if let Some(x) = self.map.get(&key) { + self.list.take(x.clone()); + self.list.push(x.clone()); + x.borrow_mut().val = value; + } else { + // remove a value + if self.map.len() == self.capacity { + let tail = self.list.tail.clone().unwrap(); + self.list.take(tail.clone()); + self.map.remove(&tail.borrow().key); + } + + let node = std::rc::Rc::new(std::cell::RefCell::new(Node { + key, + val: value, + pre: None, + next: None, + })); + + self.list.push(node.clone()); + self.map.insert(key, node); + } + } +} From 68c84f3f78bb5abe879f970f0119f80280559bb8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 21 Feb 2024 21:09:40 +0800 Subject: [PATCH 1256/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 600248e4..a1243908 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 672 | 292 | 352 | 28 | +| 673 | 292 | 353 | 28 | ### 题目 @@ -656,6 +656,7 @@ |1000261 | 链表中的两数相加 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lMSNwu.rs) | [leetcode](https://leetcode-cn.com/problems/lMSNwu/) | Medium | |1000262 | 重排链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/LGjMqU.rs) | [leetcode](https://leetcode-cn.com/problems/LGjMqU/) | Medium | |1000263 | 回文链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/aMhZSa.rs) | [leetcode](https://leetcode-cn.com/problems/aMhZSa/) | Easy | +|1000270 | LRU 缓存 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/OrIXps.rs) | [leetcode](https://leetcode-cn.com/problems/OrIXps/) | Medium | |1000273 | 有效的变位词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/dKk3P7.rs) | [leetcode](https://leetcode-cn.com/problems/dKk3P7/) | Easy | |1000275 | 变位词组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sfvd7V.rs) | [leetcode](https://leetcode-cn.com/problems/sfvd7V/) | Medium | |1000276 | 外星语言是否排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lwyVBB.rs) | [leetcode](https://leetcode-cn.com/problems/lwyVBB/) | Easy | From dd85785c0df70aae7ae08b3c9ddfbd885f245f95 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 23 Feb 2024 20:26:40 +0800 Subject: [PATCH 1257/1556] src/bin/kth-largest-sum-in-a-binary-tree.rs --- src/bin/kth-largest-sum-in-a-binary-tree.rs | 63 +++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/bin/kth-largest-sum-in-a-binary-tree.rs diff --git a/src/bin/kth-largest-sum-in-a-binary-tree.rs b/src/bin/kth-largest-sum-in-a-binary-tree.rs new file mode 100644 index 00000000..f2b9e8f2 --- /dev/null +++ b/src/bin/kth-largest-sum-in-a-binary-tree.rs @@ -0,0 +1,63 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +impl Solution { + pub fn kth_largest_level_sum(root: Option>>, k: i32) -> i64 { + if root.is_none() { + return -1; + } + + let mut results = vec![]; + let mut stack = vec![root]; + + while !stack.is_empty() { + let mut sum = 0; + let mut new_stack = vec![]; + while let Some(x) = stack.pop() { + let r = x.unwrap(); + sum += r.borrow().val as i64; + let left = r.borrow_mut().left.take(); + if left.is_some() { + new_stack.push(left); + } + + let right = r.borrow_mut().right.take(); + if right.is_some() { + new_stack.push(right); + } + } + + results.push(std::cmp::Reverse(sum)); + stack = new_stack; + } + + results.sort_unstable(); + + results.get(k as usize - 1).map(|x| x.0).unwrap_or(-1) + } +} From e8eba3fe8fb45f094f17c6850bfe1c9f677bac23 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 23 Feb 2024 20:26:43 +0800 Subject: [PATCH 1258/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a1243908..11befe60 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 673 | 292 | 353 | 28 | +| 674 | 292 | 354 | 28 | ### 题目 @@ -501,6 +501,7 @@ |2619 | 根据规则将箱子分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/categorize-box-according-to-criteria.rs) | [leetcode](https://leetcode-cn.com/problems/categorize-box-according-to-criteria/) | Easy | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2645 | 递枕头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pass-the-pillow.rs) | [leetcode](https://leetcode-cn.com/problems/pass-the-pillow/) | Easy | +|2646 | 二叉树中的第 K 大层和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-sum-in-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-sum-in-a-binary-tree/) | Medium | |2650 | 最小和分割 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-with-minimum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/split-with-minimum-sum/) | Easy | |2654 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-the-number-of-vowel-strings-in-range.rs) | [leetcode](https://leetcode-cn.com/problems/count-the-number-of-vowel-strings-in-range/) | Easy | |2662 | 检查骑士巡视方案 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-knight-tour-configuration.rs) | [leetcode](https://leetcode-cn.com/problems/check-knight-tour-configuration/) | Medium | From 873e6938898d548834ab0dc9b4fa67ad4807fc2f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 24 Feb 2024 13:08:23 +0800 Subject: [PATCH 1259/1556] src/bin/closest-nodes-queries-in-a-binary-search-tree.rs --- ...t-nodes-queries-in-a-binary-search-tree.rs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/bin/closest-nodes-queries-in-a-binary-search-tree.rs diff --git a/src/bin/closest-nodes-queries-in-a-binary-search-tree.rs b/src/bin/closest-nodes-queries-in-a-binary-search-tree.rs new file mode 100644 index 00000000..3d209ca7 --- /dev/null +++ b/src/bin/closest-nodes-queries-in-a-binary-search-tree.rs @@ -0,0 +1,60 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +fn main() {} + +struct Solution; + +impl Solution { + pub fn closest_nodes(root: Option>>, queries: Vec) -> Vec> { + let mut items = vec![]; + Self::dfs(root, &mut items); + + let mut result = vec![]; + for q in queries { + let j = items.partition_point(|x| *x < q); + let mx = if j < items.len() { items[j] } else { -1 }; + let mn = if j < items.len() && items[j] == q { + q + } else if j > 0 { + items[j - 1] + } else { + -1 + }; + result.push(vec![mn, mx]); + } + + result + } + + fn dfs(root: Option>>, items: &mut Vec) { + if root.is_none() { + return; + } + let root = root.unwrap(); + Self::dfs(root.borrow_mut().left.take(), items); + items.push(root.borrow().val); + Self::dfs(root.borrow_mut().right.take(), items); + } +} From c6cdaa07e70a2a3015c4ff14acf6273d4c6ddd49 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 24 Feb 2024 13:08:23 +0800 Subject: [PATCH 1260/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 11befe60..771236e0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 674 | 292 | 354 | 28 | +| 675 | 292 | 355 | 28 | ### 题目 @@ -488,6 +488,7 @@ |2519 | 找出前缀异或的原始数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-original-array-of-prefix-xor.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-original-array-of-prefix-xor/) | Medium | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | +|2567 | 二叉搜索树最近节点查询 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/closest-nodes-queries-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/closest-nodes-queries-in-a-binary-search-tree/) | Medium | |2571 | 找出中枢整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-pivot-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-pivot-integer/) | Easy | |2573 | 从链表中移除节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-nodes-from-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-nodes-from-linked-list/) | Medium | |2575 | 分割圆的最少切割次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cuts-to-divide-a-circle.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cuts-to-divide-a-circle/) | Easy | From 673604ed6f3ed977fce8fa82300cffef82b60230 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Feb 2024 13:44:00 +0800 Subject: [PATCH 1261/1556] src/bin/maximum-ascending-subarray-sum.rs --- src/bin/maximum-ascending-subarray-sum.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/bin/maximum-ascending-subarray-sum.rs diff --git a/src/bin/maximum-ascending-subarray-sum.rs b/src/bin/maximum-ascending-subarray-sum.rs new file mode 100644 index 00000000..5b50c914 --- /dev/null +++ b/src/bin/maximum-ascending-subarray-sum.rs @@ -0,0 +1,22 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_ascending_sum(nums: Vec) -> i32 { + let mut result = nums[0]; + let mut n = nums[0]; + for i in 1..nums.len() { + if nums[i] > nums[i - 1] { + n += nums[i]; + } else { + n = nums[i]; + } + result = result.max(n); + } + + result + } +} From 0d9c6e6a1f6e9f30d9dc057d25735764ef2cad46 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 25 Feb 2024 13:44:01 +0800 Subject: [PATCH 1262/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 771236e0..beb51d0f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 675 | 292 | 355 | 28 | +| 676 | 293 | 355 | 28 | ### 题目 @@ -436,6 +436,7 @@ |1894 | 交替合并字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-strings-alternately.rs) | [leetcode](https://leetcode-cn.com/problems/merge-strings-alternately/) | Easy | |1899 | 统计匹配检索规则的物品数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-items-matching-a-rule.rs) | [leetcode](https://leetcode-cn.com/problems/count-items-matching-a-rule/) | Easy | |1905 | 设计一个验证系统 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-authentication-manager.rs) | [leetcode](https://leetcode-cn.com/problems/design-authentication-manager/) | Medium | +|1927 | 最大升序子数组和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-ascending-subarray-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-ascending-subarray-sum/) | Easy | |1929 | 有界数组中指定下标处的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-at-a-given-index-in-a-bounded-array.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-at-a-given-index-in-a-bounded-array/) | Medium | |1938 | 最少操作使数组递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-make-the-array-increasing.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-make-the-array-increasing/) | Easy | |1940 | 每个查询的最大异或值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-xor-for-each-query.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-xor-for-each-query/) | Medium | From 6dae6da83738bbe32a0dab59cd860ca67829535f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 26 Feb 2024 21:30:16 +0800 Subject: [PATCH 1263/1556] src/bin/range-sum-of-bst.rs --- src/bin/range-sum-of-bst.rs | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/bin/range-sum-of-bst.rs diff --git a/src/bin/range-sum-of-bst.rs b/src/bin/range-sum-of-bst.rs new file mode 100644 index 00000000..6491145f --- /dev/null +++ b/src/bin/range-sum-of-bst.rs @@ -0,0 +1,51 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +impl Solution { + pub fn range_sum_bst(root: Option>>, low: i32, high: i32) -> i32 { + let mut result = 0; + + fn dfs(root: Option>>, result: &mut i32, low: i32, high: i32) { + if root.is_none() { + return; + } + + let root = root.unwrap(); + dfs(root.borrow_mut().left.take(), result, low, high); + dfs(root.borrow_mut().right.take(), result, low, high); + + if root.borrow().val <= high && root.borrow().val >= low { + *result += root.borrow().val; + } + } + + dfs(root, &mut result, low, high); + + result + } +} From 0fdde5267ed69b4e84ecfa21345a9551e30ebbdb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 26 Feb 2024 21:30:17 +0800 Subject: [PATCH 1264/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index beb51d0f..550e002c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 676 | 293 | 355 | 28 | +| 677 | 294 | 355 | 28 | ### 题目 @@ -328,6 +328,7 @@ |953 | 仅仅反转字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-only-letters.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-only-letters/) | Easy | |954 | 环形子数组的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-circular-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-circular-subarray/) | Medium | |967 | 下降路径最小和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-falling-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-falling-path-sum/) | Medium | +|975 | 二叉搜索树的范围和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-of-bst.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-of-bst/) | Easy | |977 | 不同的子序列 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distinct-subsequences-ii.rs) | [leetcode](https://leetcode-cn.com/problems/distinct-subsequences-ii/) | Hard | |979 | 增减字符串匹配 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/di-string-match.rs) | [leetcode](https://leetcode-cn.com/problems/di-string-match/) | Easy | |981 | 删列造序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-columns-to-make-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/delete-columns-to-make-sorted/) | Easy | From f852031d3174e7863c4dfd807b4e6bed73b192c5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 26 Feb 2024 21:30:59 +0800 Subject: [PATCH 1265/1556] aaa --- src/bin/short-encoding-of-words.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/short-encoding-of-words.rs b/src/bin/short-encoding-of-words.rs index 918281de..15af2392 100644 --- a/src/bin/short-encoding-of-words.rs +++ b/src/bin/short-encoding-of-words.rs @@ -8,7 +8,7 @@ fn main() { "time".to_string(), "me".to_string(), "bell".to_string(), - ], ), + ],), 10 ); @@ -48,7 +48,7 @@ impl Solution { set.iter().map(|x| x.len() as i32).sum::() + set.len() as i32 } - /// tire tree 字典树 + // tire tree 字典树 // pub fn minimum_length_encoding(words: Vec) -> i32 { // struct TireTree { // nodes: std::collections::HashMap, From 92637d3c5e91aa6f8ead0e36678c0d7ad8080eec Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 27 Feb 2024 20:56:53 +0800 Subject: [PATCH 1266/1556] src/bin/minimum-sum-of-mountain-triplets-i.rs --- src/bin/minimum-sum-of-mountain-triplets-i.rs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/bin/minimum-sum-of-mountain-triplets-i.rs diff --git a/src/bin/minimum-sum-of-mountain-triplets-i.rs b/src/bin/minimum-sum-of-mountain-triplets-i.rs new file mode 100644 index 00000000..2e5f0926 --- /dev/null +++ b/src/bin/minimum-sum-of-mountain-triplets-i.rs @@ -0,0 +1,43 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::minimum_sum(vec![8, 6, 1, 5, 3]), 9); + assert_eq!(Solution::minimum_sum(vec![5, 4, 8, 7, 10, 2]), 13); + assert_eq!(Solution::minimum_sum(vec![6, 5, 4, 3, 4, 5]), -1); +} + +struct Solution; + +impl Solution { + pub fn minimum_sum(nums: Vec) -> i32 { + let (mut m1, mut m2) = (vec![0; nums.len()], vec![0; nums.len()]); + for i in 0..nums.len() { + if i == 0 { + m1[i] = nums[i]; + } else { + m1[i] = m1[i - 1].min(nums[i]); + } + } + + for i in (0..nums.len()).rev() { + if i == nums.len() - 1 { + m2[i] = nums[i]; + } else { + m2[i] = m2[i + 1].min(nums[i]); + } + } + + let mut result = i32::MAX; + for i in 1..nums.len() - 1 { + if m1[i - 1] < nums[i] && nums[i] > m2[i + 1] { + result = result.min(m1[i - 1] + m2[i + 1] + nums[i]) + } + } + + if result == i32::MAX { + -1 + } else { + result + } + } +} From 2efca450d655d1fb0e90403f58bac4485c538861 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 27 Feb 2024 20:56:53 +0800 Subject: [PATCH 1267/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 550e002c..9113f6ce 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 677 | 294 | 355 | 28 | +| 678 | 295 | 355 | 28 | ### 题目 @@ -550,6 +550,7 @@ |3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | |3095 | 最大合金数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-alloys.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-alloys/) | Medium | |3152 | 有序三元组中的最大值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-an-ordered-triplet-ii.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-an-ordered-triplet-ii/) | Medium | +|3176 | 元素和最小的山形三元组 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sum-of-mountain-triplets-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sum-of-mountain-triplets-i/) | Easy | |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | From fc14e17282f5254c09af062eb6b24de3085bc970 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 28 Feb 2024 21:33:18 +0800 Subject: [PATCH 1268/1556] src/bin/make-costs-of-paths-equal-in-a-binary-tree.rs --- ...e-costs-of-paths-equal-in-a-binary-tree.rs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/make-costs-of-paths-equal-in-a-binary-tree.rs diff --git a/src/bin/make-costs-of-paths-equal-in-a-binary-tree.rs b/src/bin/make-costs-of-paths-equal-in-a-binary-tree.rs new file mode 100644 index 00000000..b8c7beb0 --- /dev/null +++ b/src/bin/make-costs-of-paths-equal-in-a-binary-tree.rs @@ -0,0 +1,31 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::min_increments(7, vec![1, 5, 2, 2, 3, 3, 1]), 6); + assert_eq!(Solution::min_increments(3, vec![5, 3, 3]), 0); + assert_eq!( + Solution::min_increments( + 15, + vec![ + 764, 1460, 2664, 764, 2725, 4556, 5305, 8829, 5064, 5929, 7660, 6321, 4830, 7055, + 3761, + ], + ), + 15735 + ); +} + +struct Solution; + +impl Solution { + pub fn min_increments(n: i32, cost: Vec) -> i32 { + let mut cost = cost; + let mut ans = 0; + for i in (1..=n as usize / 2).rev() { + // 从最后一个非叶节点开始算 + ans += (cost[i * 2 - 1] - cost[i * 2]).abs(); // 两个子节点变成一样的 + cost[i - 1] += cost[i * 2 - 1].max(cost[i * 2]); // 累加路径和 + } + ans + } +} From 25394d10c163545bec8be076887b6d042ae2af37 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 28 Feb 2024 21:33:19 +0800 Subject: [PATCH 1269/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9113f6ce..fd73f1ce 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 678 | 295 | 355 | 28 | +| 679 | 295 | 356 | 28 | ### 题目 @@ -531,6 +531,7 @@ |2756 | 购买两块巧克力 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/buy-two-chocolates.rs) | [leetcode](https://leetcode-cn.com/problems/buy-two-chocolates/) | Easy | |2767 | K 个元素的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-with-exactly-k-elements.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-with-exactly-k-elements/) | Easy | |2777 | 找出不同元素数目差数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-distinct-difference-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-distinct-difference-array/) | Easy | +|2780 | 使二叉树所有路径值相等的最小代价 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-costs-of-paths-equal-in-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/make-costs-of-paths-equal-in-a-binary-tree/) | Medium | |2787 | 移动机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/movement-of-robots.rs) | [leetcode](https://leetcode-cn.com/problems/movement-of-robots/) | Medium | |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | |2800 | 删除子串后的字符串最小长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-string-length-after-removing-substrings.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-string-length-after-removing-substrings/) | Easy | From fd1984cdfa6e3988fd5ee0305c5ee747f301a381 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 29 Feb 2024 21:47:22 +0800 Subject: [PATCH 1270/1556] src/bin/maximum-repeating-substring.rs --- src/bin/maximum-repeating-substring.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/bin/maximum-repeating-substring.rs diff --git a/src/bin/maximum-repeating-substring.rs b/src/bin/maximum-repeating-substring.rs new file mode 100644 index 00000000..3746e87b --- /dev/null +++ b/src/bin/maximum-repeating-substring.rs @@ -0,0 +1,26 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_repeating(sequence: String, word: String) -> i32 { + let mut result = 0; + for i in 0..sequence.len() { + result = result.max(Self::d(&sequence[i..], &word)); + } + + result + } + + fn d(mut sequences: &str, word: &str) -> i32 { + let mut result = 0; + while sequences.len() >= word.len() && sequences.starts_with(word) { + result += 1; + sequences = &sequences[word.len()..]; + } + + result + } +} From cef062aa4c4aa7fc77e0d076ad893389b22ca770 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 29 Feb 2024 21:47:22 +0800 Subject: [PATCH 1271/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fd73f1ce..525aad26 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 679 | 295 | 356 | 28 | +| 680 | 296 | 356 | 28 | ### 题目 @@ -420,6 +420,7 @@ |1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | |1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | |1677 | 矩阵对角线元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/matrix-diagonal-sum.rs) | [leetcode](https://leetcode-cn.com/problems/matrix-diagonal-sum/) | Easy | +|1764 | 最大重复子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-repeating-substring.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-repeating-substring/) | Easy | |1767 | 设计前中后队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-front-middle-back-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-front-middle-back-queue/) | Medium | |1777 | 确定两个字符串是否接近 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/determine-if-two-strings-are-close.rs) | [leetcode](https://leetcode-cn.com/problems/determine-if-two-strings-are-close/) | Medium | |1782 | 具有给定数值的最小字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-string-with-a-given-numeric-value.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-string-with-a-given-numeric-value/) | Medium | From f8808ffb3a4307d464593fc38191b6c0de8cf79b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 3 Mar 2024 23:11:01 +0800 Subject: [PATCH 1272/1556] src/bin/minimum-time-visiting-all-points.rs --- src/bin/minimum-time-visiting-all-points.rs | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/minimum-time-visiting-all-points.rs diff --git a/src/bin/minimum-time-visiting-all-points.rs b/src/bin/minimum-time-visiting-all-points.rs new file mode 100644 index 00000000..2eaf1966 --- /dev/null +++ b/src/bin/minimum-time-visiting-all-points.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!( + Solution::min_time_to_visit_all_points(vec![vec![1, 1], vec![3, 4], vec![-1, 0]]), + 7 + ); + + assert_eq!( + Solution::min_time_to_visit_all_points(vec![vec![3, 2], vec![-2, 2]]), + 5 + ); +} + +struct Solution; + +impl Solution { + pub fn min_time_to_visit_all_points(points: Vec>) -> i32 { + (1..points.len()) + .map(|x| Self::distance(&points[x - 1], &points[x])) + .sum() + } + + /// 实际就是x[0]-y[0]与x[1]-y[1]的最大值 + fn distance(x: &[i32], y: &[i32]) -> i32 { + (x[0] - y[0]).abs().max((x[1] - y[1]).abs()) + } +} From 738f547ede8410eccedd0a5bd8d69208d0068f04 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 3 Mar 2024 23:11:02 +0800 Subject: [PATCH 1273/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 525aad26..3ba1bf35 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 680 | 296 | 356 | 28 | +| 681 | 297 | 356 | 28 | ### 题目 @@ -381,6 +381,7 @@ |1380 | 统计封闭岛屿的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-closed-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-closed-islands/) | Medium | |1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | |1394 | 网格中的最小路径代价 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-path-cost-in-a-grid.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-path-cost-in-a-grid/) | Medium | +|1395 | 访问所有点的最小时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-time-visiting-all-points.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-time-visiting-all-points/) | Easy | |1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | |1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | |1401 | 不浪费原料的汉堡制作方案 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-burgers-with-no-waste-of-ingredients.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-burgers-with-no-waste-of-ingredients/) | Medium | From e20cdbc5f4827a3c87253dd82f267812cff7cd87 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 4 Mar 2024 20:29:58 +0800 Subject: [PATCH 1274/1556] src/bin/find-xor-beauty-of-array.rs --- src/bin/find-xor-beauty-of-array.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/bin/find-xor-beauty-of-array.rs diff --git a/src/bin/find-xor-beauty-of-array.rs b/src/bin/find-xor-beauty-of-array.rs new file mode 100644 index 00000000..b4dcfae8 --- /dev/null +++ b/src/bin/find-xor-beauty-of-array.rs @@ -0,0 +1,11 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn xor_beauty(nums: Vec) -> i32 { + nums.into_iter().fold(0, |x, y| x ^ y) + } +} From 7c06d2368cdda578cbddb0bcbae7bb228baf51f0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 4 Mar 2024 20:29:58 +0800 Subject: [PATCH 1275/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ba1bf35..2554a220 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 681 | 297 | 356 | 28 | +| 682 | 297 | 357 | 28 | ### 题目 @@ -504,6 +504,7 @@ |2608 | 统计能整除数字的位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-the-digits-that-divide-a-number.rs) | [leetcode](https://leetcode-cn.com/problems/count-the-digits-that-divide-a-number/) | Easy | |2616 | 执行 K 次操作后的最大分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-score-after-applying-k-operations.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-score-after-applying-k-operations/) | Medium | |2619 | 根据规则将箱子分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/categorize-box-according-to-criteria.rs) | [leetcode](https://leetcode-cn.com/problems/categorize-box-according-to-criteria/) | Easy | +|2621 | 查询数组异或美丽值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-xor-beauty-of-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-xor-beauty-of-array/) | Medium | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2645 | 递枕头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pass-the-pillow.rs) | [leetcode](https://leetcode-cn.com/problems/pass-the-pillow/) | Easy | |2646 | 二叉树中的第 K 大层和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-sum-in-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-sum-in-a-binary-tree/) | Medium | From 769f376397977745e56895b678f4188bf8475878 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 5 Mar 2024 21:05:47 +0800 Subject: [PATCH 1276/1556] src/bin/number-of-arithmetic-triplets.rs --- src/bin/number-of-arithmetic-triplets.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/number-of-arithmetic-triplets.rs diff --git a/src/bin/number-of-arithmetic-triplets.rs b/src/bin/number-of-arithmetic-triplets.rs new file mode 100644 index 00000000..4821fbf0 --- /dev/null +++ b/src/bin/number-of-arithmetic-triplets.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn arithmetic_triplets(nums: Vec, diff: i32) -> i32 { + let mut map: std::collections::HashSet = nums.iter().map(|x| *x).collect(); + let mut result = 0; + + for i in 0..nums.len() { + if map.contains(&(nums[i] + diff)) && map.contains(&(nums[i] + diff + diff)) { + result += 1; + } + } + + result + } +} From 085d3fd6727f07cca16ce07e77cdb4c8b5dc238c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 5 Mar 2024 21:05:47 +0800 Subject: [PATCH 1277/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2554a220..e0686dc3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 682 | 297 | 357 | 28 | +| 683 | 298 | 357 | 28 | ### 题目 @@ -483,6 +483,7 @@ |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | |2413 | 无限集中的最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-number-in-infinite-set.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-number-in-infinite-set/) | Medium | |2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | +|2442 | 算术三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-arithmetic-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-arithmetic-triplets/) | Easy | |2470 | 从字符串中移除星号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-stars-from-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/removing-stars-from-a-string/) | Medium | |2473 | 数位和相等数对的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs) | [leetcode](https://leetcode-cn.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | |2482 | 被列覆盖的最多行数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-rows-covered-by-columns.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-rows-covered-by-columns/) | Medium | From 745bc37070de8c8731d470075f75a8fe8e4d18ff Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 6 Mar 2024 20:14:42 +0800 Subject: [PATCH 1278/1556] src/bin/find-the-k-or-of-an-array.rs --- src/bin/find-the-k-or-of-an-array.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/find-the-k-or-of-an-array.rs diff --git a/src/bin/find-the-k-or-of-an-array.rs b/src/bin/find-the-k-or-of-an-array.rs new file mode 100644 index 00000000..2dec3674 --- /dev/null +++ b/src/bin/find-the-k-or-of-an-array.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_k_or(nums: Vec, k: i32) -> i32 { + let mut result = 0; + + for mut i in 0..32 { + if nums + .iter() + .map(|x| *x) + .filter(|x| (x >> i) & 1 == 1) + .count() + >= k as usize + { + result += 2i32.pow(i as _); + } + } + + result + } +} From 05393c67a0e222d189945721b34356328d9766ef Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 6 Mar 2024 20:14:43 +0800 Subject: [PATCH 1279/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e0686dc3..1d83a7ed 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 683 | 298 | 357 | 28 | +| 684 | 299 | 357 | 28 | ### 题目 @@ -556,6 +556,7 @@ |3095 | 最大合金数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-alloys.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-alloys/) | Medium | |3152 | 有序三元组中的最大值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-an-ordered-triplet-ii.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-an-ordered-triplet-ii/) | Medium | |3176 | 元素和最小的山形三元组 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sum-of-mountain-triplets-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sum-of-mountain-triplets-i/) | Easy | +|3183 | 找出数组中的 K-or 值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-k-or-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-k-or-of-an-array/) | Easy | |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | From 5e95ba63815118e373f140324eeebf730a71a9ee Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 7 Mar 2024 20:21:03 +0800 Subject: [PATCH 1280/1556] src/bin/find-the-divisibility-array-of-a-string.rs --- ...find-the-divisibility-array-of-a-string.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/find-the-divisibility-array-of-a-string.rs diff --git a/src/bin/find-the-divisibility-array-of-a-string.rs b/src/bin/find-the-divisibility-array-of-a-string.rs new file mode 100644 index 00000000..1ce6f945 --- /dev/null +++ b/src/bin/find-the-divisibility-array-of-a-string.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn divisibility_array(word: String, m: i32) -> Vec { + let mut result = vec![0; word.len()]; + let m = m as i64; + let mut s = 0i64; + for (i, j) in word.bytes().enumerate() { + s = (s * 10 + (j - b'0') as i64) % m; + if s == 0 { + result[i] = 1; + } + } + + result + } +} From 9e7899c9d85b9e5c81dbce870af7068e1f17b54e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 7 Mar 2024 20:21:03 +0800 Subject: [PATCH 1281/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d83a7ed..06f0b19a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 684 | 299 | 357 | 28 | +| 685 | 299 | 358 | 28 | ### 题目 @@ -524,6 +524,7 @@ |2692 | 从数量最多的堆取走礼物 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/take-gifts-from-the-richest-pile.rs) | [leetcode](https://leetcode-cn.com/problems/take-gifts-from-the-richest-pile/) | Easy | |2694 | 找出可整除性得分最大的整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-divisibility-score.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-divisibility-score/) | Easy | |2698 | 找出数组的串联值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-array-concatenation-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-array-concatenation-value/) | Easy | +|2713 | 找出字符串的可整除数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-divisibility-array-of-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-divisibility-array-of-a-string/) | Medium | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | |2723 | 最长平衡子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-longest-balanced-substring-of-a-binary-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-longest-balanced-substring-of-a-binary-string/) | Easy | |2727 | 老人的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-senior-citizens.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-senior-citizens/) | Easy | From 8627234d425ae51ff6331e71af9812e4421c4fe7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 8 Mar 2024 21:12:40 +0800 Subject: [PATCH 1282/1556] src/bin/find-the-minimum-possible-sum-of-a-beautiful-array.rs --- ...he-minimum-possible-sum-of-a-beautiful-array.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/bin/find-the-minimum-possible-sum-of-a-beautiful-array.rs diff --git a/src/bin/find-the-minimum-possible-sum-of-a-beautiful-array.rs b/src/bin/find-the-minimum-possible-sum-of-a-beautiful-array.rs new file mode 100644 index 00000000..d6ef9ba0 --- /dev/null +++ b/src/bin/find-the-minimum-possible-sum-of-a-beautiful-array.rs @@ -0,0 +1,14 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_possible_sum(n: i32, target: i32) -> i32 { + let n = n as i64; + let k = target as i64; + let m = n.min(k / 2); + ((m * (m + 1) + (n - m - 1 + k * 2) * (n - m)) / 2 % 1_000_000_007) as i32 + } +} From 671b1d71bb17c7dde5851dad0ad79e9379a1070a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 8 Mar 2024 21:12:41 +0800 Subject: [PATCH 1283/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 06f0b19a..5a4c1595 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 685 | 299 | 358 | 28 | +| 686 | 299 | 359 | 28 | ### 题目 @@ -551,6 +551,7 @@ |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | |2920 | 使循环数组所有元素相等的最少秒数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-seconds-to-equalize-a-circular-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-seconds-to-equalize-a-circular-array/) | Medium | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | +|3026 | 找出美丽数组的最小和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-minimum-possible-sum-of-a-beautiful-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-minimum-possible-sum-of-a-beautiful-array/) | Medium | |3045 | 使数组成为递增数组的最少右移次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-right-shifts-to-sort-the-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-right-shifts-to-sort-the-array/) | Easy | |3093 | 计算 K 置位下标对应元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-values-at-indices-with-k-set-bits.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-values-at-indices-with-k-set-bits/) | Easy | |3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | From 951be752b1a900dd5f626e53e3fa9e02e193cf64 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 9 Mar 2024 21:29:35 +0800 Subject: [PATCH 1284/1556] src/bin/maximum-number-of-operations-with-the-same-score-i.rs --- ...ber-of-operations-with-the-same-score-i.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/maximum-number-of-operations-with-the-same-score-i.rs diff --git a/src/bin/maximum-number-of-operations-with-the-same-score-i.rs b/src/bin/maximum-number-of-operations-with-the-same-score-i.rs new file mode 100644 index 00000000..d3c4eb27 --- /dev/null +++ b/src/bin/maximum-number-of-operations-with-the-same-score-i.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_operations(nums: Vec) -> i32 { + let mut result = 0; + let mut n = &nums[..]; + let mut sum = None; + while n.len() >= 2 { + match sum { + None => sum = Some(n[0] + n[1]), + Some(x) if n[0] + n[1] != x => break, + _ => {} + } + result += 1; + n = &n[2..]; + } + + result + } +} From 282778ad23923594d41ecf9cf8f7440337e43f0c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 9 Mar 2024 21:29:35 +0800 Subject: [PATCH 1285/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a4c1595..5183721b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 686 | 299 | 359 | 28 | +| 687 | 300 | 359 | 28 | ### 题目 @@ -560,6 +560,7 @@ |3176 | 元素和最小的山形三元组 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sum-of-mountain-triplets-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sum-of-mountain-triplets-i/) | Easy | |3183 | 找出数组中的 K-or 值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-k-or-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-k-or-of-an-array/) | Easy | |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | +|3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | |100240 | 魔术索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magic-index-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/magic-index-lcci/) | Easy | From 63371c11be36b1f56f1da4c7f44dba064005036a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 10 Mar 2024 11:17:38 +0800 Subject: [PATCH 1286/1556] src/bin/bulls-and-cows.rs --- src/bin/bulls-and-cows.rs | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/bin/bulls-and-cows.rs diff --git a/src/bin/bulls-and-cows.rs b/src/bin/bulls-and-cows.rs new file mode 100644 index 00000000..edb515f5 --- /dev/null +++ b/src/bin/bulls-and-cows.rs @@ -0,0 +1,52 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn get_hint1(secret: String, guess: String) -> String { + let (secret, guess) = (secret.as_bytes(), guess.as_bytes()); + let mut count = std::collections::HashMap::new(); + for &i in secret { + count.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + + let (mut bulls, mut cows_1) = (0, 0); + + for i in 0..secret.len() { + if secret[i] == guess[i] { + bulls += 1; + } + + if let Some(x) = count.get_mut(&guess[i]) { + if *x > 0 { + *x -= 1; + cows_1 += 1; + } + } + } + + let cows = cows_1 - bulls; + + format!("{bulls}A{cows}B") + } + + pub fn get_hint(secret: String, guess: String) -> String { + let (mut c1, mut c2) = ([0; 10], [0; 10]); + let mut bulls = 0; + let (mut secret, mut guess) = (secret.as_bytes(), guess.as_bytes()); + for i in 0..secret.len() { + if secret[i] == guess[i] { + bulls += 1; + } else { + c1[(secret[i] - b'0') as usize] += 1; + c2[(guess[i] - b'0') as usize] += 1; + } + } + + let cows: i32 = (0..10).map(|x| c1[x].min(c2[x])).sum(); + + format!("{bulls}A{cows}B") + } +} From 1ff478caeda4bcf7ec483c4332bf45b57464e631 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 10 Mar 2024 11:17:38 +0800 Subject: [PATCH 1287/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5183721b..50c6f188 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 687 | 300 | 359 | 28 | +| 688 | 300 | 360 | 28 | ### 题目 @@ -189,6 +189,7 @@ |290 | 单词规律 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/word-pattern.rs) | [leetcode](https://leetcode-cn.com/problems/word-pattern/) | Easy | |292 | Nim 游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nim-game.rs) | [leetcode](https://leetcode-cn.com/problems/nim-game/) | Easy | |297 | 二叉树的序列化与反序列化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/serialize-and-deserialize-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree/) | Hard | +|299 | 猜数字游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulls-and-cows.rs) | [leetcode](https://leetcode-cn.com/problems/bulls-and-cows/) | Medium | |300 | 最长递增子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-increasing-subsequence/) | Medium | |303 | 区域和检索 - 数组不可变 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-immutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-immutable/) | Easy | |307 | 区域和检索 - 数组可修改 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-query-mutable.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-query-mutable/) | Medium | From 7bcac5e2f65dbb0e134bf0bdeed1fae340632afc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Mar 2024 20:40:55 +0800 Subject: [PATCH 1288/1556] src/bin/maximum-count-of-positive-integer-and-negative-integer.rs --- ...-of-positive-integer-and-negative-integer.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/bin/maximum-count-of-positive-integer-and-negative-integer.rs diff --git a/src/bin/maximum-count-of-positive-integer-and-negative-integer.rs b/src/bin/maximum-count-of-positive-integer-and-negative-integer.rs new file mode 100644 index 00000000..383b5925 --- /dev/null +++ b/src/bin/maximum-count-of-positive-integer-and-negative-integer.rs @@ -0,0 +1,17 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::maximum_count(vec![-2, -1, -1, 1, 2, 3]), 3); + assert_eq!(Solution::maximum_count(vec![-3, -2, -1, 0, 0, 1, 2]), 3); + assert_eq!(Solution::maximum_count(vec![5, 20, 66, 1314]), 4); +} + +struct Solution; + +impl Solution { + pub fn maximum_count(nums: Vec) -> i32 { + let mut index1 = nums.partition_point(|x| *x < 0); + let mut index2 = nums.partition_point(|x| *x < 1); + (index1 as i32).max((nums.len() - index2) as i32) + } +} From b8905adee32076bb0c2bc1f2d4140d1d0af3bdb5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 11 Mar 2024 20:41:01 +0800 Subject: [PATCH 1289/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 50c6f188..d1e8bf9b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 688 | 300 | 360 | 28 | +| 689 | 301 | 360 | 28 | ### 题目 @@ -504,6 +504,7 @@ |2602 | 最多可以摧毁的敌人城堡数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-enemy-forts-that-can-be-captured.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-enemy-forts-that-can-be-captured/) | Easy | |2603 | 奖励最顶尖的 K 名学生 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reward-top-k-students.rs) | [leetcode](https://leetcode-cn.com/problems/reward-top-k-students/) | Medium | |2608 | 统计能整除数字的位数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-the-digits-that-divide-a-number.rs) | [leetcode](https://leetcode-cn.com/problems/count-the-digits-that-divide-a-number/) | Easy | +|2614 | 正整数和负整数的最大计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-count-of-positive-integer-and-negative-integer.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-count-of-positive-integer-and-negative-integer/) | Easy | |2616 | 执行 K 次操作后的最大分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-score-after-applying-k-operations.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-score-after-applying-k-operations/) | Medium | |2619 | 根据规则将箱子分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/categorize-box-according-to-criteria.rs) | [leetcode](https://leetcode-cn.com/problems/categorize-box-according-to-criteria/) | Easy | |2621 | 查询数组异或美丽值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-xor-beauty-of-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-xor-beauty-of-array/) | Medium | From 196f6fb7ae805998e4054f5248ad801e2098412f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 12 Mar 2024 20:49:07 +0800 Subject: [PATCH 1290/1556] src/bin/minimum-number-of-pushes-to-type-word-i.rs --- ...minimum-number-of-pushes-to-type-word-i.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/bin/minimum-number-of-pushes-to-type-word-i.rs diff --git a/src/bin/minimum-number-of-pushes-to-type-word-i.rs b/src/bin/minimum-number-of-pushes-to-type-word-i.rs new file mode 100644 index 00000000..5a0f6d85 --- /dev/null +++ b/src/bin/minimum-number-of-pushes-to-type-word-i.rs @@ -0,0 +1,26 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::minimum_pushes("abcde".into()), 5); + assert_eq!(Solution::minimum_pushes("xycdefghij".into()), 12); + assert_eq!( + Solution::minimum_pushes("amrvxnhsewkoipjyuclgtdbfq".into()), + 52 + ); +} + +struct Solution; + +impl Solution { + pub fn minimum_pushes(word: String) -> i32 { + let mut r = 0; + let mut len = word.len(); + match len { + 0..=8 => len as i32, + 9..=16 => 8 + (len as i32 - 8) * 2, + 17..=24 => 24 + (len as i32 - 16) * 3, + 25..=26 => 48 + (len as i32 - 24) * 4, + _ => unreachable!(), + } + } +} From 6ca7840329b54152652c0b6077ad6fc9bc696378 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 12 Mar 2024 20:49:08 +0800 Subject: [PATCH 1291/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d1e8bf9b..eb8e50a0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 689 | 301 | 360 | 28 | +| 690 | 302 | 360 | 28 | ### 题目 @@ -562,6 +562,7 @@ |3176 | 元素和最小的山形三元组 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sum-of-mountain-triplets-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sum-of-mountain-triplets-i/) | Easy | |3183 | 找出数组中的 K-or 值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-k-or-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-k-or-of-an-array/) | Easy | |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | +|3275 | 输入单词需要的最少按键次数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-pushes-to-type-word-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-pushes-to-type-word-i/) | Easy | |3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | From 2096b3a351486312ad47db7c8083ef4879771dbe Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 13 Mar 2024 20:44:08 +0800 Subject: [PATCH 1292/1556] src/bin/maximum-odd-binary-number.rs --- src/bin/maximum-odd-binary-number.rs | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/maximum-odd-binary-number.rs diff --git a/src/bin/maximum-odd-binary-number.rs b/src/bin/maximum-odd-binary-number.rs new file mode 100644 index 00000000..ef41dea1 --- /dev/null +++ b/src/bin/maximum-odd-binary-number.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!( + Solution::maximum_odd_binary_number("0101".to_string()), + "1001".to_string() + ); + + assert_eq!( + Solution::maximum_odd_binary_number("010".to_string()), + "001".to_string() + ); +} + +struct Solution; + +impl Solution { + pub fn maximum_odd_binary_number(s: String) -> String { + let mut l = s.len(); + let m = s.bytes().into_iter().filter(|x| *x == b'1').count(); + let mut s = String::with_capacity(l); + for i in 0..l - 1 { + if i < m - 1 { + s.push('1'); + } else { + s.push('0'); + } + } + s.push('1'); + s + } +} From 86cfce92df46a59b2d7ea3dbd876c95518429dd5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 13 Mar 2024 20:44:09 +0800 Subject: [PATCH 1293/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eb8e50a0..d2c993c2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 690 | 302 | 360 | 28 | +| 691 | 303 | 360 | 28 | ### 题目 @@ -555,6 +555,7 @@ |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | |3026 | 找出美丽数组的最小和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-minimum-possible-sum-of-a-beautiful-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-minimum-possible-sum-of-a-beautiful-array/) | Medium | |3045 | 使数组成为递增数组的最少右移次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-right-shifts-to-sort-the-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-right-shifts-to-sort-the-array/) | Easy | +|3055 | 最大二进制奇数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-odd-binary-number.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-odd-binary-number/) | Easy | |3093 | 计算 K 置位下标对应元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-values-at-indices-with-k-set-bits.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-values-at-indices-with-k-set-bits/) | Easy | |3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | |3095 | 最大合金数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-alloys.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-alloys/) | Medium | From 0613b6ebd0941916dbe8894825f0f8512e50ebd1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 14 Mar 2024 20:26:37 +0800 Subject: [PATCH 1294/1556] src/bin/largest-element-in-an-array-after-merge-operations.rs --- ...ment-in-an-array-after-merge-operations.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/largest-element-in-an-array-after-merge-operations.rs diff --git a/src/bin/largest-element-in-an-array-after-merge-operations.rs b/src/bin/largest-element-in-an-array-after-merge-operations.rs new file mode 100644 index 00000000..6de33364 --- /dev/null +++ b/src/bin/largest-element-in-an-array-after-merge-operations.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_array_value(nums: Vec) -> i64 { + let mut result = nums[nums.len() - 1] as i64; + + for i in (0..nums.len() - 1).rev() { + result = if nums[i] as i64 <= result { + result + nums[i] as i64 + } else { + nums[i] as i64 + }; + } + + result + } +} From 35512041fb33ad337ab907ef250b12e45b1cb665 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 14 Mar 2024 20:26:38 +0800 Subject: [PATCH 1295/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d2c993c2..a4318632 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 691 | 303 | 360 | 28 | +| 692 | 303 | 361 | 28 | ### 题目 @@ -549,6 +549,7 @@ |2847 | 最大字符串配对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-maximum-number-of-string-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/find-maximum-number-of-string-pairs/) | Easy | |2866 | 最长奇偶子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-even-odd-subarray-with-threshold.rs) | [leetcode](https://leetcode-cn.com/problems/longest-even-odd-subarray-with-threshold/) | Easy | |2870 | 最长交替子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-alternating-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/longest-alternating-subarray/) | Easy | +|2872 | 合并后数组中的最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-element-in-an-array-after-merge-operations.rs) | [leetcode](https://leetcode-cn.com/problems/largest-element-in-an-array-after-merge-operations/) | Medium | |2881 | 按分隔符拆分字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-strings-by-separator.rs) | [leetcode](https://leetcode-cn.com/problems/split-strings-by-separator/) | Easy | |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | |2920 | 使循环数组所有元素相等的最少秒数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-seconds-to-equalize-a-circular-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-seconds-to-equalize-a-circular-array/) | Medium | From 7bfa371d2440a7ab6932f56184754679af2c8b80 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 15 Mar 2024 20:22:00 +0800 Subject: [PATCH 1296/1556] src/bin/simple-bank-system.rs --- src/bin/simple-bank-system.rs | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/bin/simple-bank-system.rs diff --git a/src/bin/simple-bank-system.rs b/src/bin/simple-bank-system.rs new file mode 100644 index 00000000..e82a13ab --- /dev/null +++ b/src/bin/simple-bank-system.rs @@ -0,0 +1,61 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +/** + * Your Bank object will be instantiated and called as such: + * let obj = Bank::new(balance); + * let ret_1: bool = obj.transfer(account1, account2, money); + * let ret_2: bool = obj.deposit(account, money); + * let ret_3: bool = obj.withdraw(account, money); + */ +struct Bank { + balance: Vec, +} + +impl Bank { + fn new(balance: Vec) -> Self { + Self { balance } + } + + fn transfer(&mut self, account1: i32, account2: i32, money: i64) -> bool { + if account1 as usize > self.balance.len() || account2 as usize > self.balance.len() { + return false; + } + if self.balance[account1 as usize - 1] >= money { + self.balance[account2 as usize - 1] += money; + self.balance[account1 as usize - 1] -= money; + true + } else { + false + } + } + + fn deposit(&mut self, account: i32, money: i64) -> bool { + if account as usize > self.balance.len() { + return false; + } + + self.balance[account as usize - 1] += money; + return true; + } + + fn withdraw(&mut self, account: i32, money: i64) -> bool { + if account as usize > self.balance.len() { + return false; + } + + if self.balance[account as usize - 1] >= money { + self.balance[account as usize - 1] -= money; + true + } else { + false + } + } +} From 7c0aa150caafb5d0b5c30c66e40e058099777640 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 15 Mar 2024 20:22:00 +0800 Subject: [PATCH 1297/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a4318632..19dfb56c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 692 | 303 | 361 | 28 | +| 693 | 303 | 362 | 28 | ### 题目 @@ -460,6 +460,7 @@ |2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | |2161 | 股票价格波动 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/stock-price-fluctuation.rs) | [leetcode](https://leetcode-cn.com/problems/stock-price-fluctuation/) | Medium | |2168 | 检查句子中的数字是否递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-numbers-are-ascending-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-numbers-are-ascending-in-a-sentence/) | Easy | +|2169 | 简易银行系统 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simple-bank-system.rs) | [leetcode](https://leetcode-cn.com/problems/simple-bank-system/) | Medium | |2177 | 检查两个字符串是否几乎相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-whether-two-strings-are-almost-equivalent.rs) | [leetcode](https://leetcode-cn.com/problems/check-whether-two-strings-are-almost-equivalent/) | Easy | |2190 | 统计出现过一次的公共字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-common-words-with-one-occurrence.rs) | [leetcode](https://leetcode-cn.com/problems/count-common-words-with-one-occurrence/) | Easy | |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | From 4543eefed9e3f71a63d280a87d9870cdae02c112 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 16 Mar 2024 22:28:33 +0800 Subject: [PATCH 1298/1556] src/bin/maximum-number-of-moves-in-a-grid.rs --- src/bin/maximum-number-of-moves-in-a-grid.rs | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/maximum-number-of-moves-in-a-grid.rs diff --git a/src/bin/maximum-number-of-moves-in-a-grid.rs b/src/bin/maximum-number-of-moves-in-a-grid.rs new file mode 100644 index 00000000..9a736d20 --- /dev/null +++ b/src/bin/maximum-number-of-moves-in-a-grid.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_moves(grid: Vec>) -> i32 { + let mut dp = vec![0; grid.len()]; + + for i in (0..grid[0].len() - 1).rev() { + let mut new_dp = vec![0; grid.len()]; + for j in (0..grid.len()) { + if grid[j][i] < grid[j][i + 1] { + new_dp[j] = dp[j] + 1; + } + + if j != 0 && grid[j][i] < grid[j - 1][i + 1] { + new_dp[j] = new_dp[j].max(dp[j - 1] + 1) + } + + if j != grid.len() - 1 && grid[j][i] < grid[j + 1][i + 1] { + new_dp[j] = new_dp[j].max(dp[j + 1] + 1) + } + } + + dp = new_dp; + } + + dp.into_iter().max().unwrap() + } +} From 39d4040f5a3519d91a9a5d8f4eb1bc43af3a17b0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 16 Mar 2024 22:28:33 +0800 Subject: [PATCH 1299/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 19dfb56c..3fb77758 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 693 | 303 | 362 | 28 | +| 694 | 303 | 363 | 28 | ### 题目 @@ -542,6 +542,7 @@ |2780 | 使二叉树所有路径值相等的最小代价 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-costs-of-paths-equal-in-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/make-costs-of-paths-equal-in-a-binary-tree/) | Medium | |2787 | 移动机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/movement-of-robots.rs) | [leetcode](https://leetcode-cn.com/problems/movement-of-robots/) | Medium | |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | +|2794 | 矩阵中移动的最大次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-moves-in-a-grid.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-moves-in-a-grid/) | Medium | |2800 | 删除子串后的字符串最小长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-string-length-after-removing-substrings.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-string-length-after-removing-substrings/) | Easy | |2802 | 求一个整数的惩罚数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-punishment-number-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-punishment-number-of-an-integer/) | Medium | |2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | From b7c4bd422bbb03fffeb8532fa70df863838c15dd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 17 Mar 2024 14:06:44 +0800 Subject: [PATCH 1300/1556] src/bin/detect-pattern-of-length-m-repeated-k-or-more-times.rs --- ...rn-of-length-m-repeated-k-or-more-times.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/detect-pattern-of-length-m-repeated-k-or-more-times.rs diff --git a/src/bin/detect-pattern-of-length-m-repeated-k-or-more-times.rs b/src/bin/detect-pattern-of-length-m-repeated-k-or-more-times.rs new file mode 100644 index 00000000..6c603be5 --- /dev/null +++ b/src/bin/detect-pattern-of-length-m-repeated-k-or-more-times.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn contains_pattern(arr: Vec, m: i32, k: i32) -> bool { + if (arr.len() as i32) < m * k { + return false; + } + + 'l: for i in 0..arr.len() - (m as usize) { + for j in i..m as usize + i { + for v in 0..k as usize { + match arr.get(j + v * m as usize) { + Some(&x) if x != arr[j] => continue 'l, + None => continue 'l, + _ => {} + } + } + } + + return true; + } + + false + } +} From 710ac44da871789ff1efad87af921f2572e52156 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 17 Mar 2024 14:06:45 +0800 Subject: [PATCH 1301/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3fb77758..15b698fb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 694 | 303 | 363 | 28 | +| 695 | 304 | 363 | 28 | ### 题目 @@ -422,6 +422,7 @@ |1660 | 千位分隔数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/thousand-separator.rs) | [leetcode](https://leetcode-cn.com/problems/thousand-separator/) | Easy | |1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | |1677 | 矩阵对角线元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/matrix-diagonal-sum.rs) | [leetcode](https://leetcode-cn.com/problems/matrix-diagonal-sum/) | Easy | +|1689 | 重复至少 K 次且长度为 M 的模式 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-pattern-of-length-m-repeated-k-or-more-times.rs) | [leetcode](https://leetcode-cn.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times/) | Easy | |1764 | 最大重复子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-repeating-substring.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-repeating-substring/) | Easy | |1767 | 设计前中后队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-front-middle-back-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-front-middle-back-queue/) | Medium | |1777 | 确定两个字符串是否接近 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/determine-if-two-strings-are-close.rs) | [leetcode](https://leetcode-cn.com/problems/determine-if-two-strings-are-close/) | Medium | From a37aa11843ea61419e0f9e710b0fb8914045ad54 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 19 Mar 2024 20:16:31 +0800 Subject: [PATCH 1302/1556] src/bin/generate-a-string-with-characters-that-have-odd-counts.rs --- ...ng-with-characters-that-have-odd-counts.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/bin/generate-a-string-with-characters-that-have-odd-counts.rs diff --git a/src/bin/generate-a-string-with-characters-that-have-odd-counts.rs b/src/bin/generate-a-string-with-characters-that-have-odd-counts.rs new file mode 100644 index 00000000..c1f2cb08 --- /dev/null +++ b/src/bin/generate-a-string-with-characters-that-have-odd-counts.rs @@ -0,0 +1,19 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn generate_the_string(n: i32) -> String { + if n % 2 == 1 { + "a".repeat(n as usize) + } else { + let mut result = String::with_capacity(n as usize); + result.push('a'); + result.extend((0..n - 1).map(|_x| 'b')); + + result + } + } +} From 54e309a4c70a31e2c880d8986623810beb84b01b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 19 Mar 2024 20:16:32 +0800 Subject: [PATCH 1303/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 15b698fb..6555f806 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 695 | 304 | 363 | 28 | +| 696 | 305 | 363 | 28 | ### 题目 @@ -398,6 +398,7 @@ |1472 | 上升下降字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increasing-decreasing-string.rs) | [leetcode](https://leetcode-cn.com/problems/increasing-decreasing-string/) | Easy | |1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | |1484 | 二叉树中的链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/linked-list-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/linked-list-in-binary-tree/) | Medium | +|1490 | 生成每种字符都是奇数个的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/generate-a-string-with-characters-that-have-odd-counts.rs) | [leetcode](https://leetcode-cn.com/problems/generate-a-string-with-characters-that-have-odd-counts/) | Easy | |1491 | 二进制字符串前缀一致的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-times-binary-string-is-prefix-aligned.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-times-binary-string-is-prefix-aligned/) | Medium | |1501 | 圆和矩形是否有重叠 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circle-and-rectangle-overlapping.rs) | [leetcode](https://leetcode-cn.com/problems/circle-and-rectangle-overlapping/) | Medium | |1503 | 做菜顺序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reducing-dishes.rs) | [leetcode](https://leetcode-cn.com/problems/reducing-dishes/) | Hard | From 57204013aa74dd9e1f33125d2d290c5be12b5897 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 19 Mar 2024 20:39:47 +0800 Subject: [PATCH 1304/1556] src/bin/number-of-good-pairs.rs --- src/bin/number-of-good-pairs.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/number-of-good-pairs.rs diff --git a/src/bin/number-of-good-pairs.rs b/src/bin/number-of-good-pairs.rs new file mode 100644 index 00000000..e856a867 --- /dev/null +++ b/src/bin/number-of-good-pairs.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn num_identical_pairs(nums: Vec) -> i32 { + let mut hash = std::collections::HashMap::new(); + let mut result = 0; + for i in nums { + if let Some(&x) = hash.get(&i) { + result += x; + } + + hash.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + result + } +} From 437a64cb50869f5b998220da1a3207b5db619749 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 19 Mar 2024 20:39:47 +0800 Subject: [PATCH 1305/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6555f806..3c563055 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 696 | 305 | 363 | 28 | +| 697 | 306 | 363 | 28 | ### 题目 @@ -417,6 +417,7 @@ |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | |1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | |1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | +|1635 | 好数对的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-good-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-good-pairs/) | Easy | |1636 | 仅含 1 的子串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-substrings-with-only-1s.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-substrings-with-only-1s/) | Medium | |1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | Easy | |1656 | 统计好三元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-good-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/count-good-triplets/) | Easy | From f0cc79042bb68486858b656f2b96d701a40ece10 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 20 Mar 2024 20:27:53 +0800 Subject: [PATCH 1306/1556] src/bin/squares-of-a-sorted-array.rs --- src/bin/squares-of-a-sorted-array.rs | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/squares-of-a-sorted-array.rs diff --git a/src/bin/squares-of-a-sorted-array.rs b/src/bin/squares-of-a-sorted-array.rs new file mode 100644 index 00000000..4dbc1cfb --- /dev/null +++ b/src/bin/squares-of-a-sorted-array.rs @@ -0,0 +1,31 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn sorted_squares(nums: Vec) -> Vec { + let mut r = vec![0; nums.len()]; + let mut k = nums.len() - 1; + let mut nums = &nums[..]; + + while !nums.is_empty() { + if nums.len() == 1 { + r[k] = nums[0].pow(2); + nums = &nums[1..]; + } else { + if nums[0].abs() > nums[nums.len() - 1].abs() { + r[k] = nums[0].pow(2); + nums = &nums[1..]; + } else { + r[k] = nums[nums.len() - 1].pow(2); + nums = &nums[..nums.len() - 1]; + } + } + + k -= 1; + } + r + } +} From 3ce9f825cc4a284d452850c46076b18307da877a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 20 Mar 2024 20:27:54 +0800 Subject: [PATCH 1307/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c563055..ce547518 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 697 | 306 | 363 | 28 | +| 698 | 307 | 363 | 28 | ### 题目 @@ -339,6 +339,7 @@ |1005 | 单值二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/univalued-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/univalued-binary-tree/) | Easy | |1007 | 连续差相同的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/numbers-with-same-consecutive-differences.rs) | [leetcode](https://leetcode-cn.com/problems/numbers-with-same-consecutive-differences/) | Medium | |1010 | 强整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/powerful-integers.rs) | [leetcode](https://leetcode-cn.com/problems/powerful-integers/) | Medium | +|1019 | 有序数组的平方 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/squares-of-a-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/squares-of-a-sorted-array/) | Easy | |1021 | 在二叉树中分配硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-coins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-coins-in-binary-tree/) | Medium | |1035 | 二叉树的堂兄弟节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cousins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/cousins-in-binary-tree/) | Easy | |1036 | 腐烂的橘子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotting-oranges.rs) | [leetcode](https://leetcode-cn.com/problems/rotting-oranges/) | Medium | From e61f3dc295554a3bc4aed8926c0865ea1ba0e65d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 21 Mar 2024 20:58:51 +0800 Subject: [PATCH 1308/1556] src/bin/frequency-tracker.rs --- src/bin/frequency-tracker.rs | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/bin/frequency-tracker.rs diff --git a/src/bin/frequency-tracker.rs b/src/bin/frequency-tracker.rs new file mode 100644 index 00000000..edc1312e --- /dev/null +++ b/src/bin/frequency-tracker.rs @@ -0,0 +1,68 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ +/** + * Your FrequencyTracker object will be instantiated and called as such: + * let obj = FrequencyTracker::new(); + * obj.add(number); + * obj.delete_one(number); + * let ret_3: bool = obj.has_frequency(frequency); + */ + +struct FrequencyTracker { + /// 每个数字对应的次数 + s1: std::collections::HashMap, + /// 每个次数对应的数字个数 + s2: std::collections::HashMap, +} + +impl FrequencyTracker { + fn new() -> Self { + Self { + s1: Default::default(), + s2: Default::default(), + } + } + + fn add(&mut self, number: i32) { + self.s1.entry(number).and_modify(|x| *x += 1).or_insert(1); + let n = self.s1[&number]; + + self.s2.entry(n).and_modify(|x| *x += 1).or_insert(1); + self.remove_s2_or_delete(n - 1); + } + + fn remove_s2_or_delete(&mut self, times: i32) { + self.s2.entry(times).and_modify(|x| *x -= 1); + let &x = self.s2.get(×).unwrap_or(&0); + if x == 0 { + self.s2.remove(×); + } + } + + fn delete_one(&mut self, number: i32) { + self.s1.entry(number).and_modify(|x| *x -= 1); + match self.s1.get(&number) { + Some(&x) => { + if x == 0 { + self.s1.remove(&number); + } + + self.s2.entry(x).and_modify(|x| *x += 1).or_insert(1); + self.remove_s2_or_delete(x + 1); + } + _ => {} + } + } + + fn has_frequency(&self, frequency: i32) -> bool { + self.s2.get(&frequency).is_some() + } +} From 632d09cd742f5aebbe5fae27849b734bd2d83f9a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 21 Mar 2024 20:58:51 +0800 Subject: [PATCH 1309/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ce547518..77d91793 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 698 | 307 | 363 | 28 | +| 699 | 307 | 364 | 28 | ### 题目 @@ -543,6 +543,7 @@ |2756 | 购买两块巧克力 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/buy-two-chocolates.rs) | [leetcode](https://leetcode-cn.com/problems/buy-two-chocolates/) | Easy | |2767 | K 个元素的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-with-exactly-k-elements.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-with-exactly-k-elements/) | Easy | |2777 | 找出不同元素数目差数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-distinct-difference-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-distinct-difference-array/) | Easy | +|2778 | 频率跟踪器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/frequency-tracker.rs) | [leetcode](https://leetcode-cn.com/problems/frequency-tracker/) | Medium | |2780 | 使二叉树所有路径值相等的最小代价 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-costs-of-paths-equal-in-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/make-costs-of-paths-equal-in-a-binary-tree/) | Medium | |2787 | 移动机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/movement-of-robots.rs) | [leetcode](https://leetcode-cn.com/problems/movement-of-robots/) | Medium | |2791 | 找出转圈游戏输家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-losers-of-the-circular-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-losers-of-the-circular-game/) | Easy | From 5e5d334a1e4702396ee93ccfc556f210e67a32fa Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 24 Mar 2024 23:22:36 +0800 Subject: [PATCH 1310/1556] src/bin/increment-submatrices-by-one.rs --- src/bin/increment-submatrices-by-one.rs | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bin/increment-submatrices-by-one.rs diff --git a/src/bin/increment-submatrices-by-one.rs b/src/bin/increment-submatrices-by-one.rs new file mode 100644 index 00000000..59ec0637 --- /dev/null +++ b/src/bin/increment-submatrices-by-one.rs @@ -0,0 +1,40 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 二维差分 + /// 开始的下标+1,结尾+1的下标-1 + /// 例如有数组 vec![0,0,0,0,0,0,0,0],如果把[1,3]的下标都加一,因此我们有差分数组vec![0,1,0,0,-1,0,0,0] + /// 然后每个下标为前缀和 + pub fn range_add_queries(n: i32, queries: Vec>) -> Vec> { + let mut diff = vec![vec![0; n as usize + 2]; n as usize + 2]; + + for query in queries { + let (r1, c1, r2, c2) = ( + query[0] as usize, + query[1] as usize, + query[2] as usize, + query[3] as usize, + ); + + diff[r1 + 1][c1 + 1] += 1; + diff[r1 + 1][c2 + 2] -= 1; + diff[r2 + 2][c1 + 1] -= 1; + diff[r2 + 2][c2 + 2] += 1; + } + + for i in 1..=n as usize { + for j in 1..=n as usize { + diff[i][j] += diff[i][j - 1] + diff[i - 1][j] - diff[i - 1][j - 1]; + } + } + + diff[1..n as usize + 1] + .into_iter() + .map(|x| x[1..n as usize + 1].to_vec()) + .collect() + } +} From 6b9b960cf5fbd3742aff2fc9ed00c01497f11e64 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 24 Mar 2024 23:22:37 +0800 Subject: [PATCH 1311/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 77d91793..060438c4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 699 | 307 | 364 | 28 | +| 700 | 307 | 365 | 28 | ### 题目 @@ -513,6 +513,7 @@ |2616 | 执行 K 次操作后的最大分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-score-after-applying-k-operations.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-score-after-applying-k-operations/) | Medium | |2619 | 根据规则将箱子分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/categorize-box-according-to-criteria.rs) | [leetcode](https://leetcode-cn.com/problems/categorize-box-according-to-criteria/) | Easy | |2621 | 查询数组异或美丽值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-xor-beauty-of-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-xor-beauty-of-array/) | Medium | +|2625 | 子矩阵元素加 1 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increment-submatrices-by-one.rs) | [leetcode](https://leetcode-cn.com/problems/increment-submatrices-by-one/) | Medium | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2645 | 递枕头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pass-the-pillow.rs) | [leetcode](https://leetcode-cn.com/problems/pass-the-pillow/) | Easy | |2646 | 二叉树中的第 K 大层和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-sum-in-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-sum-in-a-binary-tree/) | Medium | From 45e440bace2b8158c6469bf815c6d510ed1b2ea6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 25 Mar 2024 20:55:30 +0800 Subject: [PATCH 1312/1556] src/bin/coin-change-ii.rs --- src/bin/coin-change-ii.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/coin-change-ii.rs diff --git a/src/bin/coin-change-ii.rs b/src/bin/coin-change-ii.rs new file mode 100644 index 00000000..16bc73fb --- /dev/null +++ b/src/bin/coin-change-ii.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn change(amount: i32, coins: Vec) -> i32 { + let mut r = vec![0; amount as usize + 1]; + r[0] = 1; + + for coin in coins { + for i in coin..=amount { + r[i as usize] += r[(i - coin) as usize]; + } + } + + r[amount as usize] + } +} From b0a2dc339cbfa5eac690bb2aabe9fb92dcf936b3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 25 Mar 2024 20:55:31 +0800 Subject: [PATCH 1313/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 060438c4..bb130d34 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 700 | 307 | 365 | 28 | +| 701 | 307 | 366 | 28 | ### 题目 @@ -261,6 +261,7 @@ |508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | |513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | |515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | +|518 | 零钱兑换 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change-ii.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change-ii/) | Medium | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | |530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | From bc616a65d1dae97d7ba4e5a9691f01d19a14dbe8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 26 Mar 2024 20:43:52 +0800 Subject: [PATCH 1314/1556] src/bin/binary-subarrays-with-sum.rs --- src/bin/binary-subarrays-with-sum.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/binary-subarrays-with-sum.rs diff --git a/src/bin/binary-subarrays-with-sum.rs b/src/bin/binary-subarrays-with-sum.rs new file mode 100644 index 00000000..74afa1e4 --- /dev/null +++ b/src/bin/binary-subarrays-with-sum.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn num_subarrays_with_sum(nums: Vec, goal: i32) -> i32 { + let mut map = std::collections::HashMap::::new(); + let mut sum = 0; + let mut result = 0; + for i in nums { + sum += i; + map.entry(sum).and_modify(|x| *x += 1).or_insert(1); + result += *map.get(&(sum - goal)).unwrap_or(&0); + } + + result + } +} From 93f6d5a8a79f0f8df13bd2adcf74663a3cc2995c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 26 Mar 2024 20:43:53 +0800 Subject: [PATCH 1315/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bb130d34..a9e4b863 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 701 | 307 | 366 | 28 | +| 702 | 307 | 367 | 28 | ### 题目 @@ -329,6 +329,7 @@ |950 | 卡牌分组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/x-of-a-kind-in-a-deck-of-cards.rs) | [leetcode](https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards/) | Easy | |953 | 仅仅反转字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-only-letters.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-only-letters/) | Easy | |954 | 环形子数组的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-circular-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-circular-subarray/) | Medium | +|966 | 和相同的二元子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-subarrays-with-sum.rs) | [leetcode](https://leetcode-cn.com/problems/binary-subarrays-with-sum/) | Medium | |967 | 下降路径最小和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-falling-path-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-falling-path-sum/) | Medium | |975 | 二叉搜索树的范围和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/range-sum-of-bst.rs) | [leetcode](https://leetcode-cn.com/problems/range-sum-of-bst/) | Easy | |977 | 不同的子序列 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distinct-subsequences-ii.rs) | [leetcode](https://leetcode-cn.com/problems/distinct-subsequences-ii/) | Hard | From 5ed4c3ecb9c8407e46beb5c32552b2139a3a5836 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 27 Mar 2024 20:21:48 +0800 Subject: [PATCH 1316/1556] src/bin/count-ways-to-group-overlapping-ranges.rs --- .../count-ways-to-group-overlapping-ranges.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/count-ways-to-group-overlapping-ranges.rs diff --git a/src/bin/count-ways-to-group-overlapping-ranges.rs b/src/bin/count-ways-to-group-overlapping-ranges.rs new file mode 100644 index 00000000..ec891a3e --- /dev/null +++ b/src/bin/count-ways-to-group-overlapping-ranges.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_ways(ranges: Vec>) -> i32 { + let mut ranges = ranges; + ranges.sort(); + let mut max = -1; + let mut m = 1; + + for range in ranges { + if range[0] > max { + m = m * 2 % 1000000007; + } + + max = max.max(range[1]); + } + + m + } +} From a77645c31d9680a7519c31aaa02bb17d7c1a3f0c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 27 Mar 2024 20:21:49 +0800 Subject: [PATCH 1317/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a9e4b863..99b7baad 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 702 | 307 | 367 | 28 | +| 703 | 307 | 368 | 28 | ### 题目 @@ -520,6 +520,7 @@ |2645 | 递枕头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pass-the-pillow.rs) | [leetcode](https://leetcode-cn.com/problems/pass-the-pillow/) | Easy | |2646 | 二叉树中的第 K 大层和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-largest-sum-in-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/kth-largest-sum-in-a-binary-tree/) | Medium | |2650 | 最小和分割 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-with-minimum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/split-with-minimum-sum/) | Easy | +|2651 | 统计将重叠区间合并成组的方案数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-ways-to-group-overlapping-ranges.rs) | [leetcode](https://leetcode-cn.com/problems/count-ways-to-group-overlapping-ranges/) | Medium | |2654 | 统计范围内的元音字符串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-the-number-of-vowel-strings-in-range.rs) | [leetcode](https://leetcode-cn.com/problems/count-the-number-of-vowel-strings-in-range/) | Easy | |2662 | 检查骑士巡视方案 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-knight-tour-configuration.rs) | [leetcode](https://leetcode-cn.com/problems/check-knight-tour-configuration/) | Medium | |2663 | 将钱分给最多的儿童 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-money-to-maximum-children.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-money-to-maximum-children/) | Easy | From 4596ea9ee0fefbe5dfc9ab8b7884679c6b947f5f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 28 Mar 2024 20:59:57 +0800 Subject: [PATCH 1318/1556] src/bin/duplicate-zeros.rs --- src/bin/duplicate-zeros.rs | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/bin/duplicate-zeros.rs diff --git a/src/bin/duplicate-zeros.rs b/src/bin/duplicate-zeros.rs new file mode 100644 index 00000000..4250cac8 --- /dev/null +++ b/src/bin/duplicate-zeros.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 有多少个零重复,后面就会被截断多少 + /// 然后从截断开始的位置往前回放,遇到0就放2两个就行了。 + pub fn duplicate_zeros(arr: &mut Vec) { + let (mut i, mut j) = (0, 0); + while j <= arr.len() - 1 { + if arr[i] == 0 { + j += 1; + } + j += 1; + i += 1; + } + + j -= 1; + i -= 1; + + while i >= 0 { + if j < arr.len() { + arr[j] = arr[i]; + } + + if arr[i] == 0 { + j -= 1; + arr[j] = 0; + } + + if i == 0 { + return; + } + + j -= 1; + i -= 1; + } + } +} From 31082553c2f388ab5ce02e02d6c669e83737b72b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 28 Mar 2024 20:59:58 +0800 Subject: [PATCH 1319/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99b7baad..6fd7f8a8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 703 | 307 | 368 | 28 | +| 704 | 308 | 368 | 28 | ### 题目 @@ -356,6 +356,7 @@ |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | |1146 | 字符串的最大公因子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/greatest-common-divisor-of-strings.rs) | [leetcode](https://leetcode-cn.com/problems/greatest-common-divisor-of-strings/) | Easy | |1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | +|1168 | 复写零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/duplicate-zeros.rs) | [leetcode](https://leetcode-cn.com/problems/duplicate-zeros/) | Easy | |1184 | 拼车 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/car-pooling.rs) | [leetcode](https://leetcode-cn.com/problems/car-pooling/) | Medium | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | |1218 | 最深叶节点的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-deepest-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves/) | Medium | From 6e2c7aa7aa6db08325226c6f77b38700f7e486f2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 29 Mar 2024 21:07:39 +0800 Subject: [PATCH 1320/1556] src/bin/sender-with-largest-word-count.rs --- src/bin/sender-with-largest-word-count.rs | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/bin/sender-with-largest-word-count.rs diff --git a/src/bin/sender-with-largest-word-count.rs b/src/bin/sender-with-largest-word-count.rs new file mode 100644 index 00000000..ced5d40e --- /dev/null +++ b/src/bin/sender-with-largest-word-count.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn largest_word_count(messages: Vec, senders: Vec) -> String { + let mut h = std::collections::HashMap::new(); + + for (i, v) in messages.iter().enumerate() { + let n = v.split(' ').count(); + h.entry(&senders[i]) + .and_modify(|x| *x += n as i32) + .or_insert(n as i32); + } + let mut r = &String::new(); + let mut i = 0; + for (n, v) in h { + if v > i { + r = n; + i = v; + } else if v == i { + r = r.max(n); + } + } + + r.clone() + } +} From 6ad5254f0407d80b6873903f726873da323a310a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 29 Mar 2024 21:07:39 +0800 Subject: [PATCH 1321/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6fd7f8a8..f62934bb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 704 | 308 | 368 | 28 | +| 705 | 308 | 369 | 28 | ### 题目 @@ -487,6 +487,7 @@ |2328 | 向表达式添加括号后的最小结果 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimize-result-by-adding-parentheses-to-expression.rs) | [leetcode](https://leetcode-cn.com/problems/minimize-result-by-adding-parentheses-to-expression/) | Medium | |2346 | 字符串中最大的 3 位相同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-3-same-digit-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-3-same-digit-number-in-string/) | Easy | |2351 | 买钢笔和铅笔的方案数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-ways-to-buy-pens-and-pencils.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-ways-to-buy-pens-and-pencils/) | Medium | +|2378 | 最多单词数的发件人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sender-with-largest-word-count.rs) | [leetcode](https://leetcode-cn.com/problems/sender-with-largest-word-count/) | Medium | |2384 | 判断根结点是否等于子结点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/root-equals-sum-of-children.rs) | [leetcode](https://leetcode-cn.com/problems/root-equals-sum-of-children/) | Easy | |2386 | 极大极小游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-max-game.rs) | [leetcode](https://leetcode-cn.com/problems/min-max-game/) | Easy | |2392 | 咒语和药水的成功对数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/successful-pairs-of-spells-and-potions.rs) | [leetcode](https://leetcode-cn.com/problems/successful-pairs-of-spells-and-potions/) | Medium | From 5b91e43a879a416175df51c8bb03805350637d9c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 30 Mar 2024 11:36:01 +0800 Subject: [PATCH 1322/1556] src/bin/minimum-number-of-coins-to-be-added.rs --- .../minimum-number-of-coins-to-be-added.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/minimum-number-of-coins-to-be-added.rs diff --git a/src/bin/minimum-number-of-coins-to-be-added.rs b/src/bin/minimum-number-of-coins-to-be-added.rs new file mode 100644 index 00000000..d3b2e3b6 --- /dev/null +++ b/src/bin/minimum-number-of-coins-to-be-added.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_added_coins(mut coins: Vec, target: i32) -> i32 { + coins.sort_unstable(); + let mut ans = 0; + let mut s = 1; + let mut i = 0; + while s <= target { + if i < coins.len() && coins[i] <= s { + s += coins[i]; + i += 1; + } else { + s *= 2; // 必须添加 s + ans += 1; + } + } + ans + } +} From 8d90b93fb8b68a2950d370253339758a80d765ef Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 30 Mar 2024 11:36:02 +0800 Subject: [PATCH 1323/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f62934bb..5a6cc238 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 705 | 308 | 369 | 28 | +| 706 | 308 | 370 | 28 | ### 题目 @@ -577,6 +577,7 @@ |3176 | 元素和最小的山形三元组 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sum-of-mountain-triplets-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sum-of-mountain-triplets-i/) | Easy | |3183 | 找出数组中的 K-or 值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-k-or-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-k-or-of-an-array/) | Easy | |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | +|3231 | 需要添加的硬币的最小数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-coins-to-be-added.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-coins-to-be-added/) | Medium | |3275 | 输入单词需要的最少按键次数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-pushes-to-type-word-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-pushes-to-type-word-i/) | Easy | |3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | From 30051306ff7443672c34c42990846b12591743fc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 31 Mar 2024 11:50:24 +0800 Subject: [PATCH 1324/1556] src/bin/verify-preorder-serialization-of-a-binary-tree.rs --- ...preorder-serialization-of-a-binary-tree.rs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/bin/verify-preorder-serialization-of-a-binary-tree.rs diff --git a/src/bin/verify-preorder-serialization-of-a-binary-tree.rs b/src/bin/verify-preorder-serialization-of-a-binary-tree.rs new file mode 100644 index 00000000..1ab84076 --- /dev/null +++ b/src/bin/verify-preorder-serialization-of-a-binary-tree.rs @@ -0,0 +1,52 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 栈 + /// 当栈顶出现两个#,则说明当前节点叶子节点,可以把叶子节点去掉(转化为一个#继续遍历) + pub fn is_valid_serialization1(preorder: String) -> bool { + let mut stack = vec![]; + for i in preorder.split(',') { + match i { + "#" => { + stack.push("#"); + while stack.len() >= 3 + && stack[stack.len() - 1] == "#" + && stack[stack.len() - 2] == "#" + && stack[stack.len() - 3] != "#" + { + stack.pop(); + stack.pop(); + stack.pop(); + stack.push("#"); + } + } + i => stack.push(i), + } + } + + stack.len() == 1 && stack[0] == "#" + } + + /// 入度出度。入度为多少节点指向它,出度是指它指向多少节点 + /// 入度+1,出度-1,最终和为0 则表示有效 + /// 注:整个过程中和必须大于等于0 + pub fn is_valid_serialization(preorder: String) -> bool { + let mut diff = 1; + for i in preorder.split(',') { + diff -= 1; + if diff < 0 { + return false; + } + + if i != "#" { + diff += 2; + } + } + + diff == 0 + } +} From 9bbec5a9cff5e5b4c849b76bb0ada7abffbb07bf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 31 Mar 2024 11:50:24 +0800 Subject: [PATCH 1325/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a6cc238..9893885f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 706 | 308 | 370 | 28 | +| 707 | 308 | 371 | 28 | ### 题目 @@ -198,6 +198,7 @@ |319 | 灯泡开关 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bulb-switcher.rs) | [leetcode](https://leetcode-cn.com/problems/bulb-switcher/) | Medium | |322 | 零钱兑换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change/) | Medium | |326 | 3 的幂 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/power-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/power-of-three/) | Easy | +|331 | 验证二叉树的前序序列化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/verify-preorder-serialization-of-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/verify-preorder-serialization-of-a-binary-tree/) | Medium | |334 | 递增的三元子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increasing-triplet-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/increasing-triplet-subsequence/) | Medium | |337 | 打家劫舍 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/house-robber-iii.rs) | [leetcode](https://leetcode-cn.com/problems/house-robber-iii/) | Medium | |338 | 比特位计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-bits.rs) | [leetcode](https://leetcode-cn.com/problems/counting-bits/) | Easy | From 18a0605762e8c9a4408e547acfa84fd473e76ffb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 1 Apr 2024 20:08:51 +0800 Subject: [PATCH 1326/1556] src/bin/faulty-keyboard.rs --- src/bin/faulty-keyboard.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/bin/faulty-keyboard.rs diff --git a/src/bin/faulty-keyboard.rs b/src/bin/faulty-keyboard.rs new file mode 100644 index 00000000..9f7e62bc --- /dev/null +++ b/src/bin/faulty-keyboard.rs @@ -0,0 +1,33 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 双端队列实现 + pub fn final_string(s: String) -> String { + use std::collections::LinkedList; + let mut list = LinkedList::new(); + let mut f = true; // true代表正向,false代表逆向 + + for i in s.chars() { + if i == 'i' { + f = !f; + continue; + } + + if f { + list.push_back(i); + } else { + list.push_front(i); + } + } + + if f { + list.into_iter().collect() + } else { + list.into_iter().rev().collect() + } + } +} From 0db1f7004c0df2098a6bd837efd866a06fc7fb08 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 1 Apr 2024 20:08:51 +0800 Subject: [PATCH 1327/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9893885f..1f4256ae 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 707 | 308 | 371 | 28 | +| 708 | 309 | 371 | 28 | ### 题目 @@ -565,6 +565,7 @@ |2870 | 最长交替子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-alternating-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/longest-alternating-subarray/) | Easy | |2872 | 合并后数组中的最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-element-in-an-array-after-merge-operations.rs) | [leetcode](https://leetcode-cn.com/problems/largest-element-in-an-array-after-merge-operations/) | Medium | |2881 | 按分隔符拆分字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-strings-by-separator.rs) | [leetcode](https://leetcode-cn.com/problems/split-strings-by-separator/) | Easy | +|2886 | 故障键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/faulty-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/faulty-keyboard/) | Easy | |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | |2920 | 使循环数组所有元素相等的最少秒数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-seconds-to-equalize-a-circular-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-seconds-to-equalize-a-circular-array/) | Medium | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | From 1fb774e8dc9c834cf3e8562162ae934dac17c457 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 2 Apr 2024 20:59:47 +0800 Subject: [PATCH 1328/1556] src/bin/all-possible-full-binary-trees.rs --- src/bin/all-possible-full-binary-trees.rs | 61 +++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/bin/all-possible-full-binary-trees.rs diff --git a/src/bin/all-possible-full-binary-trees.rs b/src/bin/all-possible-full-binary-trees.rs new file mode 100644 index 00000000..26932724 --- /dev/null +++ b/src/bin/all-possible-full-binary-trees.rs @@ -0,0 +1,61 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +fn main() {} + +struct Solution; + +impl Solution { + /// 递归,n为偶数肯定不行 + /// 假设左节点按1,3,5递增 + /// 则右节点数为n-1-1,n-1-3,n-1-5 + pub fn all_possible_fbt(n: i32) -> Vec>>> { + let mut v = vec![]; + if n % 2 == 0 { + return v; + } + + if n == 1 { + v.push(Some(Rc::new(RefCell::new(TreeNode::new(0))))); + return v; + } + + for i in (1..=n - 2).step_by(2) { + let left = Self::all_possible_fbt(i); + let right = Self::all_possible_fbt(n - i - 1); + + for l in left.iter() { + for r in right.iter() { + let mut root = Rc::new(RefCell::new(TreeNode::new(0))); + root.borrow_mut().left = l.clone(); + root.borrow_mut().right = r.clone(); + + v.push(Some(root)) + } + } + } + + v + } +} From a40e5f466c6856bd8cf42e9b03f24533157f4eaf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 2 Apr 2024 20:59:48 +0800 Subject: [PATCH 1329/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f4256ae..e1bfe7fc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 708 | 309 | 371 | 28 | +| 709 | 309 | 372 | 28 | ### 题目 @@ -323,6 +323,7 @@ |924 | 公平的糖果交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fair-candy-swap.rs) | [leetcode](https://leetcode-cn.com/problems/fair-candy-swap/) | Easy | |925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | |928 | 三维形体的表面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/surface-area-of-3d-shapes.rs) | [leetcode](https://leetcode-cn.com/problems/surface-area-of-3d-shapes/) | Easy | +|930 | 所有可能的真二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-possible-full-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/all-possible-full-binary-trees/) | Medium | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | |937 | 股票价格跨度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-stock-span.rs) | [leetcode](https://leetcode-cn.com/problems/online-stock-span/) | Medium | From 38e06cc69ae90b45f5fdd425a3e7596c53db4477 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Apr 2024 18:46:11 +0800 Subject: [PATCH 1330/1556] src/bin/all-possible-full-binary-trees.rs --- src/bin/all-possible-full-binary-trees.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/all-possible-full-binary-trees.rs b/src/bin/all-possible-full-binary-trees.rs index 26932724..1e13fa97 100644 --- a/src/bin/all-possible-full-binary-trees.rs +++ b/src/bin/all-possible-full-binary-trees.rs @@ -59,3 +59,4 @@ impl Solution { v } } + From aa78d4525b6f76d05bf20f36402c646eba7bc15b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Apr 2024 18:46:12 +0800 Subject: [PATCH 1331/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1bfe7fc..068f4305 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 709 | 309 | 372 | 28 | +| 710 | 309 | 373 | 28 | ### 题目 @@ -324,6 +324,7 @@ |925 | 根据前序和后序遍历构造二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-tree-from-preorder-and-postorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | |928 | 三维形体的表面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/surface-area-of-3d-shapes.rs) | [leetcode](https://leetcode-cn.com/problems/surface-area-of-3d-shapes/) | Easy | |930 | 所有可能的真二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-possible-full-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/all-possible-full-binary-trees/) | Medium | +|930 | 所有可能的真二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-possible-full-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/all-possible-full-binary-trees/) | Medium | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | |937 | 股票价格跨度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-stock-span.rs) | [leetcode](https://leetcode-cn.com/problems/online-stock-span/) | Medium | From 002017311e588f448a11641a2ad9d19aa3e0697f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 6 Apr 2024 22:20:58 +0800 Subject: [PATCH 1332/1556] src/bin/finding-pairs-with-a-certain-sum.rs --- src/bin/finding-pairs-with-a-certain-sum.rs | 58 +++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/bin/finding-pairs-with-a-certain-sum.rs diff --git a/src/bin/finding-pairs-with-a-certain-sum.rs b/src/bin/finding-pairs-with-a-certain-sum.rs new file mode 100644 index 00000000..d2c29b20 --- /dev/null +++ b/src/bin/finding-pairs-with-a-certain-sum.rs @@ -0,0 +1,58 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ + +struct FindSumPairs { + nums2_map: std::collections::HashMap, + nums1: Vec, + nums2: Vec, +} + +impl FindSumPairs { + + fn new(nums1: Vec, nums2: Vec) -> Self { + let mut nums2_map = std::collections::HashMap::new(); + + for &i in nums2.iter() { + nums2_map.entry(i).and_modify(|x| *x += 1).or_insert(1); + } + + + Self { + nums2_map, + nums1, + nums2, + } + } + + fn add(&mut self, index: i32, val: i32) { + let mut origin = self.nums2[index as usize]; + self.nums2[index as usize] += val; + self.nums2_map.entry(origin).and_modify(|x| *x-=1); + self.nums2_map.entry(origin + val).and_modify(|x| *x += 1).or_insert(1); + } + + fn count(&self, tot: i32) -> i32 { + let mut result = 0; + for &i in self.nums1.iter() { + result += *self.nums2_map.get(&(tot-i)).unwrap_or(&0); + } + + result + } +} + +/** + * Your FindSumPairs object will be instantiated and called as such: + * let obj = FindSumPairs::new(nums1, nums2); + * obj.add(index, val); + * let ret_2: i32 = obj.count(tot); + */ From ff891d6918205807c29691498736200b496915d8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 6 Apr 2024 22:20:58 +0800 Subject: [PATCH 1333/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 068f4305..71f0eeb7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 710 | 309 | 373 | 28 | +| 711 | 309 | 374 | 28 | ### 题目 @@ -459,6 +459,7 @@ |1965 | K 进制表示下的各位数字总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-digits-in-base-k.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-digits-in-base-k/) | Easy | |1971 | 增长的内存泄露 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/incremental-memory-leak.rs) | [leetcode](https://leetcode-cn.com/problems/incremental-memory-leak/) | Medium | |1983 | 人口最多的年份 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-population-year.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-population-year/) | Easy | +|1995 | 找出和为指定值的下标对 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/finding-pairs-with-a-certain-sum.rs) | [leetcode](https://leetcode-cn.com/problems/finding-pairs-with-a-certain-sum/) | Medium | |2011 | 插入后的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-after-insertion.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-after-insertion/) | Medium | |2022 | 最大子序列交替和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-alternating-subsequence-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-alternating-subsequence-sum/) | Medium | |2032 | 字符串中的最大奇数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-odd-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-odd-number-in-string/) | Easy | From 280162c2e19af394dcd27ef38cd3d65209168df2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 7 Apr 2024 20:54:54 +0800 Subject: [PATCH 1334/1556] src/bin/throne-inheritance.rs --- src/bin/throne-inheritance.rs | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/bin/throne-inheritance.rs diff --git a/src/bin/throne-inheritance.rs b/src/bin/throne-inheritance.rs new file mode 100644 index 00000000..297cb5e3 --- /dev/null +++ b/src/bin/throne-inheritance.rs @@ -0,0 +1,68 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ + +struct ThroneInheritance { + death: std::collections::HashSet, + tree: std::collections::HashMap>, + king_name: String, +} + +impl ThroneInheritance { + + fn new(kingName: String) -> Self { + Self { + death: std::collections::HashSet::new(), + tree: { + let mut tree = std::collections::HashMap::new(); + tree.insert(kingName.clone(), vec![]); + tree + }, + king_name: kingName, + } + } + + fn birth(&mut self, parent_name: String, child_name: String) { + self.tree.entry(parent_name).and_modify(|x|x.push(child_name.clone())); + self.tree.entry(child_name.clone()).or_insert(vec![]); + } + + fn death(&mut self, name: String) { + self.death.insert(name); + } + + fn dfs(&self, name: &String, data: &mut Vec) { + if !self.death.contains(name) { + data.push(name.clone()); + } + + if let Some(children) = self.tree.get(name) { + for child in children { + self.dfs(child, data); + } + } + } + + fn get_inheritance_order(&self) -> Vec { + let mut data = vec![]; + + self.dfs(&self.king_name, &mut data); + + data + } +} + +/** + * Your ThroneInheritance object will be instantiated and called as such: + * let obj = ThroneInheritance::new(kingName); + * obj.birth(parentName, childName); + * obj.death(name); + * let ret_3: Vec = obj.get_inheritance_order(); + */ From 52f116a73865ac4ce86ef5f00961d8b4c606cafe Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 7 Apr 2024 20:54:55 +0800 Subject: [PATCH 1335/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 71f0eeb7..8e5dc9b4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 711 | 309 | 374 | 28 | +| 712 | 309 | 375 | 28 | ### 题目 @@ -432,6 +432,7 @@ |1666 | 整理字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-the-string-great.rs) | [leetcode](https://leetcode-cn.com/problems/make-the-string-great/) | Easy | |1677 | 矩阵对角线元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/matrix-diagonal-sum.rs) | [leetcode](https://leetcode-cn.com/problems/matrix-diagonal-sum/) | Easy | |1689 | 重复至少 K 次且长度为 M 的模式 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-pattern-of-length-m-repeated-k-or-more-times.rs) | [leetcode](https://leetcode-cn.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times/) | Easy | +|1722 | 王位继承顺序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/throne-inheritance.rs) | [leetcode](https://leetcode-cn.com/problems/throne-inheritance/) | Medium | |1764 | 最大重复子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-repeating-substring.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-repeating-substring/) | Easy | |1767 | 设计前中后队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-front-middle-back-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-front-middle-back-queue/) | Medium | |1777 | 确定两个字符串是否接近 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/determine-if-two-strings-are-close.rs) | [leetcode](https://leetcode-cn.com/problems/determine-if-two-strings-are-close/) | Medium | From fda9bfdd62ab2fe643ab400f3de2d6feb551cc21 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 8 Apr 2024 20:59:40 +0800 Subject: [PATCH 1336/1556] src/bin/odd-string-difference.rs --- src/bin/odd-string-difference.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/odd-string-difference.rs diff --git a/src/bin/odd-string-difference.rs b/src/bin/odd-string-difference.rs new file mode 100644 index 00000000..ec2a2bc4 --- /dev/null +++ b/src/bin/odd-string-difference.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn odd_string(words: Vec) -> String { + let mut d = std::collections::HashMap::new(); + + for i in words { + let mut s = vec![]; + for j in 1..i.as_bytes().len() { + s.push(i.as_bytes()[j] - i.as_bytes()[j - 1]); + } + + d.entry(s).or_insert(vec![]).push(i); + } + + for (i, j) in d { + if j.len() == 1 { + return j[0].clone(); + } + } + + unreachable!() + } +} From 6373c922371aee46ff536385f0a7d58569abc50b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 8 Apr 2024 20:59:40 +0800 Subject: [PATCH 1337/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e5dc9b4..59da493e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 712 | 309 | 375 | 28 | +| 713 | 310 | 375 | 28 | ### 题目 @@ -506,6 +506,7 @@ |2509 | 最小异或 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimize-xor.rs) | [leetcode](https://leetcode-cn.com/problems/minimize-xor/) | Medium | |2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | |2519 | 找出前缀异或的原始数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-original-array-of-prefix-xor.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-original-array-of-prefix-xor/) | Medium | +|2547 | 差值数组不同的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/odd-string-difference.rs) | [leetcode](https://leetcode-cn.com/problems/odd-string-difference/) | Easy | |2551 | 对数组执行操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-operations-to-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/apply-operations-to-an-array/) | Easy | |2566 | 数组中不等三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-unequal-triplets-in-array.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-unequal-triplets-in-array/) | Easy | |2567 | 二叉搜索树最近节点查询 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/closest-nodes-queries-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/closest-nodes-queries-in-a-binary-search-tree/) | Medium | From bddd91638775a75cbd6e27f46f9e1a008fd57ffa Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 9 Apr 2024 20:05:37 +0800 Subject: [PATCH 1338/1556] src/bin/minimum-swaps-to-make-strings-equal.rs --- .../minimum-swaps-to-make-strings-equal.rs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/minimum-swaps-to-make-strings-equal.rs diff --git a/src/bin/minimum-swaps-to-make-strings-equal.rs b/src/bin/minimum-swaps-to-make-strings-equal.rs new file mode 100644 index 00000000..793c4d0e --- /dev/null +++ b/src/bin/minimum-swaps-to-make-strings-equal.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// s1[i] != s2[i] 的个数d + /// 如果个数为奇数,则永远不可能完成 + /// 如果个数为偶数,如果x和y的个数为偶数,则 d / 2 + /// 否则 d/2+1 + pub fn minimum_swap(s1: String, s2: String) -> i32 { + let mut x = 0; + let mut c_x = 0; + for i in 0..s1.len() { + if s1.as_bytes()[i] != s2.as_bytes()[i] { + x += 1; + + if s1.as_bytes()[i] == b'x' { + c_x += 1; + } + } + } + + if x % 2 == 1 { + -1 + } else { + if c_x % 2 == 0 { + x / 2 + } else { + x / 2 + 1 + } + } + } +} From c7201a051dc1104fb7ce2248af6d5c26df500b7c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 9 Apr 2024 20:05:38 +0800 Subject: [PATCH 1339/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 59da493e..eb579489 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 713 | 310 | 375 | 28 | +| 714 | 310 | 376 | 28 | ### 题目 @@ -383,6 +383,7 @@ |1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | |1363 | 兼具大小写的最好英文字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/greatest-english-letter-in-upper-and-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/greatest-english-letter-in-upper-and-lower-case/) | Easy | |1364 | 同积元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tuple-with-same-product.rs) | [leetcode](https://leetcode-cn.com/problems/tuple-with-same-product/) | Medium | +|1369 | 交换字符使得字符串相同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-swaps-to-make-strings-equal.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-swaps-to-make-strings-equal/) | Medium | |1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | |1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | |1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | From 2f4c8ea52a3cda2b9bd566d1644dd62355d481e3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 10 Apr 2024 20:50:56 +0800 Subject: [PATCH 1340/1556] src/bin/maximum-gap.rs --- src/bin/maximum-gap.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/bin/maximum-gap.rs diff --git a/src/bin/maximum-gap.rs b/src/bin/maximum-gap.rs new file mode 100644 index 00000000..5a02c6e9 --- /dev/null +++ b/src/bin/maximum-gap.rs @@ -0,0 +1,19 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_gap(nums: Vec) -> i32 { + let mut heap: std::collections::BinaryHeap = nums.into_iter().collect(); + let mut r = 0; + let mut prev = heap.pop().unwrap(); + while let Some(x) = heap.pop() { + r = r.max(prev - x); + prev = x; + } + + r + } +} From 051873df72ae53f33d8f20aba91dcac32231d0dc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 10 Apr 2024 20:50:56 +0800 Subject: [PATCH 1341/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eb579489..d6ef8436 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 714 | 310 | 376 | 28 | +| 715 | 310 | 377 | 28 | ### 题目 @@ -131,6 +131,7 @@ |154 | 寻找旋转排序数组中的最小值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-minimum-in-rotated-sorted-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii/) | Hard | |155 | 最小栈 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-stack.rs) | [leetcode](https://leetcode-cn.com/problems/min-stack/) | Medium | |162 | 寻找峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-peak-element.rs) | [leetcode](https://leetcode-cn.com/problems/find-peak-element/) | Medium | +|164 | 最大间距 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-gap.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-gap/) | Medium | |165 | 比较版本号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-version-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/compare-version-numbers/) | Medium | |166 | 分数到小数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fraction-to-recurring-decimal.rs) | [leetcode](https://leetcode-cn.com/problems/fraction-to-recurring-decimal/) | Medium | |167 | 两数之和 II - 输入有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-sum-ii-input-array-is-sorted.rs) | [leetcode](https://leetcode-cn.com/problems/two-sum-ii-input-array-is-sorted/) | Medium | From 02596ceb09e13da7c254964dbd9eebc895727a8a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 11 Apr 2024 20:49:21 +0800 Subject: [PATCH 1342/1556] src/bin/sort-integers-by-the-number-of-1-bits.rs --- .../sort-integers-by-the-number-of-1-bits.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/bin/sort-integers-by-the-number-of-1-bits.rs diff --git a/src/bin/sort-integers-by-the-number-of-1-bits.rs b/src/bin/sort-integers-by-the-number-of-1-bits.rs new file mode 100644 index 00000000..dfb829ab --- /dev/null +++ b/src/bin/sort-integers-by-the-number-of-1-bits.rs @@ -0,0 +1,18 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn sort_by_bits(arr: Vec) -> Vec { + let mut arr = arr; + + arr.sort_by(|x, y| match x.count_ones().cmp(&y.count_ones()) { + std::cmp::Ordering::Equal => x.cmp(y), + i => i, + }); + + arr + } +} From 244bb04ebe72f8f06bf58170b37c59c1164108c2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 11 Apr 2024 20:49:22 +0800 Subject: [PATCH 1343/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6ef8436..df2914da 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 715 | 310 | 377 | 28 | +| 716 | 311 | 377 | 28 | ### 题目 @@ -403,6 +403,7 @@ |1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | |1450 | 删除给定值的叶子节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/delete-leaves-with-a-given-value.rs) | [leetcode](https://leetcode-cn.com/problems/delete-leaves-with-a-given-value/) | Medium | |1455 | 餐厅过滤器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/filter-restaurants-by-vegan-friendly-price-and-distance.rs) | [leetcode](https://leetcode-cn.com/problems/filter-restaurants-by-vegan-friendly-price-and-distance/) | Medium | +|1458 | 根据数字二进制下 1 的数目排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-integers-by-the-number-of-1-bits.rs) | [leetcode](https://leetcode-cn.com/problems/sort-integers-by-the-number-of-1-bits/) | Easy | |1468 | 检查整数及其两倍数是否存在 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/) | Easy | |1472 | 上升下降字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increasing-decreasing-string.rs) | [leetcode](https://leetcode-cn.com/problems/increasing-decreasing-string/) | Easy | |1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | From b3deffbbd0497b2a9a109360e6a9dbe8cebfd220 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 12 Apr 2024 20:26:35 +0800 Subject: [PATCH 1344/1556] src/bin/implement-rand10-using-rand7.rs --- src/bin/implement-rand10-using-rand7.rs | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/bin/implement-rand10-using-rand7.rs diff --git a/src/bin/implement-rand10-using-rand7.rs b/src/bin/implement-rand10-using-rand7.rs new file mode 100644 index 00000000..18334e05 --- /dev/null +++ b/src/bin/implement-rand10-using-rand7.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +/** + * The rand7() API is already defined for you. + * @return a random integer in the range 1 to 7 + * fn rand7() -> i32; + */ + +fn rand7() -> i32 { + unimplemented!() +} + +impl Solution { + pub fn resolve() -> i32 { + (rand7() - 1) * 7 + rand7() - 1 + } + + pub fn rand10() -> i32 { + let mut pos = Self::resolve(); + while pos >= 40 { + pos = Self::resolve(); + } + + pos % 10 + 1 + } +} From 13059f7fe2c2f67e0ee7d4226a226bfd6aca7c3f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 12 Apr 2024 20:26:36 +0800 Subject: [PATCH 1345/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index df2914da..45700056 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 716 | 311 | 377 | 28 | +| 717 | 311 | 378 | 28 | ### 题目 @@ -315,6 +315,7 @@ |868 | 推多米诺 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/push-dominoes.rs) | [leetcode](https://leetcode-cn.com/problems/push-dominoes/) | Medium | |879 | 到最近的人的最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximize-distance-to-closest-person.rs) | [leetcode](https://leetcode-cn.com/problems/maximize-distance-to-closest-person/) | Medium | |890 | 柠檬水找零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lemonade-change.rs) | [leetcode](https://leetcode-cn.com/problems/lemonade-change/) | Easy | +|903 | 用 Rand7() 实现 Rand10() | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-rand10-using-rand7.rs) | [leetcode](https://leetcode-cn.com/problems/implement-rand10-using-rand7/) | Medium | |904 | 叶子相似的树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/leaf-similar-trees.rs) | [leetcode](https://leetcode-cn.com/problems/leaf-similar-trees/) | Easy | |905 | 最长的斐波那契子序列的长度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/length-of-longest-fibonacci-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/length-of-longest-fibonacci-subsequence/) | Medium | |906 | 模拟行走机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/walking-robot-simulation.rs) | [leetcode](https://leetcode-cn.com/problems/walking-robot-simulation/) | Medium | From f0b65cadd710bdb6cd9623dfc2e91519beabc2e5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 13 Apr 2024 11:25:47 +0800 Subject: [PATCH 1346/1556] src/bin/find-champion-ii.rs --- src/bin/find-champion-ii.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/find-champion-ii.rs diff --git a/src/bin/find-champion-ii.rs b/src/bin/find-champion-ii.rs new file mode 100644 index 00000000..219bb0cf --- /dev/null +++ b/src/bin/find-champion-ii.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_champion(n: i32, edges: Vec>) -> i32 { + use std::collections::HashSet; + + let mut s: HashSet<_> = edges.iter().map(|x| x[1]).collect(); + if s.len() != n as usize - 1 { + return -1; + } + + let mut result = None; + for i in edges { + if !s.contains(&i[0]) { + if result.is_some() && Some(i[0]) != result { + return -1; + } else { + result = Some(i[0]); + } + } + } + + result.unwrap_or(0) + } +} From 6f5b9becc0ff76895ae67fea099aff08b1318b1b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 13 Apr 2024 11:25:48 +0800 Subject: [PATCH 1347/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 45700056..25018501 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 717 | 311 | 378 | 28 | +| 718 | 311 | 379 | 28 | ### 题目 @@ -588,6 +588,7 @@ |3176 | 元素和最小的山形三元组 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sum-of-mountain-triplets-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sum-of-mountain-triplets-i/) | Easy | |3183 | 找出数组中的 K-or 值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-k-or-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-k-or-of-an-array/) | Easy | |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | +|3189 | 找到冠军 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-ii/) | Medium | |3231 | 需要添加的硬币的最小数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-coins-to-be-added.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-coins-to-be-added/) | Medium | |3275 | 输入单词需要的最少按键次数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-pushes-to-type-word-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-pushes-to-type-word-i/) | Easy | |3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | From 8c45b1442b18a5f4e6235690155212cdd31fd75a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 14 Apr 2024 23:20:27 +0800 Subject: [PATCH 1348/1556] src/bin/design-hashset.rs --- src/bin/design-hashset.rs | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/bin/design-hashset.rs diff --git a/src/bin/design-hashset.rs b/src/bin/design-hashset.rs new file mode 100644 index 00000000..76df8680 --- /dev/null +++ b/src/bin/design-hashset.rs @@ -0,0 +1,53 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ + +/** + * Your MyHashSet object will be instantiated and called as such: + * let obj = MyHashSet::new(); + * obj.add(key); + * obj.remove(key); + * let ret_3: bool = obj.contains(key); + */ + +struct MyHashSet { + data: Box>, +} + +impl MyHashSet { + const S: u8 = 0b10000000; + + fn new() -> Self { + Self { + data: Box::new(vec![0; 10usize.pow(6u32) / 8 + 1]), + } + } + + fn add(&mut self, key: i32) { + let index1 = key as usize / 8; + let index2 = key as usize % 8; + + self.data[index1] |= Self::S >> index2; + } + + fn remove(&mut self, key: i32) { + let index1 = key as usize / 8; + let index2 = key as usize % 8; + + self.data[index1] &= !(Self::S >> index2); + } + + fn contains(&self, key: i32) -> bool { + let index1 = key as usize / 8; + let index2 = key as usize % 8; + + self.data[index1] & Self::S >> index2 != 0 + } +} From e5d49323b33fe9d93028555ec6076c4410bed194 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 14 Apr 2024 23:20:27 +0800 Subject: [PATCH 1349/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 25018501..436a4aa0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 718 | 311 | 379 | 28 | +| 719 | 312 | 379 | 28 | ### 题目 @@ -302,6 +302,7 @@ |783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | |784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | +|816 | 设计哈希集合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-hashset.rs) | [leetcode](https://leetcode-cn.com/problems/design-hashset/) | Easy | |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | |834 | 模糊坐标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ambiguous-coordinates.rs) | [leetcode](https://leetcode-cn.com/problems/ambiguous-coordinates/) | Medium | From 7efbc49321f38f5a6d85eadca440c40af41c14f2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 15 Apr 2024 20:23:31 +0800 Subject: [PATCH 1350/1556] src/bin/design-hashmap.rs --- src/bin/design-hashmap.rs | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/bin/design-hashmap.rs diff --git a/src/bin/design-hashmap.rs b/src/bin/design-hashmap.rs new file mode 100644 index 00000000..2cd75fb3 --- /dev/null +++ b/src/bin/design-hashmap.rs @@ -0,0 +1,82 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ + +/** + * Your MyHashMap object will be instantiated and called as such: + * let obj = MyHashMap::new(); + * obj.put(key, value); + * let ret_2: i32 = obj.get(key); + * obj.remove(key); + */ + +struct Node { + key: i32, + value: i32, +} +struct MyHashMap { + array: Vec>, +} + +impl MyHashMap { + fn new() -> Self { + Self { + array: (0..1001) + .map(|_| std::collections::LinkedList::new()) + .collect(), + } + } + + fn put(&mut self, key: i32, value: i32) { + let index = key as usize / 1000; + let mut iter = self.array[index].iter_mut(); + + while let Some(n) = iter.next() { + if n.key == key { + n.value = value; + return; + } + } + + self.array[index].push_back(Node { key, value }); + } + + fn get(&self, key: i32) -> i32 { + let index = key as usize / 1000; + let mut iter = self.array[index].iter(); + + while let Some(n) = iter.next() { + if n.key == key { + return n.value; + } + } + + -1 + } + + fn remove(&mut self, key: i32) { + let index = key as usize / 1000; + let mut iter = self.array[index].iter(); + let mut x = None; + + for (i, n) in iter.enumerate() { + if n.key == key { + x = Some(i); + break; + } + } + + if let Some(x) = x { + let mut m = self.array[index].split_off(x); + m.pop_front(); + self.array[index].append(&mut m); + } + } +} From 97a8a37c6801b9ead661a4181d6341e91c7aa059 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 15 Apr 2024 20:23:31 +0800 Subject: [PATCH 1351/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 436a4aa0..4f6cafb6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 719 | 312 | 379 | 28 | +| 720 | 313 | 379 | 28 | ### 题目 @@ -303,6 +303,7 @@ |784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | |816 | 设计哈希集合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-hashset.rs) | [leetcode](https://leetcode-cn.com/problems/design-hashset/) | Easy | +|817 | 设计哈希映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-hashmap.rs) | [leetcode](https://leetcode-cn.com/problems/design-hashmap/) | Easy | |825 | 保持城市天际线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-increase-to-keep-city-skyline.rs) | [leetcode](https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/) | Medium | |829 | 子域名访问计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subdomain-visit-count.rs) | [leetcode](https://leetcode-cn.com/problems/subdomain-visit-count/) | Medium | |834 | 模糊坐标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/ambiguous-coordinates.rs) | [leetcode](https://leetcode-cn.com/problems/ambiguous-coordinates/) | Medium | From 5fad8421664f67dec1fa0065c04191a6d7f97e79 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 16 Apr 2024 20:59:00 +0800 Subject: [PATCH 1352/1556] src/bin/number-of-common-factors.rs --- src/bin/number-of-common-factors.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/bin/number-of-common-factors.rs diff --git a/src/bin/number-of-common-factors.rs b/src/bin/number-of-common-factors.rs new file mode 100644 index 00000000..d82811d0 --- /dev/null +++ b/src/bin/number-of-common-factors.rs @@ -0,0 +1,13 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn common_factors(a: i32, b: i32) -> i32 { + (1..=a.min(b)) + .filter(|x| a % *x == 0 && b % *x == 0) + .count() as i32 + } +} From 22403290813e9489d312c3d2bbf5b5c014644ce4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 16 Apr 2024 20:59:00 +0800 Subject: [PATCH 1353/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f6cafb6..ece7893a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 720 | 313 | 379 | 28 | +| 721 | 314 | 379 | 28 | ### 题目 @@ -509,6 +509,7 @@ |2473 | 数位和相等数对的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs) | [leetcode](https://leetcode-cn.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | |2482 | 被列覆盖的最多行数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-rows-covered-by-columns.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-rows-covered-by-columns/) | Medium | |2493 | 反转二叉树的奇数层 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-odd-levels-of-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-odd-levels-of-binary-tree/) | Medium | +|2507 | 公因子的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-common-factors.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-common-factors/) | Easy | |2509 | 最小异或 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimize-xor.rs) | [leetcode](https://leetcode-cn.com/problems/minimize-xor/) | Medium | |2518 | 处理用时最长的那个任务的员工 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/the-employee-that-worked-on-the-longest-task.rs) | [leetcode](https://leetcode-cn.com/problems/the-employee-that-worked-on-the-longest-task/) | Easy | |2519 | 找出前缀异或的原始数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-original-array-of-prefix-xor.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-original-array-of-prefix-xor/) | Medium | From 22b8474890e982ab7dda5faddab26e36ef39e403 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 17 Apr 2024 20:45:32 +0800 Subject: [PATCH 1354/1556] src/bin/divide-array-into-arrays-with-max-difference.rs --- ...e-array-into-arrays-with-max-difference.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/divide-array-into-arrays-with-max-difference.rs diff --git a/src/bin/divide-array-into-arrays-with-max-difference.rs b/src/bin/divide-array-into-arrays-with-max-difference.rs new file mode 100644 index 00000000..4755ec9f --- /dev/null +++ b/src/bin/divide-array-into-arrays-with-max-difference.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn divide_array(nums: Vec, k: i32) -> Vec> { + let mut nums = nums; + nums.sort(); + + let mut result = vec![]; + + for i in (2..nums.len()).step_by(3) { + if nums[i] - nums[i - 2] > k { + return vec![]; + } + + result.push(vec![nums[i], nums[i - 1], nums[i - 2]]); + } + + result + } +} From 9b94d25fc1d55cfd5e0455925ffee1921a165203 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 17 Apr 2024 20:45:33 +0800 Subject: [PATCH 1355/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ece7893a..e9daa47a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 721 | 314 | 379 | 28 | +| 722 | 314 | 380 | 28 | ### 题目 @@ -593,6 +593,7 @@ |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | |3189 | 找到冠军 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-ii/) | Medium | |3231 | 需要添加的硬币的最小数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-coins-to-be-added.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-coins-to-be-added/) | Medium | +|3241 | 划分数组并满足最大差限制 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/divide-array-into-arrays-with-max-difference.rs) | [leetcode](https://leetcode-cn.com/problems/divide-array-into-arrays-with-max-difference/) | Medium | |3275 | 输入单词需要的最少按键次数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-pushes-to-type-word-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-pushes-to-type-word-i/) | Easy | |3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | From 4f0dd996cbb8e8f5f4ea6efd5a834417e6dfacfc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Apr 2024 20:57:19 +0800 Subject: [PATCH 1356/1556] src/bin/find-original-array-from-doubled-array.rs --- .../find-original-array-from-doubled-array.rs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/find-original-array-from-doubled-array.rs diff --git a/src/bin/find-original-array-from-doubled-array.rs b/src/bin/find-original-array-from-doubled-array.rs new file mode 100644 index 00000000..e37c48dd --- /dev/null +++ b/src/bin/find-original-array-from-doubled-array.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_original_array(changed: Vec) -> Vec { + let mut changed = changed; + changed.sort(); + let mut map = std::collections::HashMap::new(); + let mut result = vec![]; + + for i in changed { + if let Some(x) = map.get_mut(&i) { + if *x > 0 { + *x -= 1; + } + + if *x == 0 { + map.remove(&i); + } + } else { + result.push(i); + map.entry(i * 2).and_modify(|x| *x += 1).or_insert(1); + } + } + + if map.is_empty() { + result + } else { + vec![] + } + } +} From f2d647bb33ca8a9a114abbd1bc691e463108a381 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 18 Apr 2024 20:57:19 +0800 Subject: [PATCH 1357/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e9daa47a..d62d3f4a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 722 | 314 | 380 | 28 | +| 723 | 314 | 381 | 28 | ### 题目 @@ -474,6 +474,7 @@ |2053 | 检查是否所有字符出现次数相同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-all-characters-have-equal-number-of-occurrences.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-all-characters-have-equal-number-of-occurrences/) | Easy | |2094 | 移除石子使总数最小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-stones-to-minimize-the-total.rs) | [leetcode](https://leetcode-cn.com/problems/remove-stones-to-minimize-the-total/) | Medium | |2104 | 树上的操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/operations-on-tree.rs) | [leetcode](https://leetcode-cn.com/problems/operations-on-tree/) | Medium | +|2117 | 从双倍数组中还原原数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-original-array-from-doubled-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-original-array-from-doubled-array/) | Medium | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | |2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | |2161 | 股票价格波动 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/stock-price-fluctuation.rs) | [leetcode](https://leetcode-cn.com/problems/stock-price-fluctuation/) | Medium | From 22861b52d9266487161d1c79bfbc7537b89e6880 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 19 Apr 2024 21:09:44 +0800 Subject: [PATCH 1358/1556] src/bin/merge-two-2d-arrays-by-summing-values.rs --- .../merge-two-2d-arrays-by-summing-values.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/merge-two-2d-arrays-by-summing-values.rs diff --git a/src/bin/merge-two-2d-arrays-by-summing-values.rs b/src/bin/merge-two-2d-arrays-by-summing-values.rs new file mode 100644 index 00000000..a64b7baa --- /dev/null +++ b/src/bin/merge-two-2d-arrays-by-summing-values.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn merge_arrays(nums1: Vec>, nums2: Vec>) -> Vec> { + let mut result = vec![]; + let (mut i, mut j) = (0, 0); + + while i < nums1.len() && j < nums2.len() { + if nums1[i][0] < nums2[j][0] { + result.push(nums1[i].clone()); + i += 1; + } else if nums1[i][0] > nums2[j][0] { + result.push(nums2[j].clone()); + j += 1; + } else { + result.push(vec![nums1[i][0], nums1[i][1] + nums2[j][1]]); + i += 1; + j += 1; + } + } + + if i < nums1.len() { + result.extend_from_slice(&nums1[i..]); + } + + if j < nums2.len() { + result.extend_from_slice(&nums2[j..]); + } + + result + } +} From 151b8c6c34c9153e9e73f400937b5a0ba103b931 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 19 Apr 2024 21:09:44 +0800 Subject: [PATCH 1359/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d62d3f4a..86eacaff 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 723 | 314 | 381 | 28 | +| 724 | 315 | 381 | 28 | ### 题目 @@ -551,6 +551,7 @@ |2692 | 从数量最多的堆取走礼物 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/take-gifts-from-the-richest-pile.rs) | [leetcode](https://leetcode-cn.com/problems/take-gifts-from-the-richest-pile/) | Easy | |2694 | 找出可整除性得分最大的整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-divisibility-score.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-divisibility-score/) | Easy | |2698 | 找出数组的串联值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-array-concatenation-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-array-concatenation-value/) | Easy | +|2707 | 合并两个二维数组 - 求和法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-2d-arrays-by-summing-values.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-2d-arrays-by-summing-values/) | Easy | |2713 | 找出字符串的可整除数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-divisibility-array-of-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-divisibility-array-of-a-string/) | Medium | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | |2723 | 最长平衡子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-longest-balanced-substring-of-a-binary-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-longest-balanced-substring-of-a-binary-string/) | Easy | From 1e5579175cda78990fc9896e405fd1c1d6bab21b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 20 Apr 2024 12:25:17 +0800 Subject: [PATCH 1360/1556] src/bin/partition-list.rs --- src/bin/partition-list.rs | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/bin/partition-list.rs diff --git a/src/bin/partition-list.rs b/src/bin/partition-list.rs new file mode 100644 index 00000000..2508965f --- /dev/null +++ b/src/bin/partition-list.rs @@ -0,0 +1,44 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} +impl Solution { + pub fn partition(head: Option>, x: i32) -> Option> { + let (mut l1, mut l2) = (ListNode::new(-1), ListNode::new(-1)); + let (mut ptr1, mut ptr2) = (&mut l1.next, &mut l2.next); + + let mut head = head; + + while head.is_some() { + let mut h = head.unwrap(); + head = h.next.take(); + + if h.val < x { + *ptr1 = Some(h); + ptr1 = ptr1.as_mut().map(|mut x| &mut x.next).unwrap(); + } else { + *ptr2 = Some(h); + ptr2 = ptr2.as_mut().map(|mut x| &mut x.next).unwrap(); + } + } + + *ptr1 = l2.next.take(); + + l1.next + } +} From c209f4de9af450086f5d38b43706e1b565185ee3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 20 Apr 2024 12:25:17 +0800 Subject: [PATCH 1361/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 86eacaff..7afa6e71 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 724 | 315 | 381 | 28 | +| 725 | 315 | 382 | 28 | ### 题目 @@ -85,6 +85,7 @@ |83 | 删除排序链表中的重复元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicates-from-sorted-list.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/) | Easy | |84 | 柱状图中最大的矩形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-rectangle-in-histogram.rs) | [leetcode](https://leetcode-cn.com/problems/largest-rectangle-in-histogram/) | Hard | |85 | 最大矩形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-rectangle.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-rectangle/) | Hard | +|86 | 分隔链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/partition-list.rs) | [leetcode](https://leetcode-cn.com/problems/partition-list/) | Medium | |87 | 扰乱字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/scramble-string.rs) | [leetcode](https://leetcode-cn.com/problems/scramble-string/) | Hard | |88 | 合并两个有序数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-sorted-array.rs) | [leetcode](https://leetcode-cn.com/problems/merge-sorted-array/) | Easy | |89 | 格雷编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/gray-code.rs) | [leetcode](https://leetcode-cn.com/problems/gray-code/) | Medium | From e79a31e7204e0b8af9ff598c10bb8e85a9935dc0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 21 Apr 2024 10:31:57 +0800 Subject: [PATCH 1362/1556] src/bin/longest-palindromic-subsequence.rs --- src/bin/longest-palindromic-subsequence.rs | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/bin/longest-palindromic-subsequence.rs diff --git a/src/bin/longest-palindromic-subsequence.rs b/src/bin/longest-palindromic-subsequence.rs new file mode 100644 index 00000000..31e68062 --- /dev/null +++ b/src/bin/longest-palindromic-subsequence.rs @@ -0,0 +1,49 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn longest_palindrome_subseq(s: String) -> i32 { + let mut dp = vec![]; + for i in 0..s.len() { + dp.push(vec![-1; s.len()]); + } + + Self::dfs(s.as_bytes(), &mut dp, 0, s.len() - 1); + + dp[0][s.len() - 1] + } + + pub fn dfs(s: &[u8], v: &mut [Vec], i: usize, j: usize) { + if v[i][j] != -1 { + return; + } + + if i == j { + v[i][j] = 1; + return; + } + + if i > j { + v[i][j] = 0; + return; + } + + if j == 0 || i == s.len() - 1 { + v[i][j] = 0; + return; + } + + if s[i] == s[j] { + Self::dfs(s, v, i + 1, j - 1); + v[i][j] = v[i + 1][j - 1] + 2; + } else { + Self::dfs(s, v, i + 1, j); + Self::dfs(s, v, i, j - 1); + + v[i][j] = v[i + 1][j].max(v[i][j - 1]); + } + } +} From 56abcfde78116a2c7fa00edadd02fdbe92e1424e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 21 Apr 2024 10:31:58 +0800 Subject: [PATCH 1363/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7afa6e71..30108fe8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 725 | 315 | 382 | 28 | +| 726 | 315 | 383 | 28 | ### 题目 @@ -264,6 +264,7 @@ |508 | 出现次数最多的子树元素和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-frequent-subtree-sum.rs) | [leetcode](https://leetcode-cn.com/problems/most-frequent-subtree-sum/) | Medium | |513 | 找树左下角的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-bottom-left-tree-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-bottom-left-tree-value/) | Medium | |515 | 在每个树行中找最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-largest-value-in-each-tree-row.rs) | [leetcode](https://leetcode-cn.com/problems/find-largest-value-in-each-tree-row/) | Medium | +|516 | 最长回文子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindromic-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindromic-subsequence/) | Medium | |518 | 零钱兑换 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change-ii.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change-ii/) | Medium | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | From ac0c1e21034f9f6f1d79e16ceb41dd45ff68e1a4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 22 Apr 2024 20:23:04 +0800 Subject: [PATCH 1364/1556] src/bin/combination-sum-iv.rs --- src/bin/combination-sum-iv.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/combination-sum-iv.rs diff --git a/src/bin/combination-sum-iv.rs b/src/bin/combination-sum-iv.rs new file mode 100644 index 00000000..f1f85b84 --- /dev/null +++ b/src/bin/combination-sum-iv.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn combination_sum4(nums: Vec, target: i32) -> i32 { + Self::dp(&mut std::collections::HashMap::new(), &nums, target) + } + + pub fn dp(hash: &mut std::collections::HashMap, nums: &[i32], target: i32) -> i32 { + if let Some(x) = hash.get(&target) { + return *x; + } + + if target == 0 { + return 1; + } else if target < 0 { + return 0; + } + + let mut result = 0; + for &i in nums { + result += Self::dp(hash, nums, target - i); + } + + hash.insert(target, result); + + result + } +} From 426f7be25c753d65eafa006cbf35ff26ccc8cca4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 22 Apr 2024 20:23:04 +0800 Subject: [PATCH 1365/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 30108fe8..4b3c7365 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 726 | 315 | 383 | 28 | +| 727 | 315 | 384 | 28 | ### 题目 @@ -216,6 +216,7 @@ |371 | 两整数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-two-integers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-two-integers/) | Medium | |374 | 猜数字大小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/guess-number-higher-or-lower.rs) | [leetcode](https://leetcode-cn.com/problems/guess-number-higher-or-lower/) | Easy | |376 | 摆动序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/wiggle-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/wiggle-subsequence/) | Medium | +|377 | 组合总和 Ⅳ | [src](https://github.com/rustors/leetcode/blob/main/src/bin/combination-sum-iv.rs) | [leetcode](https://leetcode-cn.com/problems/combination-sum-iv/) | Medium | |378 | 有序矩阵中第 K 小的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/kth-smallest-element-in-a-sorted-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/) | Medium | |380 | O(1) 时间插入、删除和获取随机元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1/) | Medium | |381 | O(1) 时间插入、删除和获取随机元素 - 允许重复 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-delete-getrandom-o1-duplicates-allowed.rs) | [leetcode](https://leetcode-cn.com/problems/insert-delete-getrandom-o1-duplicates-allowed/) | Hard | From 44a4b33b27c6f14308da149d05f059c7a6fd06a1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 23 Apr 2024 20:35:38 +0800 Subject: [PATCH 1366/1556] src/bin/grumpy-bookstore-owner.rs --- src/bin/grumpy-bookstore-owner.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/bin/grumpy-bookstore-owner.rs diff --git a/src/bin/grumpy-bookstore-owner.rs b/src/bin/grumpy-bookstore-owner.rs new file mode 100644 index 00000000..e3b094e2 --- /dev/null +++ b/src/bin/grumpy-bookstore-owner.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_satisfied(customers: Vec, grumpy: Vec, minutes: i32) -> i32 { + let mut sum = 0; + let mut customers = customers; + + for i in 0..customers.len() { + if grumpy[i] == 0 { + sum += customers[i]; + customers[i] = 0; + } + + if i > 0 { + customers[i] += customers[i - 1]; + } + } + + let mut x = customers[minutes as usize - 1]; + for i in minutes as usize..customers.len() { + x = x.max(customers[i] - customers[i - minutes as usize]); + } + + sum + x + } +} From 0c7acce5a94a1b3b50450a8484c05c89c5114aff Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 23 Apr 2024 20:35:39 +0800 Subject: [PATCH 1367/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b3c7365..b6267ff5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 727 | 315 | 384 | 28 | +| 728 | 315 | 385 | 28 | ### 题目 @@ -364,6 +364,7 @@ |1114 | 从二叉搜索树到更大和树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/binary-search-tree-to-greater-sum-tree.rs) | [leetcode](https://leetcode-cn.com/problems/binary-search-tree-to-greater-sum-tree/) | Medium | |1119 | 困于环中的机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/robot-bounded-in-circle.rs) | [leetcode](https://leetcode-cn.com/problems/robot-bounded-in-circle/) | Medium | |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | +|1138 | 爱生气的书店老板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/grumpy-bookstore-owner.rs) | [leetcode](https://leetcode-cn.com/problems/grumpy-bookstore-owner/) | Medium | |1146 | 字符串的最大公因子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/greatest-common-divisor-of-strings.rs) | [leetcode](https://leetcode-cn.com/problems/greatest-common-divisor-of-strings/) | Easy | |1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | |1168 | 复写零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/duplicate-zeros.rs) | [leetcode](https://leetcode-cn.com/problems/duplicate-zeros/) | Easy | From 29275cfe658d8b43e4191929d32fc88fddd02977 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 24 Apr 2024 20:57:33 +0800 Subject: [PATCH 1368/1556] src/bin/amount-of-time-for-binary-tree-to-be-infected.rs --- ...-of-time-for-binary-tree-to-be-infected.rs | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/bin/amount-of-time-for-binary-tree-to-be-infected.rs diff --git a/src/bin/amount-of-time-for-binary-tree-to-be-infected.rs b/src/bin/amount-of-time-for-binary-tree-to-be-infected.rs new file mode 100644 index 00000000..a3c0d3d9 --- /dev/null +++ b/src/bin/amount-of-time-for-binary-tree-to-be-infected.rs @@ -0,0 +1,76 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +impl Solution { + /// hashmap记录与节点所有相连的值 + /// 然后在dfs这个hashmap + pub fn amount_of_time(root: Option>>, start: i32) -> i32 { + let mut hash = std::collections::HashMap::>::new(); + + Self::dfs1(&mut hash, root, None); + Self::dfs2(&hash, start, -1) + } + + pub fn dfs1( + hash: &mut std::collections::HashMap>, + root: Option>>, + parent: Option, + ) { + if root.is_none() { + return; + } + + let root = root.unwrap(); + let value = root.borrow().val; + + if let Some(i) = parent { + hash.entry(value).or_insert(vec![]).push(i); + hash.entry(i).or_insert(vec![]).push(value); + } + + Self::dfs1(hash, root.borrow_mut().left.take(), Some(value)); + Self::dfs1(hash, root.borrow_mut().right.take(), Some(value)); + } + + pub fn dfs2(hash: &std::collections::HashMap>, start: i32, last: i32) -> i32 { + match hash.get(&start) { + Some(v) => { + let mut r = 0; + for &i in v { + if i == last { + continue; + } + r = r.max(1 + Self::dfs2(hash, i, start)); + } + + r + } + None => 0, + } + } +} From 66e801b908ea870dd827d696d284b896c3f49cc1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 24 Apr 2024 20:57:34 +0800 Subject: [PATCH 1369/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b6267ff5..0cd8faf2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 728 | 315 | 385 | 28 | +| 729 | 315 | 386 | 28 | ### 题目 @@ -510,6 +510,7 @@ |2413 | 无限集中的最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-number-in-infinite-set.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-number-in-infinite-set/) | Medium | |2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | |2442 | 算术三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-arithmetic-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-arithmetic-triplets/) | Easy | +|2461 | 感染二叉树需要的总时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/amount-of-time-for-binary-tree-to-be-infected.rs) | [leetcode](https://leetcode-cn.com/problems/amount-of-time-for-binary-tree-to-be-infected/) | Medium | |2470 | 从字符串中移除星号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-stars-from-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/removing-stars-from-a-string/) | Medium | |2473 | 数位和相等数对的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs) | [leetcode](https://leetcode-cn.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | |2482 | 被列覆盖的最多行数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-rows-covered-by-columns.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-rows-covered-by-columns/) | Medium | From 1e053e958b6ed689067b4cf86e557c8e8b272cc1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 25 Apr 2024 20:30:33 +0800 Subject: [PATCH 1370/1556] src/bin/total-distance-traveled.rs --- src/bin/total-distance-traveled.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/total-distance-traveled.rs diff --git a/src/bin/total-distance-traveled.rs b/src/bin/total-distance-traveled.rs new file mode 100644 index 00000000..1d964065 --- /dev/null +++ b/src/bin/total-distance-traveled.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn distance_traveled(main_tank: i32, additional_tank: i32) -> i32 { + let (mut main_tank, mut additional_tank) = (main_tank, additional_tank); + let mut result = 0; + + while main_tank > 0 { + if main_tank >= 5 { + main_tank -= 5; + result += 50; + if additional_tank > 0 { + main_tank += 1; + additional_tank -= 1; + } + } else { + result += main_tank * 10; + main_tank = 0; + } + } + + result + } +} From f814442d6d4ec25537af20eee60684e8dc0ab7a6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 25 Apr 2024 20:30:33 +0800 Subject: [PATCH 1371/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0cd8faf2..983ff20f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 729 | 315 | 386 | 28 | +| 730 | 316 | 386 | 28 | ### 题目 @@ -580,6 +580,7 @@ |2816 | 字典序最小回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographically-smallest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographically-smallest-palindrome/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |2847 | 最大字符串配对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-maximum-number-of-string-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/find-maximum-number-of-string-pairs/) | Easy | +|2857 | 总行驶距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/total-distance-traveled.rs) | [leetcode](https://leetcode-cn.com/problems/total-distance-traveled/) | Easy | |2866 | 最长奇偶子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-even-odd-subarray-with-threshold.rs) | [leetcode](https://leetcode-cn.com/problems/longest-even-odd-subarray-with-threshold/) | Easy | |2870 | 最长交替子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-alternating-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/longest-alternating-subarray/) | Easy | |2872 | 合并后数组中的最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-element-in-an-array-after-merge-operations.rs) | [leetcode](https://leetcode-cn.com/problems/largest-element-in-an-array-after-merge-operations/) | Medium | From 22ccbc4bc55b03da8d03006fe880dc6528015cd9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 26 Apr 2024 20:49:21 +0800 Subject: [PATCH 1372/1556] src/bin/all-possible-full-binary-trees.rs --- src/bin/all-possible-full-binary-trees.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin/all-possible-full-binary-trees.rs b/src/bin/all-possible-full-binary-trees.rs index 1e13fa97..26932724 100644 --- a/src/bin/all-possible-full-binary-trees.rs +++ b/src/bin/all-possible-full-binary-trees.rs @@ -59,4 +59,3 @@ impl Solution { v } } - From 0c43d11015632d649cc2ba4f53fce9083fc5efa6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 26 Apr 2024 20:49:21 +0800 Subject: [PATCH 1373/1556] src/bin/snapshot-array.rs --- src/bin/snapshot-array.rs | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/bin/snapshot-array.rs diff --git a/src/bin/snapshot-array.rs b/src/bin/snapshot-array.rs new file mode 100644 index 00000000..71e891c7 --- /dev/null +++ b/src/bin/snapshot-array.rs @@ -0,0 +1,64 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ + +/** + * Your SnapshotArray object will be instantiated and called as such: + * let obj = SnapshotArray::new(length); + * obj.set(index, val); + * let ret_2: i32 = obj.snap(); + * let ret_3: i32 = obj.get(index, snap_id); + */ + +struct SnapshotArray { + snapshot_id: std::cell::Cell, + storage: Vec>, +} + +impl SnapshotArray { + fn new(length: i32) -> Self { + Self { + snapshot_id: std::cell::Cell::new(0), + storage: { + let mut data = Vec::with_capacity(length as usize); + for _ in 0..length { + data.push(vec![]); + } + data + }, + } + } + + fn set(&mut self, index: i32, val: i32) { + if let Some(x) = self.storage[index as usize].last_mut() { + if x.0 == self.snapshot_id.get() { + x.1 = val; + return; + } + } + + self.storage[index as usize].push((self.snapshot_id.get(), val)); + } + + fn snap(&self) -> i32 { + self.snapshot_id.set(self.snapshot_id.get() + 1); + self.snapshot_id.get() - 1 + } + + fn get(&self, index: i32, snap_id: i32) -> i32 { + let s = self.storage.get(index as usize).unwrap(); + let i = s.partition_point(|x| x.0 <= snap_id); + if i > 0 { + s[i - 1].1 + } else { + 0 + } + } +} From ea893f356bffbd31855f3a8a65f4333d3b0241e5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 26 Apr 2024 20:49:22 +0800 Subject: [PATCH 1374/1556] README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 983ff20f..beed9aac 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 730 | 316 | 386 | 28 | +| 732 | 316 | 388 | 28 | ### 题目 @@ -332,6 +332,7 @@ |928 | 三维形体的表面积 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/surface-area-of-3d-shapes.rs) | [leetcode](https://leetcode-cn.com/problems/surface-area-of-3d-shapes/) | Easy | |930 | 所有可能的真二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-possible-full-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/all-possible-full-binary-trees/) | Medium | |930 | 所有可能的真二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-possible-full-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/all-possible-full-binary-trees/) | Medium | +|930 | 所有可能的真二叉树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-possible-full-binary-trees.rs) | [leetcode](https://leetcode-cn.com/problems/all-possible-full-binary-trees/) | Medium | |932 | 单调数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/monotonic-array.rs) | [leetcode](https://leetcode-cn.com/problems/monotonic-array/) | Easy | |936 | RLE 迭代器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rle-iterator.rs) | [leetcode](https://leetcode-cn.com/problems/rle-iterator/) | Medium | |937 | 股票价格跨度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/online-stock-span.rs) | [leetcode](https://leetcode-cn.com/problems/online-stock-span/) | Medium | @@ -373,6 +374,7 @@ |1218 | 最深叶节点的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-deepest-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves/) | Medium | |1236 | 第 N 个泰波那契数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-th-tribonacci-number.rs) | [leetcode](https://leetcode-cn.com/problems/n-th-tribonacci-number/) | Easy | |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | +|1249 | 快照数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/snapshot-array.rs) | [leetcode](https://leetcode-cn.com/problems/snapshot-array/) | Medium | |1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | |1260 | 一年中的第几天 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/day-of-the-year.rs) | [leetcode](https://leetcode-cn.com/problems/day-of-the-year/) | Easy | |1263 | 掷骰子等于目标和的方法数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-dice-rolls-with-target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-dice-rolls-with-target-sum/) | Medium | From 645501f0e5259da233a0ff0e271ea6d40d2e2c6b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 27 Apr 2024 22:31:39 +0800 Subject: [PATCH 1375/1556] src/bin/find-the-width-of-columns-of-a-grid.rs --- .../find-the-width-of-columns-of-a-grid.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/find-the-width-of-columns-of-a-grid.rs diff --git a/src/bin/find-the-width-of-columns-of-a-grid.rs b/src/bin/find-the-width-of-columns-of-a-grid.rs new file mode 100644 index 00000000..4cee0d87 --- /dev/null +++ b/src/bin/find-the-width-of-columns-of-a-grid.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_column_width(grid: Vec>) -> Vec { + let mut result = vec![]; + + for i in 0..grid[0].len() { + let mut r = -1; + for j in 0..grid.len() { + r = r.max(grid[j][i].to_string().len() as i32); + } + result.push(r); + } + + result + } +} From fcb37ca4951d67d3f456bee0e72cd5ff344ebeee Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 27 Apr 2024 22:31:39 +0800 Subject: [PATCH 1376/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index beed9aac..624ae7c9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 732 | 316 | 388 | 28 | +| 733 | 317 | 388 | 28 | ### 题目 @@ -549,6 +549,7 @@ |2663 | 将钱分给最多的儿童 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-money-to-maximum-children.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-money-to-maximum-children/) | Easy | |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | |2668 | 从两个数字数组里生成最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/form-smallest-number-from-two-digit-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/form-smallest-number-from-two-digit-arrays/) | Easy | +|2675 | 查询网格图中每一列的宽度 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-width-of-columns-of-a-grid.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-width-of-columns-of-a-grid/) | Easy | |2676 | 一个数组所有前缀的分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-score-of-all-prefixes-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-score-of-all-prefixes-of-an-array/) | Medium | |2679 | 统计桌面上的不同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-distinct-numbers-on-board.rs) | [leetcode](https://leetcode-cn.com/problems/count-distinct-numbers-on-board/) | Easy | |2684 | 保龄球游戏的获胜者 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/determine-the-winner-of-a-bowling-game.rs) | [leetcode](https://leetcode-cn.com/problems/determine-the-winner-of-a-bowling-game/) | Easy | From a312a147f1f9ae4360e534f99734d1bb32588413 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 28 Apr 2024 19:56:37 +0800 Subject: [PATCH 1377/1556] src/bin/convert-to-base-2.rs --- src/bin/convert-to-base-2.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/bin/convert-to-base-2.rs diff --git a/src/bin/convert-to-base-2.rs b/src/bin/convert-to-base-2.rs new file mode 100644 index 00000000..c0263c98 --- /dev/null +++ b/src/bin/convert-to-base-2.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn base_neg2(n: i32) -> String { + if n == 0 { + return "0".into(); + } + let mut s = String::new(); + let mut n = n; + while n != 0 { + let mut x = n % (-2); + n /= -2; + if x == -1 { + n += 1; + x = 1; + } + + s.push_str(&x.to_string()); + } + + unsafe { + s.as_bytes_mut().reverse(); + } + s + } +} From c17247b54f646c1d1890cdfe39278d208102095f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 28 Apr 2024 19:56:37 +0800 Subject: [PATCH 1378/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 624ae7c9..6e35b49f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 733 | 317 | 388 | 28 | +| 734 | 317 | 389 | 28 | ### 题目 @@ -359,6 +359,7 @@ |1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | |1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | +|1070 | 负二进制转换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-to-base-2.rs) | [leetcode](https://leetcode-cn.com/problems/convert-to-base-2/) | Medium | |1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | |1079 | 从根到叶的二进制数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-root-to-leaf-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-root-to-leaf-binary-numbers/) | Easy | |1092 | 节点与其祖先之间的最大差值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-difference-between-node-and-ancestor.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-difference-between-node-and-ancestor/) | Medium | From 745590a2bc6a6459fb0c4ab04c2a68b3ef7cd7eb Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 29 Apr 2024 20:38:23 +0800 Subject: [PATCH 1379/1556] src/bin/maximum-sum-of-almost-unique-subarray.rs --- .../maximum-sum-of-almost-unique-subarray.rs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/bin/maximum-sum-of-almost-unique-subarray.rs diff --git a/src/bin/maximum-sum-of-almost-unique-subarray.rs b/src/bin/maximum-sum-of-almost-unique-subarray.rs new file mode 100644 index 00000000..1134ee32 --- /dev/null +++ b/src/bin/maximum-sum-of-almost-unique-subarray.rs @@ -0,0 +1,42 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::max_sum(vec![2, 6, 7, 3, 1, 7], 3, 4), 18); + assert_eq!(Solution::max_sum(vec![5, 9, 9, 2, 4, 5, 4], 1, 3), 23); + assert_eq!(Solution::max_sum(vec![1, 2, 1, 2, 1, 2, 1], 3, 3), 0); +} + +struct Solution; + +impl Solution { + pub fn max_sum(nums: Vec, m: i32, k: i32) -> i64 { + let mut hash = std::collections::HashMap::new(); + let mut result = 0; + let mut sum = 0; + for i in 0..nums.len() { + hash.entry(nums[i]).and_modify(|x| *x += 1).or_insert(1); + if i < k as usize { + sum += nums[i] as i64; + } else { + sum += (nums[i] - nums[i - k as usize]) as i64; + let c = if let Some(&x) = hash.get(&nums[i - k as usize]) { + x + } else { + -1 + }; + + if c == 1 { + hash.remove(&nums[i - k as usize]); + } else if c > 1 { + hash.insert(nums[i - k as usize], c - 1); + } + } + + if hash.len() >= m as usize { + result = result.max(sum); + } + } + + result + } +} From 8351460805933407ad87abc5f497fae19cf17a2f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 29 Apr 2024 20:38:23 +0800 Subject: [PATCH 1380/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e35b49f..3ba0a432 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 734 | 317 | 389 | 28 | +| 735 | 317 | 390 | 28 | ### 题目 @@ -592,6 +592,7 @@ |2886 | 故障键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/faulty-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/faulty-keyboard/) | Easy | |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | |2920 | 使循环数组所有元素相等的最少秒数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-seconds-to-equalize-a-circular-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-seconds-to-equalize-a-circular-array/) | Medium | +|2954 | 几乎唯一子数组的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-of-almost-unique-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-of-almost-unique-subarray/) | Medium | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | |3026 | 找出美丽数组的最小和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-minimum-possible-sum-of-a-beautiful-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-minimum-possible-sum-of-a-beautiful-array/) | Medium | |3045 | 使数组成为递增数组的最少右移次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-right-shifts-to-sort-the-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-right-shifts-to-sort-the-array/) | Easy | From 0735b4042c031ddace97ea35885332ed457cfa0e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 5 May 2024 12:34:09 +0800 Subject: [PATCH 1381/1556] src/bin/defuse-the-bomb.rs --- src/bin/defuse-the-bomb.rs | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/bin/defuse-the-bomb.rs diff --git a/src/bin/defuse-the-bomb.rs b/src/bin/defuse-the-bomb.rs new file mode 100644 index 00000000..91d84071 --- /dev/null +++ b/src/bin/defuse-the-bomb.rs @@ -0,0 +1,47 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::decrypt(vec![5, 7, 1, 4], 3), vec![12, 10, 16, 13]); + assert_eq!(Solution::decrypt(vec![1, 2, 3, 4], 0), vec![0, 0, 0, 0]); + assert_eq!(Solution::decrypt(vec![2, 4, 9, 3], -2), vec![12, 5, 6, 13]); +} + +struct Solution; + +impl Solution { + pub fn decrypt(code: Vec, k: i32) -> Vec { + let mut result = vec![0; code.len()]; + let mut code = code; + + for i in 1..code.len() { + code[i] += code[i - 1]; + } + + for i in 0..code.len() { + match k { + 0 => result[i] = 0, + _x if _x > 0 => { + if (i + k as usize) < code.len() { + result[i] = code[i + k as usize] - code[i]; + } else { + result[i] += code[code.len() - 1] - code[i]; + result[i] += code[k as usize - (code.len() - 1 - i) - 1]; + } + } + _ => { + let k = -k; + if i >= k as usize + 1 { + result[i] = code[i - 1] - code[i - k as usize - 1]; + } else { + result[i] += code[code.len() - 1] - code[code.len() - 1 - (k as usize - i)]; + if i != 0 { + result[i] += code[i - 1]; + } + } + } + } + } + + result + } +} From 5dc17e3d8a161db15d7f3aff6ddf2c92a8477505 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 5 May 2024 12:34:09 +0800 Subject: [PATCH 1382/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ba0a432..1948c301 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 735 | 317 | 390 | 28 | +| 736 | 318 | 390 | 28 | ### 题目 @@ -446,6 +446,7 @@ |1677 | 矩阵对角线元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/matrix-diagonal-sum.rs) | [leetcode](https://leetcode-cn.com/problems/matrix-diagonal-sum/) | Easy | |1689 | 重复至少 K 次且长度为 M 的模式 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-pattern-of-length-m-repeated-k-or-more-times.rs) | [leetcode](https://leetcode-cn.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times/) | Easy | |1722 | 王位继承顺序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/throne-inheritance.rs) | [leetcode](https://leetcode-cn.com/problems/throne-inheritance/) | Medium | +|1755 | 拆炸弹 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/defuse-the-bomb.rs) | [leetcode](https://leetcode-cn.com/problems/defuse-the-bomb/) | Easy | |1764 | 最大重复子字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-repeating-substring.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-repeating-substring/) | Easy | |1767 | 设计前中后队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-front-middle-back-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-front-middle-back-queue/) | Medium | |1777 | 确定两个字符串是否接近 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/determine-if-two-strings-are-close.rs) | [leetcode](https://leetcode-cn.com/problems/determine-if-two-strings-are-close/) | Medium | From 65bce7847f9aa70ff936975646199d50879fcb99 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 May 2024 08:37:39 +0800 Subject: [PATCH 1383/1556] src/bin/find-the-highest-altitude.rs --- src/bin/find-the-highest-altitude.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/bin/find-the-highest-altitude.rs diff --git a/src/bin/find-the-highest-altitude.rs b/src/bin/find-the-highest-altitude.rs new file mode 100644 index 00000000..960997e3 --- /dev/null +++ b/src/bin/find-the-highest-altitude.rs @@ -0,0 +1,19 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn largest_altitude(gain: Vec) -> i32 { + let mut current = 0; + let mut result = 0; + + for i in gain { + result = result.max(current + i); + current = current + i; + } + + result + } +} From 8a315daeb42a5d6f82b8590435d277fde5914850 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 6 May 2024 08:37:40 +0800 Subject: [PATCH 1384/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1948c301..b89eb468 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 736 | 318 | 390 | 28 | +| 737 | 319 | 390 | 28 | ### 题目 @@ -459,6 +459,7 @@ |1814 | 跳跃游戏 VI | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-vi.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-vi/) | Medium | |1817 | 计算力扣银行的钱 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-money-in-leetcode-bank.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-money-in-leetcode-bank/) | Easy | |1829 | 卡车上的最大单元数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-units-on-a-truck.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-units-on-a-truck/) | Easy | +|1833 | 找到最高海拔 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-highest-altitude.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-highest-altitude/) | Easy | |1849 | 任意子数组和的绝对值的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-absolute-sum-of-any-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | |1858 | 替换隐藏数字得到的最晚时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/latest-time-by-replacing-hidden-digits.rs) | [leetcode](https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits/) | Easy | |1884 | 生成交替二进制字符串的最少操作数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-changes-to-make-alternating-binary-string.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-changes-to-make-alternating-binary-string/) | Easy | From ae4a4775e47ba2ced76d05fb3e3266b52a23d5c4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 7 May 2024 20:51:44 +0800 Subject: [PATCH 1385/1556] src/bin/all-elements-in-two-binary-search-trees.rs --- ...all-elements-in-two-binary-search-trees.rs | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/bin/all-elements-in-two-binary-search-trees.rs diff --git a/src/bin/all-elements-in-two-binary-search-trees.rs b/src/bin/all-elements-in-two-binary-search-trees.rs new file mode 100644 index 00000000..a3831a02 --- /dev/null +++ b/src/bin/all-elements-in-two-binary-search-trees.rs @@ -0,0 +1,84 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +impl Solution { + pub fn get_all_elements( + root1: Option>>, + root2: Option>>, + ) -> Vec { + let r1 = Self::get_list(root1); + let r2 = Self::get_list(root2); + + let mut result = Vec::with_capacity(r1.len() + r2.len()); + let (mut i1, mut i2) = (0, 0); + while i1 < r1.len() || i2 < r2.len() { + match (r1.get(i1), r2.get(i2)) { + (Some(&x), Some(&y)) => { + if x <= y { + result.push(x); + i1 += 1; + } else { + result.push(y); + i2 += 1; + } + } + + (Some(&x), _) => { + result.push(x); + i1 += 1; + } + + (_, Some(&y)) => { + result.push(y); + i2 += 1; + } + _ => unreachable!(), + } + } + + result + } + + fn get_list(root: Option>>) -> Vec { + fn f(root: Option>>, r: &mut Vec) { + if root.is_none() { + return; + } + + let root = root.unwrap(); + f(root.borrow_mut().left.take(), r); + r.push(root.borrow().val); + f(root.borrow_mut().right.take(), r); + } + + let mut result = vec![]; + f(root, &mut result); + + result + } +} From f75250ec350e922dc95581aefc981ddeb9ffee30 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 7 May 2024 20:51:45 +0800 Subject: [PATCH 1386/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b89eb468..957f50e5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 737 | 319 | 390 | 28 | +| 738 | 319 | 391 | 28 | ### 题目 @@ -408,6 +408,7 @@ |1406 | 整数的各位积和之差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/) | Easy | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | |1426 | 和为零的 N 个不同整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-n-unique-integers-sum-up-to-zero.rs) | [leetcode](https://leetcode-cn.com/problems/find-n-unique-integers-sum-up-to-zero/) | Easy | +|1427 | 两棵二叉搜索树中的所有元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-elements-in-two-binary-search-trees.rs) | [leetcode](https://leetcode-cn.com/problems/all-elements-in-two-binary-search-trees/) | Medium | |1428 | 跳跃游戏 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jump-game-iii.rs) | [leetcode](https://leetcode-cn.com/problems/jump-game-iii/) | Medium | |1434 | 解码字母到整数映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/decrypt-string-from-alphabet-to-integer-mapping.rs) | [leetcode](https://leetcode-cn.com/problems/decrypt-string-from-alphabet-to-integer-mapping/) | Easy | |1441 | 或运算的最小翻转次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-flips-to-make-a-or-b-equal-to-c.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/) | Medium | From a37b99bed08286cd6d9cab7ec029cdf4239212de Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 8 May 2024 20:18:44 +0800 Subject: [PATCH 1387/1556] src/bin/watering-plants.rs --- src/bin/watering-plants.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/watering-plants.rs diff --git a/src/bin/watering-plants.rs b/src/bin/watering-plants.rs new file mode 100644 index 00000000..ac4f90d4 --- /dev/null +++ b/src/bin/watering-plants.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn watering_plants(plants: Vec, capacity: i32) -> i32 { + let mut current_capacity = capacity; + let mut result = 0; + for i in 0..plants.len() { + result += 1; + if current_capacity < plants[i] { + current_capacity = capacity; + result += i as i32 * 2; + } + + current_capacity -= plants[i]; + } + + result + } +} From ce4577e84e7c4783d45f8d98c439d4b2edf205bf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 8 May 2024 20:18:45 +0800 Subject: [PATCH 1388/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 957f50e5..8c958707 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 738 | 319 | 391 | 28 | +| 739 | 319 | 392 | 28 | ### 题目 @@ -385,6 +385,7 @@ |1293 | 存在连续三个奇数的数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/three-consecutive-odds.rs) | [leetcode](https://leetcode-cn.com/problems/three-consecutive-odds/) | Easy | |1295 | 收集足够苹果的最小花园周长 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-garden-perimeter-to-collect-enough-apples.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-garden-perimeter-to-collect-enough-apples/) | Medium | |1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | +|1310 | 给植物浇水 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/watering-plants.rs) | [leetcode](https://leetcode-cn.com/problems/watering-plants/) | Medium | |1319 | 独一无二的出现次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-number-of-occurrences.rs) | [leetcode](https://leetcode-cn.com/problems/unique-number-of-occurrences/) | Easy | |1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | |1329 | 玩筹码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cost-to-move-chips-to-the-same-position.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position/) | Easy | From 283b43c06e02b83240275a45b6a2929cdef6ae7a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 9 May 2024 21:09:33 +0800 Subject: [PATCH 1389/1556] src/bin/watering-plants-ii.rs --- src/bin/watering-plants-ii.rs | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/bin/watering-plants-ii.rs diff --git a/src/bin/watering-plants-ii.rs b/src/bin/watering-plants-ii.rs new file mode 100644 index 00000000..8ec042b7 --- /dev/null +++ b/src/bin/watering-plants-ii.rs @@ -0,0 +1,38 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_refill(plants: Vec, capacity_a: i32, capacity_b: i32) -> i32 { + let mut result = 0; + let (mut a, mut b) = (capacity_a, capacity_b); + let (mut i, mut j) = (0, plants.len() - 1); + while i <= j { + if i == j { + if a < plants[i] && b < plants[i] { + result += 1; + } + break; + } else { + if a < plants[i] { + a = capacity_a; + result += 1; + } + + if b < plants[j] { + b = capacity_b; + result += 1; + } + + a -= plants[i]; + b -= plants[j]; + i += 1; + j -= 1; + } + } + + result + } +} From 30fe9f572f4b450804b0d3391f153fc14b8052b9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 9 May 2024 21:09:33 +0800 Subject: [PATCH 1390/1556] src/bin/watering-plants.rs --- src/bin/watering-plants.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/watering-plants.rs b/src/bin/watering-plants.rs index ac4f90d4..aeac789a 100644 --- a/src/bin/watering-plants.rs +++ b/src/bin/watering-plants.rs @@ -21,3 +21,4 @@ impl Solution { result } } +https://leetcode.cn/problems/watering-plants-ii/description/?envType=daily-question&envId=2024-05-09 \ No newline at end of file From da43414c11f71bfa41364f5b0c1a5f32b1ff1f9e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 9 May 2024 21:09:33 +0800 Subject: [PATCH 1391/1556] README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c958707..b7b642e7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 739 | 319 | 392 | 28 | +| 741 | 319 | 394 | 28 | ### 题目 @@ -386,6 +386,7 @@ |1295 | 收集足够苹果的最小花园周长 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-garden-perimeter-to-collect-enough-apples.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-garden-perimeter-to-collect-enough-apples/) | Medium | |1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | |1310 | 给植物浇水 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/watering-plants.rs) | [leetcode](https://leetcode-cn.com/problems/watering-plants/) | Medium | +|1310 | 给植物浇水 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/watering-plants.rs) | [leetcode](https://leetcode-cn.com/problems/watering-plants/) | Medium | |1319 | 独一无二的出现次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/unique-number-of-occurrences.rs) | [leetcode](https://leetcode-cn.com/problems/unique-number-of-occurrences/) | Easy | |1320 | 删除字符串中的所有相邻重复项 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string-ii.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string-ii/) | Medium | |1329 | 玩筹码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-cost-to-move-chips-to-the-same-position.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-cost-to-move-chips-to-the-same-position/) | Easy | @@ -496,6 +497,7 @@ |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | |2215 | 找出 3 位偶数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/finding-3-digit-even-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/finding-3-digit-even-numbers/) | Easy | |2226 | 环和杆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rings-and-rods.rs) | [leetcode](https://leetcode-cn.com/problems/rings-and-rods/) | Easy | +|2228 | 给植物浇水 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/watering-plants-ii.rs) | [leetcode](https://leetcode-cn.com/problems/watering-plants-ii/) | Medium | |2233 | 股票平滑下跌阶段的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-smooth-descent-periods-of-a-stock.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-smooth-descent-periods-of-a-stock/) | Medium | |2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | |2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | From 29908d724a992cda3a194e3418d5aa9e37cea307 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 10 May 2024 08:24:20 +0800 Subject: [PATCH 1392/1556] src/bin/count-tested-devices-after-test-operations.rs --- ...nt-tested-devices-after-test-operations.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/bin/count-tested-devices-after-test-operations.rs diff --git a/src/bin/count-tested-devices-after-test-operations.rs b/src/bin/count-tested-devices-after-test-operations.rs new file mode 100644 index 00000000..d4408e08 --- /dev/null +++ b/src/bin/count-tested-devices-after-test-operations.rs @@ -0,0 +1,19 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_tested_devices(battery_percentages: Vec) -> i32 { + let mut result = 0; + + for i in battery_percentages { + if i > result { + result += 1; + } + } + + result + } +} From 2aa82c514d538edab7aeb0474c8d773c536fda46 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 10 May 2024 08:24:21 +0800 Subject: [PATCH 1393/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b7b642e7..c347a53d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 741 | 319 | 394 | 28 | +| 742 | 320 | 394 | 28 | ### 题目 @@ -611,6 +611,7 @@ |3183 | 找出数组中的 K-or 值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-k-or-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-k-or-of-an-array/) | Easy | |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | |3189 | 找到冠军 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-ii/) | Medium | +|3220 | 统计已测试设备 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-tested-devices-after-test-operations.rs) | [leetcode](https://leetcode-cn.com/problems/count-tested-devices-after-test-operations/) | Easy | |3231 | 需要添加的硬币的最小数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-coins-to-be-added.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-coins-to-be-added/) | Medium | |3241 | 划分数组并满足最大差限制 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/divide-array-into-arrays-with-max-difference.rs) | [leetcode](https://leetcode-cn.com/problems/divide-array-into-arrays-with-max-difference/) | Medium | |3275 | 输入单词需要的最少按键次数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-pushes-to-type-word-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-pushes-to-type-word-i/) | Easy | From 1259c1d2192b8685e220d4465c664b98d3525cac Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 12 May 2024 23:55:52 +0800 Subject: [PATCH 1394/1556] src/bin/distribute-elements-into-two-arrays-i.rs --- .../distribute-elements-into-two-arrays-i.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/distribute-elements-into-two-arrays-i.rs diff --git a/src/bin/distribute-elements-into-two-arrays-i.rs b/src/bin/distribute-elements-into-two-arrays-i.rs new file mode 100644 index 00000000..bd552309 --- /dev/null +++ b/src/bin/distribute-elements-into-two-arrays-i.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn result_array(nums: Vec) -> Vec { + let mut nums1 = Vec::with_capacity(nums.len()); + let mut nums2 = vec![]; + + nums1.push(nums[0]); + nums2.push(nums[1]); + + for i in 2..nums.len() { + if nums1[nums1.len() - 1] > nums2[nums2.len() - 1] { + nums1.push(nums[i]); + } else { + nums2.push(nums[i]); + } + } + + nums1.extend(nums2); + + nums1 + } +} From 21b584b83afb45a27e04a8f6a456c219ce0a4931 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 12 May 2024 23:55:52 +0800 Subject: [PATCH 1395/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c347a53d..fc2d865f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 742 | 320 | 394 | 28 | +| 743 | 321 | 394 | 28 | ### 题目 @@ -616,6 +616,7 @@ |3241 | 划分数组并满足最大差限制 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/divide-array-into-arrays-with-max-difference.rs) | [leetcode](https://leetcode-cn.com/problems/divide-array-into-arrays-with-max-difference/) | Medium | |3275 | 输入单词需要的最少按键次数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-pushes-to-type-word-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-pushes-to-type-word-i/) | Easy | |3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | +|3347 | 将元素分配到两个数组中 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-elements-into-two-arrays-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-elements-into-two-arrays-i/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | |100240 | 魔术索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magic-index-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/magic-index-lcci/) | Easy | From f47ddd44024e8da08ae97f5fb9f2625fbbec8ac9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 13 May 2024 21:51:28 +0800 Subject: [PATCH 1396/1556] src/bin/check-if-there-is-a-valid-partition-for-the-array.rs --- ...here-is-a-valid-partition-for-the-array.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/check-if-there-is-a-valid-partition-for-the-array.rs diff --git a/src/bin/check-if-there-is-a-valid-partition-for-the-array.rs b/src/bin/check-if-there-is-a-valid-partition-for-the-array.rs new file mode 100644 index 00000000..40b4be78 --- /dev/null +++ b/src/bin/check-if-there-is-a-valid-partition-for-the-array.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn valid_partition(nums: Vec) -> bool { + let mut dp = vec![false; nums.len() + 1]; + dp[0] = true; + for (i, &v) in nums.iter().enumerate() { + if (i > 0 && dp[i - 1] && v == nums[i - 1]) + || (i > 1 && dp[i - 2] && v == nums[i - 1] && v == nums[i - 2]) + || (i > 1 && dp[i - 2] && v == nums[i - 1] + 1 && v == nums[i - 2] + 2) + { + dp[i + 1] = true + } + } + + println!("{dp:?}"); + + dp[nums.len()] + } +} From 86fbc84d35227e7b92a665576181d995f2d6606e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 13 May 2024 21:51:28 +0800 Subject: [PATCH 1397/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc2d865f..2584837d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 743 | 321 | 394 | 28 | +| 744 | 321 | 395 | 28 | ### 题目 @@ -519,6 +519,7 @@ |2413 | 无限集中的最小数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-number-in-infinite-set.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-number-in-infinite-set/) | Medium | |2414 | 移动片段得到字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/move-pieces-to-obtain-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/move-pieces-to-obtain-a-string/) | Medium | |2442 | 算术三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-arithmetic-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-arithmetic-triplets/) | Easy | +|2443 | 检查数组是否存在有效划分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-there-is-a-valid-partition-for-the-array.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-there-is-a-valid-partition-for-the-array/) | Medium | |2461 | 感染二叉树需要的总时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/amount-of-time-for-binary-tree-to-be-infected.rs) | [leetcode](https://leetcode-cn.com/problems/amount-of-time-for-binary-tree-to-be-infected/) | Medium | |2470 | 从字符串中移除星号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-stars-from-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/removing-stars-from-a-string/) | Medium | |2473 | 数位和相等数对的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs) | [leetcode](https://leetcode-cn.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | From aacfbacd67fe9a6ee36af087a9d20bee3b130224 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 14 May 2024 08:30:58 +0800 Subject: [PATCH 1398/1556] src/bin/minimum-rounds-to-complete-all-tasks.rs --- .../minimum-rounds-to-complete-all-tasks.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/bin/minimum-rounds-to-complete-all-tasks.rs diff --git a/src/bin/minimum-rounds-to-complete-all-tasks.rs b/src/bin/minimum-rounds-to-complete-all-tasks.rs new file mode 100644 index 00000000..be4eedbb --- /dev/null +++ b/src/bin/minimum-rounds-to-complete-all-tasks.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_rounds(tasks: Vec) -> i32 { + let mut count = std::collections::HashMap::new(); + for i in tasks { + *count.entry(i).or_insert(0) += 1; + } + + let mut result = 0; + for &i in count.values() { + if i < 2 { + return -1; + } + + match i % 3 { + 0 => result += i / 3, + 1 => result += (i - 4) / 3 + 2, + 2 => result += i / 3 + 1, + _ => unreachable!(), + } + } + + result + } +} From 84123f3829cfb321ccfabfd419ca8cae13cd984e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 14 May 2024 08:30:58 +0800 Subject: [PATCH 1399/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2584837d..36afb78c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 744 | 321 | 395 | 28 | +| 745 | 321 | 396 | 28 | ### 题目 @@ -512,6 +512,7 @@ |2328 | 向表达式添加括号后的最小结果 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimize-result-by-adding-parentheses-to-expression.rs) | [leetcode](https://leetcode-cn.com/problems/minimize-result-by-adding-parentheses-to-expression/) | Medium | |2346 | 字符串中最大的 3 位相同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-3-same-digit-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-3-same-digit-number-in-string/) | Easy | |2351 | 买钢笔和铅笔的方案数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-ways-to-buy-pens-and-pencils.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-ways-to-buy-pens-and-pencils/) | Medium | +|2362 | 完成所有任务需要的最少轮数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-rounds-to-complete-all-tasks.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-rounds-to-complete-all-tasks/) | Medium | |2378 | 最多单词数的发件人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sender-with-largest-word-count.rs) | [leetcode](https://leetcode-cn.com/problems/sender-with-largest-word-count/) | Medium | |2384 | 判断根结点是否等于子结点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/root-equals-sum-of-children.rs) | [leetcode](https://leetcode-cn.com/problems/root-equals-sum-of-children/) | Easy | |2386 | 极大极小游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-max-game.rs) | [leetcode](https://leetcode-cn.com/problems/min-max-game/) | Easy | From 24d98b666a928398d5f78bca60753f99bf15540d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 15 May 2024 20:06:07 +0800 Subject: [PATCH 1400/1556] src/bin/average-salary-excluding-the-minimum-and-maximum-salary.rs --- ...excluding-the-minimum-and-maximum-salary.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/bin/average-salary-excluding-the-minimum-and-maximum-salary.rs diff --git a/src/bin/average-salary-excluding-the-minimum-and-maximum-salary.rs b/src/bin/average-salary-excluding-the-minimum-and-maximum-salary.rs new file mode 100644 index 00000000..6ea48ecb --- /dev/null +++ b/src/bin/average-salary-excluding-the-minimum-and-maximum-salary.rs @@ -0,0 +1,18 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn average(salary: Vec) -> f64 { + let (mut sum, mut max, mut min) = (0, i32::MIN, i32::MAX); + for &i in salary.iter() { + sum += i; + max = max.max(i); + min = min.min(i); + } + + (sum - max - min) as f64 / (salary.len() as f64 - 2f64) + } +} From ade4bc3074624473e5a6cda66afdacce562f9934 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 15 May 2024 20:06:07 +0800 Subject: [PATCH 1401/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 36afb78c..99e1835d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 745 | 321 | 396 | 28 | +| 746 | 322 | 396 | 28 | ### 题目 @@ -437,6 +437,7 @@ |1568 | 二叉树中的伪回文路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pseudo-palindromic-paths-in-a-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/pseudo-palindromic-paths-in-a-binary-tree/) | Medium | |1575 | 切割后面积最大的蛋糕 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts/) | Medium | |1576 | 重新规划路线 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reorder-routes-to-make-all-paths-lead-to-the-city-zero.rs) | [leetcode](https://leetcode-cn.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero/) | Medium | +|1584 | 去掉最低工资和最高工资后的工资平均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/average-salary-excluding-the-minimum-and-maximum-salary.rs) | [leetcode](https://leetcode-cn.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/) | Easy | |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | |1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | |1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | From 8a961c7ab69fc70cedaea4d90ba06b4807ea81ca Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 16 May 2024 20:56:03 +0800 Subject: [PATCH 1402/1556] src/bin/maximum-number-of-weeks-for-which-you-can-work.rs --- ...um-number-of-weeks-for-which-you-can-work.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/bin/maximum-number-of-weeks-for-which-you-can-work.rs diff --git a/src/bin/maximum-number-of-weeks-for-which-you-can-work.rs b/src/bin/maximum-number-of-weeks-for-which-you-can-work.rs new file mode 100644 index 00000000..090ff531 --- /dev/null +++ b/src/bin/maximum-number-of-weeks-for-which-you-can-work.rs @@ -0,0 +1,17 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn number_of_weeks(milestones: Vec) -> i64 { + let s = milestones.iter().map(|&x| x as i64).sum(); + let m = *milestones.iter().max().unwrap() as i64; + if m > s - m + 1 { + (s - m) * 2 + 1 + } else { + s + } + } +} From da974d38e074b72405dbea9d3cd898cbdf8cec1f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 16 May 2024 20:56:03 +0800 Subject: [PATCH 1403/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99e1835d..e3e5fd73 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 746 | 322 | 396 | 28 | +| 747 | 322 | 397 | 28 | ### 题目 @@ -485,6 +485,7 @@ |2032 | 字符串中的最大奇数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-odd-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-odd-number-in-string/) | Easy | |2049 | 消灭怪物的最大数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/eliminate-maximum-number-of-monsters.rs) | [leetcode](https://leetcode-cn.com/problems/eliminate-maximum-number-of-monsters/) | Medium | |2053 | 检查是否所有字符出现次数相同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-all-characters-have-equal-number-of-occurrences.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-all-characters-have-equal-number-of-occurrences/) | Easy | +|2084 | 你可以工作的最大周数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-weeks-for-which-you-can-work.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-weeks-for-which-you-can-work/) | Medium | |2094 | 移除石子使总数最小 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-stones-to-minimize-the-total.rs) | [leetcode](https://leetcode-cn.com/problems/remove-stones-to-minimize-the-total/) | Medium | |2104 | 树上的操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/operations-on-tree.rs) | [leetcode](https://leetcode-cn.com/problems/operations-on-tree/) | Medium | |2117 | 从双倍数组中还原原数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-original-array-from-doubled-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-original-array-from-doubled-array/) | Medium | From 64baf5b6897e7366a977d2c43c85dd57994d5d37 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 17 May 2024 08:04:03 +0800 Subject: [PATCH 1404/1556] src/bin/most-profit-assigning-work.rs --- src/bin/most-profit-assigning-work.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/most-profit-assigning-work.rs diff --git a/src/bin/most-profit-assigning-work.rs b/src/bin/most-profit-assigning-work.rs new file mode 100644 index 00000000..963d454a --- /dev/null +++ b/src/bin/most-profit-assigning-work.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_profit_assignment(difficulty: Vec, profit: Vec, worker: Vec) -> i32 { + let mut d: Vec<(i32, i32)> = difficulty.into_iter().zip(profit.into_iter()).collect(); + d.sort(); + let mut worker = worker; + worker.sort(); + let mut max = 0; + let mut result = 0; + let mut j = 0; + for i in worker { + while j < d.len() && d[j].0 <= i { + max = max.max(d[j].1); + j += 1; + } + + result += max; + } + + result + } +} From f7b0d95be8a5132f33211f401d9b1da56a04079b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 17 May 2024 08:04:03 +0800 Subject: [PATCH 1405/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e3e5fd73..d6ce1abe 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 747 | 322 | 397 | 28 | +| 748 | 322 | 398 | 28 | ### 题目 @@ -313,6 +313,7 @@ |835 | 链表组件 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/linked-list-components.rs) | [leetcode](https://leetcode-cn.com/problems/linked-list-components/) | Medium | |839 | 单词的压缩编码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/short-encoding-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/short-encoding-of-words/) | Medium | |842 | 翻转卡片游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/card-flipping-game.rs) | [leetcode](https://leetcode-cn.com/problems/card-flipping-game/) | Medium | +|853 | 安排工作以达到最大收益 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/most-profit-assigning-work.rs) | [leetcode](https://leetcode-cn.com/problems/most-profit-assigning-work/) | Medium | |857 | 较大分组的位置 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/positions-of-large-groups.rs) | [leetcode](https://leetcode-cn.com/problems/positions-of-large-groups/) | Easy | |860 | 设计循环队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-circular-queue.rs) | [leetcode](https://leetcode-cn.com/problems/design-circular-queue/) | Medium | |861 | 翻转图像 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/flipping-an-image.rs) | [leetcode](https://leetcode-cn.com/problems/flipping-an-image/) | Easy | From 810e7b6cb8c71800e3f5480edbde6b7c9a1f52f2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 19 May 2024 23:27:23 +0800 Subject: [PATCH 1406/1556] src/bin/maximum-number-of-balls-in-a-box.rs --- src/bin/maximum-number-of-balls-in-a-box.rs | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/bin/maximum-number-of-balls-in-a-box.rs diff --git a/src/bin/maximum-number-of-balls-in-a-box.rs b/src/bin/maximum-number-of-balls-in-a-box.rs new file mode 100644 index 00000000..28d69a8a --- /dev/null +++ b/src/bin/maximum-number-of-balls-in-a-box.rs @@ -0,0 +1,26 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_balls(low_limit: i32, high_limit: i32) -> i32 { + let mut max_num = 0; + let mut hash = std::collections::HashMap::new(); + for mut i in low_limit..=high_limit { + let mut sum = 0; + while i > 0 { + sum += i % 10; + i /= 10; + } + + let x = hash.entry(sum).and_modify(|x| *x += 1).or_insert(1); + if *x > max_num { + max_num = *x; + } + } + + max_num + } +} From b3b42d6d549540e2ab4fbb32dea5a70929f00fd2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 19 May 2024 23:27:23 +0800 Subject: [PATCH 1407/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6ce1abe..108c7df4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 748 | 322 | 398 | 28 | +| 749 | 323 | 398 | 28 | ### 题目 @@ -465,6 +465,7 @@ |1817 | 计算力扣银行的钱 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/calculate-money-in-leetcode-bank.rs) | [leetcode](https://leetcode-cn.com/problems/calculate-money-in-leetcode-bank/) | Easy | |1829 | 卡车上的最大单元数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-units-on-a-truck.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-units-on-a-truck/) | Easy | |1833 | 找到最高海拔 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-highest-altitude.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-highest-altitude/) | Easy | +|1844 | 盒子中小球的最大数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-balls-in-a-box.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-balls-in-a-box/) | Easy | |1849 | 任意子数组和的绝对值的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-absolute-sum-of-any-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | |1858 | 替换隐藏数字得到的最晚时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/latest-time-by-replacing-hidden-digits.rs) | [leetcode](https://leetcode-cn.com/problems/latest-time-by-replacing-hidden-digits/) | Easy | |1884 | 生成交替二进制字符串的最少操作数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-changes-to-make-alternating-binary-string.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-changes-to-make-alternating-binary-string/) | Easy | From 9b192b4638df92db25d30496900580381beb088c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 20 May 2024 21:43:00 +0800 Subject: [PATCH 1408/1556] src/bin/maximum-good-subarray-sum.rs --- src/bin/maximum-good-subarray-sum.rs | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bin/maximum-good-subarray-sum.rs diff --git a/src/bin/maximum-good-subarray-sum.rs b/src/bin/maximum-good-subarray-sum.rs new file mode 100644 index 00000000..4938ed68 --- /dev/null +++ b/src/bin/maximum-good-subarray-sum.rs @@ -0,0 +1,37 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_subarray_sum(nums: Vec, k: i32) -> i64 { + let mut hash = std::collections::HashMap::new(); + let mut sum = 0i64; + let mut result = i64::MIN; + for x in nums { + if let Some(&s) = hash.get(&(x + k)) { + result = result.max(sum + x as i64 - s); + } + + if let Some(&s) = hash.get(&(x - k)) { + result = result.max(sum + x as i64 - s); + } + + match hash.get(&x) { + Some(&s) if s < sum => {} + _ => { + hash.insert(x, sum); + } + } + + sum += x as i64; + } + + if result == i64::MIN { + 0 + } else { + result + } + } +} From d8a2f95b3e99efcc972d7e0c6bb07eae16eed3c5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 20 May 2024 21:43:01 +0800 Subject: [PATCH 1409/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 108c7df4..c44b2787 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 749 | 323 | 398 | 28 | +| 750 | 323 | 399 | 28 | ### 题目 @@ -620,6 +620,7 @@ |3220 | 统计已测试设备 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-tested-devices-after-test-operations.rs) | [leetcode](https://leetcode-cn.com/problems/count-tested-devices-after-test-operations/) | Easy | |3231 | 需要添加的硬币的最小数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-coins-to-be-added.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-coins-to-be-added/) | Medium | |3241 | 划分数组并满足最大差限制 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/divide-array-into-arrays-with-max-difference.rs) | [leetcode](https://leetcode-cn.com/problems/divide-array-into-arrays-with-max-difference/) | Medium | +|3265 | 最大好子数组和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-good-subarray-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-good-subarray-sum/) | Medium | |3275 | 输入单词需要的最少按键次数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-pushes-to-type-word-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-pushes-to-type-word-i/) | Easy | |3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | |3347 | 将元素分配到两个数组中 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-elements-into-two-arrays-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-elements-into-two-arrays-i/) | Easy | From f4cd193ca4ede9b8ff84de8811ee4e60ea04bdf0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 21 May 2024 19:52:28 +0800 Subject: [PATCH 1410/1556] src/bin/number-of-employees-who-met-the-target.rs --- src/bin/number-of-employees-who-met-the-target.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/bin/number-of-employees-who-met-the-target.rs diff --git a/src/bin/number-of-employees-who-met-the-target.rs b/src/bin/number-of-employees-who-met-the-target.rs new file mode 100644 index 00000000..34d05191 --- /dev/null +++ b/src/bin/number-of-employees-who-met-the-target.rs @@ -0,0 +1,11 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn number_of_employees_who_met_target(hours: Vec, target: i32) -> i32 { + hours.into_iter().filter(|x| *x >= target).count() as i32 + } +} From 5212b286717b7a890d097a46b2edef4eb85911b3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 21 May 2024 19:52:28 +0800 Subject: [PATCH 1411/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c44b2787..bafb374e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 750 | 323 | 399 | 28 | +| 751 | 324 | 399 | 28 | ### 题目 @@ -600,6 +600,7 @@ |2866 | 最长奇偶子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-even-odd-subarray-with-threshold.rs) | [leetcode](https://leetcode-cn.com/problems/longest-even-odd-subarray-with-threshold/) | Easy | |2870 | 最长交替子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-alternating-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/longest-alternating-subarray/) | Easy | |2872 | 合并后数组中的最大元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-element-in-an-array-after-merge-operations.rs) | [leetcode](https://leetcode-cn.com/problems/largest-element-in-an-array-after-merge-operations/) | Medium | +|2876 | 满足目标工作时长的员工数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-employees-who-met-the-target.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-employees-who-met-the-target/) | Easy | |2881 | 按分隔符拆分字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-strings-by-separator.rs) | [leetcode](https://leetcode-cn.com/problems/split-strings-by-separator/) | Easy | |2886 | 故障键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/faulty-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/faulty-keyboard/) | Easy | |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | From 8b76103ee3f6c34a200335d77abad3515582c188 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 22 May 2024 08:40:10 +0800 Subject: [PATCH 1412/1556] src/bin/find-players-with-zero-or-one-losses.rs --- .../find-players-with-zero-or-one-losses.rs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/find-players-with-zero-or-one-losses.rs diff --git a/src/bin/find-players-with-zero-or-one-losses.rs b/src/bin/find-players-with-zero-or-one-losses.rs new file mode 100644 index 00000000..248d46bb --- /dev/null +++ b/src/bin/find-players-with-zero-or-one-losses.rs @@ -0,0 +1,31 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_winners(matches: Vec>) -> Vec> { + let mut winners = std::collections::HashSet::new(); + let mut losers = std::collections::HashMap::new(); + + for i in matches { + losers.entry(i[1]).and_modify(|x| *x += 1).or_insert(1); + winners.remove(&i[1]); + if !losers.contains_key(&i[0]) { + winners.insert(i[0]); + } + } + + let mut w: Vec = winners.into_iter().collect(); + let mut l: Vec = losers + .into_iter() + .filter_map(|x| if x.1 == 1 { Some(x.0) } else { None }) + .collect(); + + w.sort_unstable(); + l.sort_unstable(); + + vec![w, l] + } +} From ee68c3f002db64f45ad2abceeac34d9355dd6107 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 22 May 2024 08:40:10 +0800 Subject: [PATCH 1413/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bafb374e..e7b05248 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 751 | 324 | 399 | 28 | +| 752 | 324 | 400 | 28 | ### 题目 @@ -394,6 +394,7 @@ |1341 | 分割平衡字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-a-string-in-balanced-strings.rs) | [leetcode](https://leetcode-cn.com/problems/split-a-string-in-balanced-strings/) | Easy | |1342 | 可以攻击国王的皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/queens-that-can-attack-the-king.rs) | [leetcode](https://leetcode-cn.com/problems/queens-that-can-attack-the-king/) | Medium | |1353 | 移除字母异位词后的结果数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-resultant-array-after-removing-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/find-resultant-array-after-removing-anagrams/) | Easy | +|1354 | 找出输掉零场或一场比赛的玩家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-players-with-zero-or-one-losses.rs) | [leetcode](https://leetcode-cn.com/problems/find-players-with-zero-or-one-losses/) | Medium | |1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | |1363 | 兼具大小写的最好英文字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/greatest-english-letter-in-upper-and-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/greatest-english-letter-in-upper-and-lower-case/) | Easy | |1364 | 同积元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tuple-with-same-product.rs) | [leetcode](https://leetcode-cn.com/problems/tuple-with-same-product/) | Medium | From 437989241b71752c2d840ba6ce1cc8bee8fc8ae7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 May 2024 09:53:47 +0800 Subject: [PATCH 1414/1556] src/bin/find-indices-with-index-and-value-difference-i.rs --- ...dices-with-index-and-value-difference-i.rs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/bin/find-indices-with-index-and-value-difference-i.rs diff --git a/src/bin/find-indices-with-index-and-value-difference-i.rs b/src/bin/find-indices-with-index-and-value-difference-i.rs new file mode 100644 index 00000000..e47ec504 --- /dev/null +++ b/src/bin/find-indices-with-index-and-value-difference-i.rs @@ -0,0 +1,42 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_indices1(nums: Vec, index_difference: i32, value_difference: i32) -> Vec { + for i in 0..nums.len() { + for j in i + index_difference as usize..nums.len() { + if (nums[i] - nums[j]).abs() >= value_difference { + return vec![i as i32, j as i32]; + } + } + } + + vec![-1, -1] + } + + pub fn find_indices(nums: Vec, index_difference: i32, value_difference: i32) -> Vec { + let (mut max_id, mut min_id) = (0, 0); + + for j in index_difference as usize..nums.len() { + let i = j - index_difference as usize; + if nums[i] > nums[max_id] { + max_id = i; + } else if nums[i] < nums[min_id] { + min_id = i; + } + + if nums[j] - nums[min_id] >= value_difference { + return vec![min_id as i32, j as i32]; + } + + if nums[max_id] - nums[j] >= value_difference { + return vec![max_id as i32, j as i32]; + } + } + + vec![-1, -1] + } +} From d21627efcb27b41ea0c59dfa8ce074f1ab6ccc39 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 25 May 2024 09:53:48 +0800 Subject: [PATCH 1415/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e7b05248..4330e3b0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 752 | 324 | 400 | 28 | +| 753 | 325 | 400 | 28 | ### 题目 @@ -615,6 +615,7 @@ |3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | |3095 | 最大合金数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-alloys.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-alloys/) | Medium | |3152 | 有序三元组中的最大值 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-value-of-an-ordered-triplet-ii.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-value-of-an-ordered-triplet-ii/) | Medium | +|3165 | 找出满足差值条件的下标 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-indices-with-index-and-value-difference-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-indices-with-index-and-value-difference-i/) | Easy | |3176 | 元素和最小的山形三元组 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-sum-of-mountain-triplets-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-sum-of-mountain-triplets-i/) | Easy | |3183 | 找出数组中的 K-or 值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-k-or-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-k-or-of-an-array/) | Easy | |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | From 09b3a4f49d0ce272164ee8100fce3535dc8c1d45 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 26 May 2024 22:06:24 +0800 Subject: [PATCH 1416/1556] src/bin/string-to-url-lcci.rs --- src/bin/string-to-url-lcci.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/string-to-url-lcci.rs diff --git a/src/bin/string-to-url-lcci.rs b/src/bin/string-to-url-lcci.rs new file mode 100644 index 00000000..8a426826 --- /dev/null +++ b/src/bin/string-to-url-lcci.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn replace_spaces(s: String, length: i32) -> String { + let mut s1 = String::new(); + for i in s.chars().take(length as usize) { + if i == ' ' { + s1.push_str("%20"); + } else { + s1.push(i); + } + } + + s1 + } +} From 454c7ddaf4156655a62d317730e4ae5397b8593a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 26 May 2024 22:06:25 +0800 Subject: [PATCH 1417/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4330e3b0..6fcf2e1b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 753 | 325 | 400 | 28 | +| 754 | 326 | 400 | 28 | ### 题目 @@ -627,6 +627,7 @@ |3275 | 输入单词需要的最少按键次数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-pushes-to-type-word-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-pushes-to-type-word-i/) | Easy | |3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | |3347 | 将元素分配到两个数组中 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-elements-into-two-arrays-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-elements-into-two-arrays-i/) | Easy | +|100160 | URL化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-url-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-url-lcci/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | |100240 | 魔术索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magic-index-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/magic-index-lcci/) | Easy | From 7440f0f0c43aae8db54553a19db26e6a51c5ed92 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 27 May 2024 20:33:04 +0800 Subject: [PATCH 1418/1556] src/bin/find-missing-observations.rs --- src/bin/find-missing-observations.rs | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/find-missing-observations.rs diff --git a/src/bin/find-missing-observations.rs b/src/bin/find-missing-observations.rs new file mode 100644 index 00000000..b7122138 --- /dev/null +++ b/src/bin/find-missing-observations.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn missing_rolls(rolls: Vec, mean: i32, n: i32) -> Vec { + let mut m = rolls.len() as i32; + let total = mean * (m + n); + let rolls_sum: i32 = rolls.into_iter().sum(); + let mut n_sum = total - rolls_sum; + let mut result = Vec::with_capacity(n as usize); + + if n_sum > n * 6 || n_sum < n { + return vec![]; + } + + for i in 1..=n { + match n_sum - (n - i) { + x if x >= 0 && x <= 5 => { + result.push(x); + n_sum -= x; + } + + _ => { + result.push(6); + n_sum -= 6; + } + } + } + + result + } +} From e338823a26e84110307261c263b08f61070a8cca Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 27 May 2024 20:33:05 +0800 Subject: [PATCH 1419/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6fcf2e1b..93834622 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 754 | 326 | 400 | 28 | +| 755 | 326 | 401 | 28 | ### 题目 @@ -493,6 +493,7 @@ |2104 | 树上的操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/operations-on-tree.rs) | [leetcode](https://leetcode-cn.com/problems/operations-on-tree/) | Medium | |2117 | 从双倍数组中还原原数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-original-array-from-doubled-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-original-array-from-doubled-array/) | Medium | |2128 | 反转单词前缀 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reverse-prefix-of-word.rs) | [leetcode](https://leetcode-cn.com/problems/reverse-prefix-of-word/) | Easy | +|2155 | 找出缺失的观测数据 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-missing-observations.rs) | [leetcode](https://leetcode-cn.com/problems/find-missing-observations/) | Medium | |2159 | 至少在两个数组中出现的值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/two-out-of-three.rs) | [leetcode](https://leetcode-cn.com/problems/two-out-of-three/) | Easy | |2161 | 股票价格波动 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/stock-price-fluctuation.rs) | [leetcode](https://leetcode-cn.com/problems/stock-price-fluctuation/) | Medium | |2168 | 检查句子中的数字是否递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-numbers-are-ascending-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-numbers-are-ascending-in-a-sentence/) | Easy | From a118112feb24eb76170f84536f1a244378b51991 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 28 May 2024 07:38:02 +0800 Subject: [PATCH 1420/1556] src/bin/find-the-peaks.rs --- src/bin/find-the-peaks.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/bin/find-the-peaks.rs diff --git a/src/bin/find-the-peaks.rs b/src/bin/find-the-peaks.rs new file mode 100644 index 00000000..b6c79c56 --- /dev/null +++ b/src/bin/find-the-peaks.rs @@ -0,0 +1,18 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_peaks(mountain: Vec) -> Vec { + let mut result = vec![]; + for i in 1..mountain.len() - 1 { + if mountain[i] > mountain[i - 1] && mountain[i] > mountain[i + 1] { + result.push(i as i32); + } + } + + result + } +} From 83fbdb80ba3abbd97368c29510a2412c8ae860c5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 28 May 2024 07:38:02 +0800 Subject: [PATCH 1421/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 93834622..a644e9cc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 755 | 326 | 401 | 28 | +| 756 | 327 | 401 | 28 | ### 题目 @@ -622,6 +622,7 @@ |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | |3189 | 找到冠军 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-ii/) | Medium | |3220 | 统计已测试设备 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-tested-devices-after-test-operations.rs) | [leetcode](https://leetcode-cn.com/problems/count-tested-devices-after-test-operations/) | Easy | +|3221 | 找出峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-peaks.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-peaks/) | Easy | |3231 | 需要添加的硬币的最小数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-coins-to-be-added.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-coins-to-be-added/) | Medium | |3241 | 划分数组并满足最大差限制 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/divide-array-into-arrays-with-max-difference.rs) | [leetcode](https://leetcode-cn.com/problems/divide-array-into-arrays-with-max-difference/) | Medium | |3265 | 最大好子数组和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-good-subarray-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-good-subarray-sum/) | Medium | From e6449939e3ccbd502c8406cebd384126fca56b0d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 30 May 2024 14:38:39 +0800 Subject: [PATCH 1422/1556] src/bin/apple-redistribution-into-boxes.rs --- src/bin/apple-redistribution-into-boxes.rs | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/apple-redistribution-into-boxes.rs diff --git a/src/bin/apple-redistribution-into-boxes.rs b/src/bin/apple-redistribution-into-boxes.rs new file mode 100644 index 00000000..4fcc6750 --- /dev/null +++ b/src/bin/apple-redistribution-into-boxes.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_boxes(apple: Vec, capacity: Vec) -> i32 { + let mut total: i32 = apple.into_iter().sum(); + let mut capacity = capacity; + capacity.sort(); + let mut result = 0; + while let Some(x) = capacity.pop() { + total -= x; + result += 1; + if total <= 0 { + break; + } + } + + result + } +} From f44559d422f60f9366f6c0aa03b24acb51621840 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 30 May 2024 14:38:39 +0800 Subject: [PATCH 1423/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a644e9cc..2b273ef5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 756 | 327 | 401 | 28 | +| 757 | 328 | 401 | 28 | ### 题目 @@ -628,6 +628,7 @@ |3265 | 最大好子数组和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-good-subarray-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-good-subarray-sum/) | Medium | |3275 | 输入单词需要的最少按键次数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-pushes-to-type-word-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-pushes-to-type-word-i/) | Easy | |3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | +|3334 | 重新分装苹果 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apple-redistribution-into-boxes.rs) | [leetcode](https://leetcode-cn.com/problems/apple-redistribution-into-boxes/) | Easy | |3347 | 将元素分配到两个数组中 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-elements-into-two-arrays-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-elements-into-two-arrays-i/) | Easy | |100160 | URL化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-url-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-url-lcci/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | From 0507f81f11dfbea9319a21d73567ed2cfac42805 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 31 May 2024 16:45:34 +0800 Subject: [PATCH 1424/1556] src/bin/find-missing-and-repeated-values.rs --- src/bin/find-missing-and-repeated-values.rs | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/find-missing-and-repeated-values.rs diff --git a/src/bin/find-missing-and-repeated-values.rs b/src/bin/find-missing-and-repeated-values.rs new file mode 100644 index 00000000..5dd13174 --- /dev/null +++ b/src/bin/find-missing-and-repeated-values.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_missing_and_repeated_values(grid: Vec>) -> Vec { + let mut hash = std::collections::HashMap::new(); + + for i in 0..grid.len() { + for j in 0..grid[0].len() { + *hash.entry(grid[i][j]).or_insert(0) += 1; + } + } + + let mut result = vec![0, 0]; + for i in 1..=(grid.len() * grid.len()) as i32 { + match hash.get(&i) { + Some(&x) if x == 2 => result[0] = i, + None => result[1] = i, + _ => {} + } + } + + result + } +} From bb944f306bb1e5ff0e3a39ece5d5d6cd45af5efc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 31 May 2024 16:45:34 +0800 Subject: [PATCH 1425/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b273ef5..2b8e421e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 757 | 328 | 401 | 28 | +| 758 | 329 | 401 | 28 | ### 题目 @@ -623,6 +623,7 @@ |3189 | 找到冠军 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-ii/) | Medium | |3220 | 统计已测试设备 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-tested-devices-after-test-operations.rs) | [leetcode](https://leetcode-cn.com/problems/count-tested-devices-after-test-operations/) | Easy | |3221 | 找出峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-peaks.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-peaks/) | Easy | +|3227 | 找出缺失和重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-missing-and-repeated-values.rs) | [leetcode](https://leetcode-cn.com/problems/find-missing-and-repeated-values/) | Easy | |3231 | 需要添加的硬币的最小数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-coins-to-be-added.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-coins-to-be-added/) | Medium | |3241 | 划分数组并满足最大差限制 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/divide-array-into-arrays-with-max-difference.rs) | [leetcode](https://leetcode-cn.com/problems/divide-array-into-arrays-with-max-difference/) | Medium | |3265 | 最大好子数组和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-good-subarray-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-good-subarray-sum/) | Medium | From ec084c7b3bd7f635da112880b95f276ec20f84e0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 1 Jun 2024 22:29:08 +0800 Subject: [PATCH 1426/1556] src/bin/distribute-candies-among-children-i.rs --- src/bin/distribute-candies-among-children-i.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/bin/distribute-candies-among-children-i.rs diff --git a/src/bin/distribute-candies-among-children-i.rs b/src/bin/distribute-candies-among-children-i.rs new file mode 100644 index 00000000..387e7e64 --- /dev/null +++ b/src/bin/distribute-candies-among-children-i.rs @@ -0,0 +1,12 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn distribute_candies(n: i32, limit: i32) -> i32 { + let c2 = |n| if n > 1 { n * (n - 1) / 2 } else { 0 }; + c2(n + 2) - 3 * c2(n - limit + 1) + 3 * c2(n - 2 * limit) - c2(n - 3 * limit - 1) + } +} From 5241b7d113fa758dce3d3e8748b9ac019d6c48f8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 1 Jun 2024 22:29:09 +0800 Subject: [PATCH 1427/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b8e421e..99d7be26 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 758 | 329 | 401 | 28 | +| 759 | 330 | 401 | 28 | ### 题目 @@ -621,6 +621,7 @@ |3183 | 找出数组中的 K-or 值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-k-or-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-k-or-of-an-array/) | Easy | |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | |3189 | 找到冠军 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-ii/) | Medium | +|3199 | 给小朋友们分糖果 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-candies-among-children-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-candies-among-children-i/) | Easy | |3220 | 统计已测试设备 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-tested-devices-after-test-operations.rs) | [leetcode](https://leetcode-cn.com/problems/count-tested-devices-after-test-operations/) | Easy | |3221 | 找出峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-peaks.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-peaks/) | Easy | |3227 | 找出缺失和重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-missing-and-repeated-values.rs) | [leetcode](https://leetcode-cn.com/problems/find-missing-and-repeated-values/) | Easy | From 6980ed6e2ee79c6c4e03ea513c2a361f3d3192e1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 4 Jun 2024 10:11:04 +0800 Subject: [PATCH 1428/1556] src/bin/distribute-candies.rs --- src/bin/distribute-candies.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/bin/distribute-candies.rs diff --git a/src/bin/distribute-candies.rs b/src/bin/distribute-candies.rs new file mode 100644 index 00000000..f3529201 --- /dev/null +++ b/src/bin/distribute-candies.rs @@ -0,0 +1,13 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn distribute_candies(candy_type: Vec) -> i32 { + use std::collections::HashSet; + let set = candy_type.iter().collect::>(); + set.len().min(candy_type.len() / 2) as _ + } +} From 83e482eef1ab8151c2c743b0f28c74a48a4d7376 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 4 Jun 2024 10:11:05 +0800 Subject: [PATCH 1429/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99d7be26..56384172 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 759 | 330 | 401 | 28 | +| 760 | 331 | 401 | 28 | ### 题目 @@ -277,6 +277,7 @@ |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |560 | 和为 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | |565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | +|575 | 分糖果 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-candies.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-candies/) | Easy | |581 | 最短无序连续子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shortest-unsorted-continuous-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/shortest-unsorted-continuous-subarray/) | Medium | |594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | |599 | 两个列表的最小索引总和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-index-sum-of-two-lists.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-index-sum-of-two-lists/) | Easy | From 191687e4b969f0a36d3df9afb6339843e607383e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 5 Jun 2024 10:50:06 +0800 Subject: [PATCH 1430/1556] src/bin/count-lattice-points-inside-a-circle.rs --- .../count-lattice-points-inside-a-circle.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/bin/count-lattice-points-inside-a-circle.rs diff --git a/src/bin/count-lattice-points-inside-a-circle.rs b/src/bin/count-lattice-points-inside-a-circle.rs new file mode 100644 index 00000000..3172a42c --- /dev/null +++ b/src/bin/count-lattice-points-inside-a-circle.rs @@ -0,0 +1,34 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_lattice_points(circles: Vec>) -> i32 { + let mut max_x = -1; + let mut max_y = -1; + let mut min_x = i32::MAX; + let mut min_y = i32::MAX; + let mut result = 0; + for i in circles.iter() { + max_x = max_x.max(i[0] + i[2]); + max_y = max_y.max(i[1] + i[2]); + min_x = min_x.min(i[0] - i[2]); + min_y = min_y.min(i[1] - i[2]); + } + + for i in min_x..=max_x { + for j in min_y..=max_y { + for c in circles.iter() { + if (i - c[0]).pow(2) + (j - c[1]).pow(2) <= c[2].pow(2) { + result += 1; + break; + } + } + } + } + + result + } +} From af7742f7f7d7c3c4b2183a5f64d48db2871b94e9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 5 Jun 2024 10:50:07 +0800 Subject: [PATCH 1431/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 56384172..aa14a141 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 760 | 331 | 401 | 28 | +| 761 | 331 | 402 | 28 | ### 题目 @@ -517,6 +517,7 @@ |2310 | 将数组和减半的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-halve-array-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-halve-array-sum/) | Medium | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |2328 | 向表达式添加括号后的最小结果 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimize-result-by-adding-parentheses-to-expression.rs) | [leetcode](https://leetcode-cn.com/problems/minimize-result-by-adding-parentheses-to-expression/) | Medium | +|2332 | 统计圆内格点数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-lattice-points-inside-a-circle.rs) | [leetcode](https://leetcode-cn.com/problems/count-lattice-points-inside-a-circle/) | Medium | |2346 | 字符串中最大的 3 位相同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-3-same-digit-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-3-same-digit-number-in-string/) | Easy | |2351 | 买钢笔和铅笔的方案数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-ways-to-buy-pens-and-pencils.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-ways-to-buy-pens-and-pencils/) | Medium | |2362 | 完成所有任务需要的最少轮数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-rounds-to-complete-all-tasks.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-rounds-to-complete-all-tasks/) | Medium | From c3e03fa8a5f212eb5c56dbf9c2d2468ce8587971 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 6 Jun 2024 10:56:44 +0800 Subject: [PATCH 1432/1556] src/bin/separate-black-and-white-balls.rs --- src/bin/separate-black-and-white-balls.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/separate-black-and-white-balls.rs diff --git a/src/bin/separate-black-and-white-balls.rs b/src/bin/separate-black-and-white-balls.rs new file mode 100644 index 00000000..8e91d7c9 --- /dev/null +++ b/src/bin/separate-black-and-white-balls.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_steps(s: String) -> i64 { + let mut index = 0; + let mut result = 0; + let s = s.as_bytes(); + for i in 0..s.len() { + if s[i] == b'0' { + result += (i - index) as i64; + index += 1; + } + } + + result + } +} From 92658cfd843e4f71cf1e4e526ce8a9888395b7ae Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 6 Jun 2024 10:56:45 +0800 Subject: [PATCH 1433/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index aa14a141..0ff2f517 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 761 | 331 | 402 | 28 | +| 762 | 331 | 403 | 28 | ### 题目 @@ -623,6 +623,7 @@ |3183 | 找出数组中的 K-or 值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-k-or-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-k-or-of-an-array/) | Easy | |3188 | 找到冠军 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-i/) | Easy | |3189 | 找到冠军 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-ii/) | Medium | +|3195 | 区分黑球与白球 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/separate-black-and-white-balls.rs) | [leetcode](https://leetcode-cn.com/problems/separate-black-and-white-balls/) | Medium | |3199 | 给小朋友们分糖果 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-candies-among-children-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-candies-among-children-i/) | Easy | |3220 | 统计已测试设备 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-tested-devices-after-test-operations.rs) | [leetcode](https://leetcode-cn.com/problems/count-tested-devices-after-test-operations/) | Easy | |3221 | 找出峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-peaks.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-peaks/) | Easy | From 50e177182c2195ce28bd2328d313c98818b1a935 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 7 Jun 2024 11:51:18 +0800 Subject: [PATCH 1434/1556] src/bin/available-captures-for-rook.rs --- src/bin/available-captures-for-rook.rs | 66 ++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/bin/available-captures-for-rook.rs diff --git a/src/bin/available-captures-for-rook.rs b/src/bin/available-captures-for-rook.rs new file mode 100644 index 00000000..d036bd24 --- /dev/null +++ b/src/bin/available-captures-for-rook.rs @@ -0,0 +1,66 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn num_rook_captures(board: Vec>) -> i32 { + let mut index = (0usize, 0usize); + for i in 0..board.len() { + for j in 0..board[0].len() { + if board[i][j] == 'R' { + index = (i, j); + break; + } + } + } + let mut result = 0; + + for i in (0..index.0).rev() { + match board[i][index.1] { + 'B' => break, + 'p' => { + result += 1; + break; + } + _ => {} + } + } + + for i in (index.0..board.len()) { + match board[i][index.1] { + 'B' => break, + 'p' => { + result += 1; + break; + } + _ => {} + } + } + + for i in (0..index.1).rev() { + match board[index.0][i] { + 'B' => break, + 'p' => { + result += 1; + break; + } + _ => {} + } + } + + for i in (index.1..board[0].len()) { + match board[index.0][i] { + 'B' => break, + 'p' => { + result += 1; + break; + } + _ => {} + } + } + + result + } +} From 210cce857903fa7d5480b9edaeab475e84ae7ac8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 7 Jun 2024 11:51:18 +0800 Subject: [PATCH 1435/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ff2f517..18b33087 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 762 | 331 | 403 | 28 | +| 763 | 332 | 403 | 28 | ### 题目 @@ -358,6 +358,7 @@ |1021 | 在二叉树中分配硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-coins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-coins-in-binary-tree/) | Medium | |1035 | 二叉树的堂兄弟节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cousins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/cousins-in-binary-tree/) | Easy | |1036 | 腐烂的橘子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotting-oranges.rs) | [leetcode](https://leetcode-cn.com/problems/rotting-oranges/) | Medium | +|1041 | 可以被一步捕获的棋子数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/available-captures-for-rook.rs) | [leetcode](https://leetcode-cn.com/problems/available-captures-for-rook/) | Easy | |1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | |1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | From 3f2cfcf82bf617ce7d8c60906f47dbc65b6b3b2d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 11 Jun 2024 21:10:56 +0800 Subject: [PATCH 1436/1556] src/bin/make-three-strings-equal.rs --- src/bin/make-three-strings-equal.rs | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/make-three-strings-equal.rs diff --git a/src/bin/make-three-strings-equal.rs b/src/bin/make-three-strings-equal.rs new file mode 100644 index 00000000..88895ef6 --- /dev/null +++ b/src/bin/make-three-strings-equal.rs @@ -0,0 +1,31 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_minimum_operations(s1: String, s2: String, s3: String) -> i32 { + let mut a = 0; + let mut index = 0; + loop { + match ( + s1.as_bytes().get(index), + s2.as_bytes().get(index), + s3.as_bytes().get(index), + ) { + (Some(&x1), Some(&x2), Some(&x3)) if x1 == x2 && x2 == x3 => { + a += 1; + index += 1; + } + _ => break, + } + } + + if a == 0 { + -1 + } else { + (s1.len() - a + s2.len() - a + s3.len() - a) as _ + } + } +} From b8da8635291fde431b0f2887d5b34c0191dbff99 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 11 Jun 2024 21:10:56 +0800 Subject: [PATCH 1437/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 18b33087..050f7ddf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 763 | 332 | 403 | 28 | +| 764 | 333 | 403 | 28 | ### 题目 @@ -626,6 +626,7 @@ |3189 | 找到冠军 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-ii/) | Medium | |3195 | 区分黑球与白球 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/separate-black-and-white-balls.rs) | [leetcode](https://leetcode-cn.com/problems/separate-black-and-white-balls/) | Medium | |3199 | 给小朋友们分糖果 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-candies-among-children-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-candies-among-children-i/) | Easy | +|3207 | 使三个字符串相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-three-strings-equal.rs) | [leetcode](https://leetcode-cn.com/problems/make-three-strings-equal/) | Easy | |3220 | 统计已测试设备 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-tested-devices-after-test-operations.rs) | [leetcode](https://leetcode-cn.com/problems/count-tested-devices-after-test-operations/) | Easy | |3221 | 找出峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-peaks.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-peaks/) | Easy | |3227 | 找出缺失和重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-missing-and-repeated-values.rs) | [leetcode](https://leetcode-cn.com/problems/find-missing-and-repeated-values/) | Easy | From c48e178147fa332ca19d0f98af76c200785dab56 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 12 Jun 2024 07:44:30 +0800 Subject: [PATCH 1438/1556] src/bin/account-balance-after-rounded-purchase.rs --- .../account-balance-after-rounded-purchase.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/bin/account-balance-after-rounded-purchase.rs diff --git a/src/bin/account-balance-after-rounded-purchase.rs b/src/bin/account-balance-after-rounded-purchase.rs new file mode 100644 index 00000000..84992ff1 --- /dev/null +++ b/src/bin/account-balance-after-rounded-purchase.rs @@ -0,0 +1,16 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn account_balance_after_purchase(purchase_amount: i32) -> i32 { + let a = purchase_amount % 10; + 100 - if a >= 5 { + purchase_amount + (10 - a) + } else { + purchase_amount - a + } + } +} From df4230400e7bf03a4219d0063d2f0b1dc2e4172b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 12 Jun 2024 07:44:30 +0800 Subject: [PATCH 1439/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 050f7ddf..54536343 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 764 | 333 | 403 | 28 | +| 765 | 334 | 403 | 28 | ### 题目 @@ -611,6 +611,7 @@ |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | |2920 | 使循环数组所有元素相等的最少秒数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-seconds-to-equalize-a-circular-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-seconds-to-equalize-a-circular-array/) | Medium | |2954 | 几乎唯一子数组的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-of-almost-unique-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-of-almost-unique-subarray/) | Medium | +|2955 | 取整购买后的账户余额 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/account-balance-after-rounded-purchase.rs) | [leetcode](https://leetcode-cn.com/problems/account-balance-after-rounded-purchase/) | Easy | |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | |3026 | 找出美丽数组的最小和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-minimum-possible-sum-of-a-beautiful-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-minimum-possible-sum-of-a-beautiful-array/) | Medium | |3045 | 使数组成为递增数组的最少右移次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-right-shifts-to-sort-the-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-right-shifts-to-sort-the-array/) | Easy | From 3194da914e96a942ad3ed24c8de65eaaf7c2eb08 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 13 Jun 2024 20:03:15 +0800 Subject: [PATCH 1440/1556] src/bin/maximum-number-of-words-you-can-type.rs --- .../maximum-number-of-words-you-can-type.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/maximum-number-of-words-you-can-type.rs diff --git a/src/bin/maximum-number-of-words-you-can-type.rs b/src/bin/maximum-number-of-words-you-can-type.rs new file mode 100644 index 00000000..4d695259 --- /dev/null +++ b/src/bin/maximum-number-of-words-you-can-type.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn can_be_typed_words(text: String, broken_letters: String) -> i32 { + let mut s = [0; 26]; + for &i in broken_letters.as_bytes() { + s[(i - b'a') as usize] = 1; + } + + let mut res = 0; + 'l: for i in text.split(' ') { + for &j in i.as_bytes() { + if s[(j - b'a') as usize] == 1 { + continue 'l; + } + } + + res += 1; + } + + res + } +} From 5427e1d679274b108094474464da5449ead49764 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 13 Jun 2024 20:03:15 +0800 Subject: [PATCH 1441/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 54536343..acbed309 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 765 | 334 | 403 | 28 | +| 766 | 335 | 403 | 28 | ### 题目 @@ -382,6 +382,7 @@ |1253 | 将矩阵按对角线排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-the-matrix-diagonally.rs) | [leetcode](https://leetcode-cn.com/problems/sort-the-matrix-diagonally/) | Medium | |1260 | 一年中的第几天 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/day-of-the-year.rs) | [leetcode](https://leetcode-cn.com/problems/day-of-the-year/) | Easy | |1263 | 掷骰子等于目标和的方法数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-dice-rolls-with-target-sum.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-dice-rolls-with-target-sum/) | Medium | +|1264 | 可以输入的最大单词数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-words-you-can-type.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-words-you-can-type/) | Easy | |1273 | 比较字符串最小字母出现频次 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/compare-strings-by-frequency-of-the-smallest-character.rs) | [leetcode](https://leetcode-cn.com/problems/compare-strings-by-frequency-of-the-smallest-character/) | Medium | |1287 | 公交站间的距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distance-between-bus-stops.rs) | [leetcode](https://leetcode-cn.com/problems/distance-between-bus-stops/) | Easy | |1289 | 一周中的第几天 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/day-of-the-week.rs) | [leetcode](https://leetcode-cn.com/problems/day-of-the-week/) | Easy | From 7e6d2ff48c62d385657bd029cd9abc2fd9d32493 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 14 Jun 2024 08:49:41 +0800 Subject: [PATCH 1442/1556] src/bin/visit-array-positions-to-maximize-score.rs --- ...visit-array-positions-to-maximize-score.rs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/bin/visit-array-positions-to-maximize-score.rs diff --git a/src/bin/visit-array-positions-to-maximize-score.rs b/src/bin/visit-array-positions-to-maximize-score.rs new file mode 100644 index 00000000..bf4f2c2b --- /dev/null +++ b/src/bin/visit-array-positions-to-maximize-score.rs @@ -0,0 +1,52 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!(Solution::max_score(vec![2, 3, 6, 1, 9, 2], 5), 13); + assert_eq!(Solution::max_score(vec![2, 4, 6, 8], 3), 20); + assert_eq!( + Solution::max_score( + vec![ + 18, 13, 60, 61, 57, 21, 10, 98, 51, 3, 13, 36, 72, 70, 68, 62, 52, 83, 63, 63, 53, + 42, 59, 98, 95, 48, 22, 64, 94, 80, 14, 14 + ], + 2 + ), + 1633 + ); + assert_eq!( + Solution::max_score( + vec![ + 38, 92, 23, 30, 25, 96, 6, 71, 78, 77, 33, 23, 71, 48, 87, 77, 53, 28, 6, 20, 90, + 83, 42, 21, 64, 95, 84, 29, 22, 21, 33, 36, 53, 51, 85, 25, 80, 56, 71, 69, 5, 21, + 4, 84, 28, 16, 65, 7 + ], + 52 + ), + 1545 + ); +} + +struct Solution; + +impl Solution { + pub fn max_score(nums: Vec, x: i32) -> i64 { + let (mut a, mut b) = (i64::MIN, i64::MIN); // a为奇最大值,b为偶最大值 + if nums[0] % 2 == 0 { + b = nums[0] as i64; + } else { + a = nums[0] as i64; + } + + let x = x as i64; + for &i in nums[1..].iter() { + let i = i as i64; + if i % 2 == 0 { + b = (b + i).max(if a == i64::MIN { 0 } else { a } + i - x) + } else { + a = (a + i).max(if b == i64::MIN { 0 } else { b } + i - x) + } + } + + a.max(b) + } +} From 1d43f2f5f4f1f73d4185e475a2890fe432d7b86a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 14 Jun 2024 08:49:41 +0800 Subject: [PATCH 1443/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index acbed309..4da54cb1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 766 | 335 | 403 | 28 | +| 767 | 335 | 404 | 28 | ### 题目 @@ -609,6 +609,7 @@ |2876 | 满足目标工作时长的员工数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-employees-who-met-the-target.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-employees-who-met-the-target/) | Easy | |2881 | 按分隔符拆分字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/split-strings-by-separator.rs) | [leetcode](https://leetcode-cn.com/problems/split-strings-by-separator/) | Easy | |2886 | 故障键盘 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/faulty-keyboard.rs) | [leetcode](https://leetcode-cn.com/problems/faulty-keyboard/) | Easy | +|2893 | 访问数组中的位置使分数最大 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/visit-array-positions-to-maximize-score.rs) | [leetcode](https://leetcode-cn.com/problems/visit-array-positions-to-maximize-score/) | Medium | |2917 | 统计和小于目标的下标对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-pairs-whose-sum-is-less-than-target.rs) | [leetcode](https://leetcode-cn.com/problems/count-pairs-whose-sum-is-less-than-target/) | Easy | |2920 | 使循环数组所有元素相等的最少秒数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-seconds-to-equalize-a-circular-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-seconds-to-equalize-a-circular-array/) | Medium | |2954 | 几乎唯一子数组的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-sum-of-almost-unique-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-sum-of-almost-unique-subarray/) | Medium | From a4b751c6a12a78dea5d43cace39c6229b9db5c07 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 16 Jun 2024 23:12:03 +0800 Subject: [PATCH 1444/1556] src/bin/longest-uncommon-subsequence-i.rs --- src/bin/longest-uncommon-subsequence-i.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/bin/longest-uncommon-subsequence-i.rs diff --git a/src/bin/longest-uncommon-subsequence-i.rs b/src/bin/longest-uncommon-subsequence-i.rs new file mode 100644 index 00000000..51ec4e5d --- /dev/null +++ b/src/bin/longest-uncommon-subsequence-i.rs @@ -0,0 +1,15 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_lu_slength(a: String, b: String) -> i32 { + if a == b { + -1 + } else { + (a.len().max(b.len())) as _ + } + } +} From 77b42bd86a434cd5c934c4c0789642bca9834fa9 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 16 Jun 2024 23:12:03 +0800 Subject: [PATCH 1445/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4da54cb1..769a3eca 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 767 | 335 | 404 | 28 | +| 768 | 336 | 404 | 28 | ### 题目 @@ -268,6 +268,7 @@ |516 | 最长回文子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-palindromic-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-palindromic-subsequence/) | Medium | |518 | 零钱兑换 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/coin-change-ii.rs) | [leetcode](https://leetcode-cn.com/problems/coin-change-ii/) | Medium | |520 | 检测大写字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/detect-capital.rs) | [leetcode](https://leetcode-cn.com/problems/detect-capital/) | Easy | +|521 | 最长特殊序列 Ⅰ | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-uncommon-subsequence-i.rs) | [leetcode](https://leetcode-cn.com/problems/longest-uncommon-subsequence-i/) | Easy | |528 | 交换链表中的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/swapping-nodes-in-a-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/swapping-nodes-in-a-linked-list/) | Medium | |530 | 二叉搜索树的最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference-in-bst.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/) | Easy | |535 | TinyURL 的加密与解密 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/encode-and-decode-tinyurl.rs) | [leetcode](https://leetcode-cn.com/problems/encode-and-decode-tinyurl/) | Medium | From 22bba089f9b5e3a36d662151881776d096911e7e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 17 Jun 2024 20:50:28 +0800 Subject: [PATCH 1446/1556] src/bin/minimum-moves-to-reach-target-score.rs --- .../minimum-moves-to-reach-target-score.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/bin/minimum-moves-to-reach-target-score.rs diff --git a/src/bin/minimum-moves-to-reach-target-score.rs b/src/bin/minimum-moves-to-reach-target-score.rs new file mode 100644 index 00000000..b40383b8 --- /dev/null +++ b/src/bin/minimum-moves-to-reach-target-score.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_moves(target: i32, max_doubles: i32) -> i32 { + let mut max_doubles = max_doubles; + let mut target = target; + let mut result = 0; + while target > 1 { + if target % 2 == 1 { + target -= 1; + result += 1; + } else { + if max_doubles > 0 { + target /= 2; + result += 1; + max_doubles -= 1; + } else { + result += target - 1; + target = 1; + } + } + } + + result + } +} From 79b873c9dd8ae920a0273fd31472787cd27dc974 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 17 Jun 2024 20:50:29 +0800 Subject: [PATCH 1447/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 769a3eca..0c4a5534 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 768 | 336 | 404 | 28 | +| 769 | 336 | 405 | 28 | ### 题目 @@ -389,6 +389,7 @@ |1289 | 一周中的第几天 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/day-of-the-week.rs) | [leetcode](https://leetcode-cn.com/problems/day-of-the-week/) | Easy | |1293 | 存在连续三个奇数的数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/three-consecutive-odds.rs) | [leetcode](https://leetcode-cn.com/problems/three-consecutive-odds/) | Easy | |1295 | 收集足够苹果的最小花园周长 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-garden-perimeter-to-collect-enough-apples.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-garden-perimeter-to-collect-enough-apples/) | Medium | +|1303 | 得到目标值的最少行动次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-moves-to-reach-target-score.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-moves-to-reach-target-score/) | Medium | |1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | |1310 | 给植物浇水 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/watering-plants.rs) | [leetcode](https://leetcode-cn.com/problems/watering-plants/) | Medium | |1310 | 给植物浇水 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/watering-plants.rs) | [leetcode](https://leetcode-cn.com/problems/watering-plants/) | Medium | From c2ba34d136e93f7db3f9a8d0d6b439616cff8603 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 18 Jun 2024 08:03:21 +0800 Subject: [PATCH 1448/1556] src/bin/apply-discount-to-prices.rs --- src/bin/apply-discount-to-prices.rs | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/bin/apply-discount-to-prices.rs diff --git a/src/bin/apply-discount-to-prices.rs b/src/bin/apply-discount-to-prices.rs new file mode 100644 index 00000000..e551e405 --- /dev/null +++ b/src/bin/apply-discount-to-prices.rs @@ -0,0 +1,33 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn discount_prices(sentence: String, discount: i32) -> String { + let mut result = String::new(); + + for mut s in sentence.split(' ') { + if s.starts_with('$') { + result.push('$'); + s = &s[1..]; + + match s.parse::() { + Ok(i) => result.push_str(&format!( + "{:.2}", + i as f64 * (1.0 - discount as f64 / 100.0) + )), + _ => result.push_str(s), + } + } else { + result.push_str(s); + } + + result.push(' '); + } + + result.pop(); + result + } +} From f4e43c0d5c7eb66bcbc181ac9a65e4189f18d0be Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 18 Jun 2024 08:03:22 +0800 Subject: [PATCH 1449/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c4a5534..2fd4e3f6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 769 | 336 | 405 | 28 | +| 770 | 336 | 406 | 28 | ### 题目 @@ -525,6 +525,7 @@ |2346 | 字符串中最大的 3 位相同数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/largest-3-same-digit-number-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/largest-3-same-digit-number-in-string/) | Easy | |2351 | 买钢笔和铅笔的方案数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-ways-to-buy-pens-and-pencils.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-ways-to-buy-pens-and-pencils/) | Medium | |2362 | 完成所有任务需要的最少轮数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-rounds-to-complete-all-tasks.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-rounds-to-complete-all-tasks/) | Medium | +|2373 | 价格减免 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apply-discount-to-prices.rs) | [leetcode](https://leetcode-cn.com/problems/apply-discount-to-prices/) | Medium | |2378 | 最多单词数的发件人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sender-with-largest-word-count.rs) | [leetcode](https://leetcode-cn.com/problems/sender-with-largest-word-count/) | Medium | |2384 | 判断根结点是否等于子结点之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/root-equals-sum-of-children.rs) | [leetcode](https://leetcode-cn.com/problems/root-equals-sum-of-children/) | Easy | |2386 | 极大极小游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/min-max-game.rs) | [leetcode](https://leetcode-cn.com/problems/min-max-game/) | Easy | From 638b4a9ac69b2c323598ee71457fe3e842ecd722 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 19 Jun 2024 07:30:02 +0800 Subject: [PATCH 1450/1556] src/bin/nGK0Fy.rs --- src/bin/nGK0Fy.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/nGK0Fy.rs diff --git a/src/bin/nGK0Fy.rs b/src/bin/nGK0Fy.rs new file mode 100644 index 00000000..b3041960 --- /dev/null +++ b/src/bin/nGK0Fy.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn calculate(s: String) -> i32 { + let (mut x, mut y) = (1, 0); + for i in s.bytes() { + match i { + b'A' => x = 2 * x + y, + b'B' => y = 2 * y + x, + _ => unreachable!(), + } + } + + x + y + } +} From 0693bb34f7d677ede2ed9ba6b94399d21b14100d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 19 Jun 2024 07:30:03 +0800 Subject: [PATCH 1451/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2fd4e3f6..007b792c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 770 | 336 | 406 | 28 | +| 771 | 337 | 406 | 28 | ### 题目 @@ -729,6 +729,7 @@ |1000025 | 不用加号的加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-without-plus-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/add-without-plus-lcci/) | Easy | |1000056 | 拿硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/na-ying-bi.rs) | [leetcode](https://leetcode-cn.com/problems/na-ying-bi/) | Easy | |1000063 | 传递信息 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/chuan-di-xin-xi.rs) | [leetcode](https://leetcode-cn.com/problems/chuan-di-xin-xi/) | Easy | +|1000139 | 速算机器人 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/nGK0Fy.rs) | [leetcode](https://leetcode-cn.com/problems/nGK0Fy/) | Easy | |1000224 | 魔塔游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/p0NxJO.rs) | [leetcode](https://leetcode-cn.com/problems/p0NxJO/) | Medium | |1000225 | 下载插件 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/Ju9Xwi.rs) | [leetcode](https://leetcode-cn.com/problems/Ju9Xwi/) | Easy | |1000228 | 整数除法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/xoh6Oh.rs) | [leetcode](https://leetcode-cn.com/problems/xoh6Oh/) | Easy | From f883ee4758fd61f215aee6db583625d2106fe099 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 20 Jun 2024 07:51:42 +0800 Subject: [PATCH 1452/1556] src/bin/number-of-beautiful-pairs.rs --- src/bin/number-of-beautiful-pairs.rs | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/bin/number-of-beautiful-pairs.rs diff --git a/src/bin/number-of-beautiful-pairs.rs b/src/bin/number-of-beautiful-pairs.rs new file mode 100644 index 00000000..4b25e6f6 --- /dev/null +++ b/src/bin/number-of-beautiful-pairs.rs @@ -0,0 +1,48 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() { + assert_eq!( + Solution::count_beautiful_pairs(vec![84, 91, 18, 59, 27, 9, 81, 33, 17, 58],), + 37 + ); +} + +struct Solution; + +impl Solution { + pub fn count_beautiful_pairs(nums: Vec) -> i32 { + let m = [ + [0; 10], + [0, 1, 1, 1, 1, 1, 1, 1, 1, 1], // 1 + [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], // 2 + [0, 1, 1, 0, 1, 1, 0, 1, 1, 0], // 3 + [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], // 4 + [0, 1, 1, 1, 1, 0, 1, 1, 1, 1], // 5 + [0, 1, 0, 0, 0, 1, 0, 1, 0, 0], // 6 + [0, 1, 1, 1, 1, 1, 1, 0, 1, 1], // 7 + [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], // 8 + [0, 1, 1, 0, 1, 1, 0, 1, 1, 0], // 9 + ]; + + let f = |mut x: i32| -> i32 { + while x > 9 { + x /= 10; + } + x + }; + + let mut result = 0; + for i in 0..nums.len() { + for j in i + 1..nums.len() { + let x = (nums[j] % 10) as usize; + let y = f(nums[i]) as usize; + + if m[x][y] == 1 { + result += 1; + } + } + } + + result + } +} From b3746daa127db2a2468b4c91a2a69b2fc3605ada Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 20 Jun 2024 07:51:43 +0800 Subject: [PATCH 1453/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 007b792c..39d5cd35 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 771 | 337 | 406 | 28 | +| 772 | 338 | 406 | 28 | ### 题目 @@ -603,6 +603,7 @@ |2802 | 求一个整数的惩罚数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-punishment-number-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-punishment-number-of-an-integer/) | Medium | |2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | |2816 | 字典序最小回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographically-smallest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographically-smallest-palindrome/) | Easy | +|2831 | 美丽下标对的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-beautiful-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-beautiful-pairs/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |2847 | 最大字符串配对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-maximum-number-of-string-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/find-maximum-number-of-string-pairs/) | Easy | |2857 | 总行驶距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/total-distance-traveled.rs) | [leetcode](https://leetcode-cn.com/problems/total-distance-traveled/) | Easy | From 5344685487a4f3ebdd8e6eab52feabe82cc84f4d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 21 Jun 2024 21:36:51 +0800 Subject: [PATCH 1454/1556] src/bin/6CE719.rs --- src/bin/6CE719.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/bin/6CE719.rs diff --git a/src/bin/6CE719.rs b/src/bin/6CE719.rs new file mode 100644 index 00000000..82508619 --- /dev/null +++ b/src/bin/6CE719.rs @@ -0,0 +1,26 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn temperature_trend(temperature_a: Vec, temperature_b: Vec) -> i32 { + let mut result = 0; + let mut current = 0; + + for i in 1..temperature_a.len() { + if temperature_a[i - 1].cmp(&temperature_a[i]) + == temperature_b[i - 1].cmp(&temperature_b[i]) + { + current += 1; + } else { + current = 0; + } + + result = result.max(current); + } + + result + } +} From 6af640cf8a15861fd964ec378fb66a7e9fea101a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 21 Jun 2024 21:36:51 +0800 Subject: [PATCH 1455/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 39d5cd35..3c717305 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 772 | 338 | 406 | 28 | +| 773 | 339 | 406 | 28 | ### 题目 @@ -780,3 +780,4 @@ |1000333 | 山峰数组的顶部 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/B1IidL.rs) | [leetcode](https://leetcode-cn.com/problems/B1IidL/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | |1000433 | 宝石补给 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WHnhjV.rs) | [leetcode](https://leetcode-cn.com/problems/WHnhjV/) | Easy | +|1000476 | 气温变化趋势 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/6CE719.rs) | [leetcode](https://leetcode-cn.com/problems/6CE719/) | Easy | From 118836c0ac4e16099d4175a1240ba09d76757ab4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 22 Jun 2024 11:28:14 +0800 Subject: [PATCH 1456/1556] src/bin/occurrences-after-bigram.rs --- src/bin/occurrences-after-bigram.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/bin/occurrences-after-bigram.rs diff --git a/src/bin/occurrences-after-bigram.rs b/src/bin/occurrences-after-bigram.rs new file mode 100644 index 00000000..8d886927 --- /dev/null +++ b/src/bin/occurrences-after-bigram.rs @@ -0,0 +1,24 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_ocurrences(text: String, first: String, second: String) -> Vec { + let mut result = vec![]; + let mut n = text.split(' '); + let mut f = n.next().unwrap(); + let mut is_result = false; + while let Some(x) = n.next() { + if is_result { + result.push(x.to_string()); + } + + is_result = f == first && x == second; + f = x; + } + + result + } +} From 6f023fe764037a900187f5dbc14c12622e6a729e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 22 Jun 2024 11:28:15 +0800 Subject: [PATCH 1457/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c717305..8a930804 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 773 | 339 | 406 | 28 | +| 774 | 340 | 406 | 28 | ### 题目 @@ -372,6 +372,7 @@ |1128 | 删除字符串中的所有相邻重复项 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-all-adjacent-duplicates-in-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/) | Easy | |1138 | 爱生气的书店老板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/grumpy-bookstore-owner.rs) | [leetcode](https://leetcode-cn.com/problems/grumpy-bookstore-owner/) | Medium | |1146 | 字符串的最大公因子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/greatest-common-divisor-of-strings.rs) | [leetcode](https://leetcode-cn.com/problems/greatest-common-divisor-of-strings/) | Easy | +|1156 | Bigram 分词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/occurrences-after-bigram.rs) | [leetcode](https://leetcode-cn.com/problems/occurrences-after-bigram/) | Easy | |1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | |1168 | 复写零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/duplicate-zeros.rs) | [leetcode](https://leetcode-cn.com/problems/duplicate-zeros/) | Easy | |1184 | 拼车 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/car-pooling.rs) | [leetcode](https://leetcode-cn.com/problems/car-pooling/) | Medium | From 7e836e140ccd6871544705d66cdafee21fea2d47 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 23 Jun 2024 10:23:04 +0800 Subject: [PATCH 1458/1556] src/bin/minimum-distance-between-bst-nodes.rs --- src/bin/minimum-distance-between-bst-nodes.rs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/bin/minimum-distance-between-bst-nodes.rs diff --git a/src/bin/minimum-distance-between-bst-nodes.rs b/src/bin/minimum-distance-between-bst-nodes.rs new file mode 100644 index 00000000..e8f2e3c5 --- /dev/null +++ b/src/bin/minimum-distance-between-bst-nodes.rs @@ -0,0 +1,53 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::cell::RefCell; +use std::rc::Rc; + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +impl Solution { + pub fn min_diff_in_bst(root: Option>>) -> i32 { + fn expand(root: Option>>, list: &mut Vec) { + if root.is_none() { + return; + } + // 中序遍历,因为这是二叉搜索树 + let root = root.unwrap(); + expand(root.borrow_mut().left.take(), list); + list.push(root.borrow().val); + expand(root.borrow_mut().right.take(), list); + } + + let mut list = vec![]; + expand(root, &mut list); + + let mut result = i32::MAX; + + for i in 1..list.len() { + result = result.min(list[i] - list[i - 1]); + } + + result + } +} From 32246d8bf2234ae4a0b469a2a89d15b9f6ac8aed Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 23 Jun 2024 10:23:05 +0800 Subject: [PATCH 1459/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8a930804..3adf06d6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 774 | 340 | 406 | 28 | +| 775 | 341 | 406 | 28 | ### 题目 @@ -306,6 +306,7 @@ |782 | 宝石与石头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/jewels-and-stones.rs) | [leetcode](https://leetcode-cn.com/problems/jewels-and-stones/) | Easy | |783 | 二叉搜索树中的搜索 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/search-in-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/search-in-a-binary-search-tree/) | Easy | |784 | 二叉搜索树中的插入操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insert-into-a-binary-search-tree.rs) | [leetcode](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/) | Medium | +|799 | 二叉搜索树节点最小距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-distance-between-bst-nodes.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-distance-between-bst-nodes/) | Easy | |800 | 字母大小写全排列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/letter-case-permutation.rs) | [leetcode](https://leetcode-cn.com/problems/letter-case-permutation/) | Medium | |816 | 设计哈希集合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-hashset.rs) | [leetcode](https://leetcode-cn.com/problems/design-hashset/) | Easy | |817 | 设计哈希映射 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-hashmap.rs) | [leetcode](https://leetcode-cn.com/problems/design-hashmap/) | Easy | From cce4b53a2dc7717950126ccede97a808cfb0d0c0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 25 Jun 2024 21:53:05 +0800 Subject: [PATCH 1460/1556] src/bin/find-winner-on-a-tic-tac-toe-game.rs --- src/bin/find-winner-on-a-tic-tac-toe-game.rs | 91 ++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/bin/find-winner-on-a-tic-tac-toe-game.rs diff --git a/src/bin/find-winner-on-a-tic-tac-toe-game.rs b/src/bin/find-winner-on-a-tic-tac-toe-game.rs new file mode 100644 index 00000000..0ea26935 --- /dev/null +++ b/src/bin/find-winner-on-a-tic-tac-toe-game.rs @@ -0,0 +1,91 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn tictactoe(moves: Vec>) -> String { + let mut s = [['C'; 3]; 3]; + let mut flag = 'A'; + for i in moves.iter() { + s[i[0] as usize][i[1] as usize] = flag; + + if i[0] == 0 { + if i[1] == 0 { + if (s[0][1] == flag && s[0][2] == flag) + || (s[1][0] == flag && s[2][0] == flag) + || (s[1][1] == flag && s[2][2] == flag) + { + return flag.to_string(); + } + } else if i[1] == 1 { + if (s[0][0] == flag && s[0][2] == flag) || (s[1][1] == flag && s[2][1] == flag) + { + return flag.to_string(); + } + } else { + if (s[0][1] == flag && s[0][0] == flag) + || (s[1][2] == flag && s[2][2] == flag) + || (s[1][1] == flag && s[2][0] == flag) + { + return flag.to_string(); + } + } + } else if i[0] == 1 { + if i[1] == 0 { + if (s[1][1] == flag && s[1][2] == flag) || (s[0][0] == flag && s[2][0] == flag) + { + return flag.to_string(); + } + } else if i[1] == 1 { + if (s[1][0] == flag && s[1][2] == flag) + || (s[0][1] == flag && s[2][1] == flag) + || (s[0][0] == flag && s[2][2] == flag) + || (s[0][2] == flag && s[2][0] == flag) + { + return flag.to_string(); + } + } else { + if (s[0][2] == flag && s[2][2] == flag) || (s[1][0] == flag && s[1][1] == flag) + { + return flag.to_string(); + } + } + } else { + if i[1] == 0 { + if (s[2][1] == flag && s[2][2] == flag) + || (s[0][0] == flag && s[1][0] == flag) + || s[1][1] == flag && s[0][2] == flag + { + return flag.to_string(); + } + } else if i[1] == 1 { + if (s[2][0] == flag && s[2][2] == flag) || (s[1][1] == flag && s[0][1] == flag) + { + return flag.to_string(); + } + } else { + if (s[2][0] == flag && s[2][1] == flag) + || (s[1][2] == flag && s[0][2] == flag) + || (s[0][0] == flag && s[1][1] == flag) + { + return flag.to_string(); + } + } + } + + if flag == 'A' { + flag = 'B'; + } else { + flag = 'A'; + } + } + + if moves.len() < 9 { + "Pending".into() + } else { + "Draw".into() + } + } +} From 970235a17bf93b45bc48e0a1047ac6ef31e9900c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 25 Jun 2024 21:53:05 +0800 Subject: [PATCH 1461/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3adf06d6..bad3f68b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 775 | 341 | 406 | 28 | +| 776 | 342 | 406 | 28 | ### 题目 @@ -415,6 +415,7 @@ |1395 | 访问所有点的最小时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-time-visiting-all-points.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-time-visiting-all-points/) | Easy | |1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | |1396 | 统计参与通信的服务器 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-servers-that-communicate.rs) | [leetcode](https://leetcode-cn.com/problems/count-servers-that-communicate/) | Medium | +|1400 | 找出井字棋的获胜者 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-winner-on-a-tic-tac-toe-game.rs) | [leetcode](https://leetcode-cn.com/problems/find-winner-on-a-tic-tac-toe-game/) | Easy | |1401 | 不浪费原料的汉堡制作方案 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-burgers-with-no-waste-of-ingredients.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-burgers-with-no-waste-of-ingredients/) | Medium | |1406 | 整数的各位积和之差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subtract-the-product-and-sum-of-digits-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/) | Easy | |1411 | 二进制链表转整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-binary-number-in-a-linked-list-to-integer.rs) | [leetcode](https://leetcode-cn.com/problems/convert-binary-number-in-a-linked-list-to-integer/) | Easy | From 6aed89ccfaf8ef4bb01cd8c143bae0344633ba5d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 26 Jun 2024 08:18:08 +0800 Subject: [PATCH 1462/1556] src/bin/maximum-difference-by-remapping-a-digit.rs --- ...maximum-difference-by-remapping-a-digit.rs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/bin/maximum-difference-by-remapping-a-digit.rs diff --git a/src/bin/maximum-difference-by-remapping-a-digit.rs b/src/bin/maximum-difference-by-remapping-a-digit.rs new file mode 100644 index 00000000..5d0bf6aa --- /dev/null +++ b/src/bin/maximum-difference-by-remapping-a-digit.rs @@ -0,0 +1,53 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_max_difference(num: i32) -> i32 { + Self::max(num) - Self::min(num) + } + + fn max(mut num: i32) -> i32 { + let mut s = vec![]; + let mut first = 0; + while num > 0 { + let x = num % 10; + if x != 9 { + first = x; + } + s.push(x); + num /= 10; + } + + let mut n = 0; + while let Some(x) = s.pop() { + if x == first { + n = n * 10 + 9; + } else { + n = n * 10 + x; + } + } + n + } + + fn min(mut num: i32) -> i32 { + let mut s = vec![]; + while num > 0 { + s.push(num % 10); + num /= 10; + } + + let mut n = 0; + let mut first = s[s.len() - 1]; + while let Some(x) = s.pop() { + if x == first { + n = n * 10 + 0; + } else { + n = n * 10 + x; + } + } + n + } +} From 6ba6417dfbfc070efd46a6a1c7f7ed37af075520 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 26 Jun 2024 08:18:09 +0800 Subject: [PATCH 1463/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bad3f68b..7756d265 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 776 | 342 | 406 | 28 | +| 777 | 343 | 406 | 28 | ### 题目 @@ -584,6 +584,7 @@ |2692 | 从数量最多的堆取走礼物 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/take-gifts-from-the-richest-pile.rs) | [leetcode](https://leetcode-cn.com/problems/take-gifts-from-the-richest-pile/) | Easy | |2694 | 找出可整除性得分最大的整数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-divisibility-score.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-divisibility-score/) | Easy | |2698 | 找出数组的串联值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-array-concatenation-value.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-array-concatenation-value/) | Easy | +|2704 | 替换一个数字后的最大差值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-difference-by-remapping-a-digit.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-difference-by-remapping-a-digit/) | Easy | |2707 | 合并两个二维数组 - 求和法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-two-2d-arrays-by-summing-values.rs) | [leetcode](https://leetcode-cn.com/problems/merge-two-2d-arrays-by-summing-values/) | Easy | |2713 | 找出字符串的可整除数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-divisibility-array-of-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-divisibility-array-of-a-string/) | Medium | |2715 | K 件物品的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/k-items-with-the-maximum-sum.rs) | [leetcode](https://leetcode-cn.com/problems/k-items-with-the-maximum-sum/) | Easy | From f5a9bb79884194653ddb04fbccd18c7217b9823f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 27 Jun 2024 07:46:37 +0800 Subject: [PATCH 1464/1556] src/bin/lexicographically-smallest-string-after-substring-operation.rs --- ...allest-string-after-substring-operation.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/lexicographically-smallest-string-after-substring-operation.rs diff --git a/src/bin/lexicographically-smallest-string-after-substring-operation.rs b/src/bin/lexicographically-smallest-string-after-substring-operation.rs new file mode 100644 index 00000000..fd03bab2 --- /dev/null +++ b/src/bin/lexicographically-smallest-string-after-substring-operation.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn smallest_string(s: String) -> String { + let s = s.as_bytes(); + let mut s1 = vec![]; + let mut flag = false; + for i in 0..s.len() { + if s[i] == b'a' && i != s.len() - 1 { + if flag { + s1.extend_from_slice(&s[i..]); + break; + } else { + s1.push(b'a'); + } + } else { + flag = true; + if s[i] != b'a' { + s1.push(s[i] - 1); + } else { + s1.push(b'a'); + } + } + } + + unsafe { String::from_utf8_unchecked(s1) } + } +} From d8abd7495455fb6162adc5e9005dff08364ecc1a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 27 Jun 2024 07:46:38 +0800 Subject: [PATCH 1465/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7756d265..99105de8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 777 | 343 | 406 | 28 | +| 778 | 343 | 407 | 28 | ### 题目 @@ -607,6 +607,7 @@ |2802 | 求一个整数的惩罚数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-punishment-number-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-punishment-number-of-an-integer/) | Medium | |2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | |2816 | 字典序最小回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographically-smallest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographically-smallest-palindrome/) | Easy | +|2828 | 执行子串操作后的字典序最小字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographically-smallest-string-after-substring-operation.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographically-smallest-string-after-substring-operation/) | Medium | |2831 | 美丽下标对的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-beautiful-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-beautiful-pairs/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | |2847 | 最大字符串配对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-maximum-number-of-string-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/find-maximum-number-of-string-pairs/) | Easy | From b08010734b25fd7b776a759bbf020e773a45a71b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 28 Jun 2024 08:24:48 +0800 Subject: [PATCH 1466/1556] src/bin/sort-integers-by-the-power-value.rs --- src/bin/sort-integers-by-the-power-value.rs | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/bin/sort-integers-by-the-power-value.rs diff --git a/src/bin/sort-integers-by-the-power-value.rs b/src/bin/sort-integers-by-the-power-value.rs new file mode 100644 index 00000000..00598be6 --- /dev/null +++ b/src/bin/sort-integers-by-the-power-value.rs @@ -0,0 +1,40 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn get_kth(lo: i32, hi: i32, k: i32) -> i32 { + let mut hash = std::collections::HashMap::new(); + let mut s = (lo..=hi).collect::>(); + s.sort_unstable_by(|x, y| { + match Self::weight(*x, &mut hash).cmp(&Self::weight(*y, &mut hash)) { + std::cmp::Ordering::Equal => x.cmp(y), + m => m, + } + }); + + s[k as usize - 1] + } + + fn weight(mut num: i32, hash: &mut std::collections::HashMap) -> i32 { + let mut weight = 0; + while num != 1 { + if let Some(&x) = hash.get(&num) { + weight += x; + break; + } + + if num % 2 == 0 { + num /= 2; + } else { + num = 3 * num + 1; + } + + weight += 1; + } + hash.insert(num, weight); + weight + } +} From 6532124e39b63a33d1c1f16a77790db14fc854ca Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 28 Jun 2024 08:24:49 +0800 Subject: [PATCH 1467/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99105de8..bbb989b0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 778 | 343 | 407 | 28 | +| 779 | 343 | 408 | 28 | ### 题目 @@ -431,6 +431,7 @@ |1472 | 上升下降字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increasing-decreasing-string.rs) | [leetcode](https://leetcode-cn.com/problems/increasing-decreasing-string/) | Easy | |1482 | 有多少小于当前数字的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/how-many-numbers-are-smaller-than-the-current-number.rs) | [leetcode](https://leetcode-cn.com/problems/how-many-numbers-are-smaller-than-the-current-number/) | Easy | |1484 | 二叉树中的链表 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/linked-list-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/linked-list-in-binary-tree/) | Medium | +|1488 | 将整数按权重排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sort-integers-by-the-power-value.rs) | [leetcode](https://leetcode-cn.com/problems/sort-integers-by-the-power-value/) | Medium | |1490 | 生成每种字符都是奇数个的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/generate-a-string-with-characters-that-have-odd-counts.rs) | [leetcode](https://leetcode-cn.com/problems/generate-a-string-with-characters-that-have-odd-counts/) | Easy | |1491 | 二进制字符串前缀一致的次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-times-binary-string-is-prefix-aligned.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-times-binary-string-is-prefix-aligned/) | Medium | |1501 | 圆和矩形是否有重叠 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/circle-and-rectangle-overlapping.rs) | [leetcode](https://leetcode-cn.com/problems/circle-and-rectangle-overlapping/) | Medium | From 1b4d99f6c03dfd8933f0431eab002bf08266c8db Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 1 Jul 2024 08:17:07 +0800 Subject: [PATCH 1468/1556] src/bin/baseball-game.rs --- src/bin/baseball-game.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/bin/baseball-game.rs diff --git a/src/bin/baseball-game.rs b/src/bin/baseball-game.rs new file mode 100644 index 00000000..8e2eda38 --- /dev/null +++ b/src/bin/baseball-game.rs @@ -0,0 +1,28 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn cal_points(operations: Vec) -> i32 { + let mut stack: Vec = vec![]; + for i in operations.iter() { + match i.as_str() { + "C" => _ = stack.pop(), + "D" => { + stack.push(stack[stack.len() - 1] * 2); + } + "+" => { + let x = stack[stack.len() - 1]; + let y = stack[stack.len() - 2]; + stack.push(x + y); + } + + m => stack.push(m.parse().unwrap()), + } + } + + stack.into_iter().sum() + } +} From 945d1c0a4b21226c36cc7047b239e26fdb17a722 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 1 Jul 2024 08:17:07 +0800 Subject: [PATCH 1469/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bbb989b0..d597302a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 779 | 343 | 408 | 28 | +| 780 | 344 | 408 | 28 | ### 题目 @@ -297,6 +297,7 @@ |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |670 | 最大交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-swap.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-swap/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | +|682 | 棒球比赛 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/baseball-game.rs) | [leetcode](https://leetcode-cn.com/problems/baseball-game/) | Easy | |718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | |722 | 删除注释 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-comments.rs) | [leetcode](https://leetcode-cn.com/problems/remove-comments/) | Medium | |724 | 寻找数组的中心下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-pivot-index.rs) | [leetcode](https://leetcode-cn.com/problems/find-pivot-index/) | Easy | From 45ad609c309c35b32ac0d425abe88e720894df3b Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 2 Jul 2024 20:07:36 +0800 Subject: [PATCH 1470/1556] src/bin/maximum-prime-difference.rs --- src/bin/maximum-prime-difference.rs | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/bin/maximum-prime-difference.rs diff --git a/src/bin/maximum-prime-difference.rs b/src/bin/maximum-prime-difference.rs new file mode 100644 index 00000000..18c6712a --- /dev/null +++ b/src/bin/maximum-prime-difference.rs @@ -0,0 +1,41 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +extern crate core; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_prime_difference(nums: Vec) -> i32 { + let first = Self::prime(nums.iter()); + let last = nums.len() - 1 - Self::prime(nums.iter().rev()); + + (last - first) as i32 + } + + fn prime<'a, T: Iterator>(iter: T) -> usize { + fn is_prime(num: i32) -> bool { + if num == 1 { + return false; + } + + for i in 2..num / 2 + 1 { + if num % i == 0 { + return false; + } + } + + true + } + let mut i = 0; + for &v in iter { + if is_prime(v) { + return i; + } + i += 1; + } + + 0 + } +} From 20d58c82663599467c2ca96b266a6c424e22b9b3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 2 Jul 2024 20:07:36 +0800 Subject: [PATCH 1471/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d597302a..114b9fca 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 780 | 344 | 408 | 28 | +| 781 | 344 | 409 | 28 | ### 题目 @@ -651,6 +651,7 @@ |3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | |3334 | 重新分装苹果 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apple-redistribution-into-boxes.rs) | [leetcode](https://leetcode-cn.com/problems/apple-redistribution-into-boxes/) | Easy | |3347 | 将元素分配到两个数组中 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-elements-into-two-arrays-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-elements-into-two-arrays-i/) | Easy | +|3373 | 质数的最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-prime-difference.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-prime-difference/) | Medium | |100160 | URL化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-url-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-url-lcci/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | From 21247944fc6da60479dad4b430d4e998ce2d12af Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Jul 2024 07:41:19 +0800 Subject: [PATCH 1472/1556] src/bin/harshad-number.rs --- src/bin/harshad-number.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/harshad-number.rs diff --git a/src/bin/harshad-number.rs b/src/bin/harshad-number.rs new file mode 100644 index 00000000..c0c248c7 --- /dev/null +++ b/src/bin/harshad-number.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn sum_of_the_digits_of_harshad_number(x: i32) -> i32 { + let mut sum = 0; + let mut x1 = x; + + while x1 > 0 { + sum += x1 % 10; + x1 /= 10; + } + + if x % sum == 0 { + sum + } else { + -1 + } + } +} From 96821cc79a2deb915e099ad439a826cf7421f873 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 3 Jul 2024 07:41:20 +0800 Subject: [PATCH 1473/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 114b9fca..08755d65 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 781 | 344 | 409 | 28 | +| 782 | 345 | 409 | 28 | ### 题目 @@ -651,6 +651,7 @@ |3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | |3334 | 重新分装苹果 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apple-redistribution-into-boxes.rs) | [leetcode](https://leetcode-cn.com/problems/apple-redistribution-into-boxes/) | Easy | |3347 | 将元素分配到两个数组中 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-elements-into-two-arrays-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-elements-into-two-arrays-i/) | Easy | +|3371 | 哈沙德数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/harshad-number.rs) | [leetcode](https://leetcode-cn.com/problems/harshad-number/) | Easy | |3373 | 质数的最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-prime-difference.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-prime-difference/) | Medium | |100160 | URL化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-url-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-url-lcci/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | From 9ab1804a38c5569472fe982d70ff8adfaa42a3dc Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 4 Jul 2024 20:56:21 +0800 Subject: [PATCH 1474/1556] src/bin/count-elements-with-strictly-smaller-and-greater-elements.rs --- ...h-strictly-smaller-and-greater-elements.rs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/bin/count-elements-with-strictly-smaller-and-greater-elements.rs diff --git a/src/bin/count-elements-with-strictly-smaller-and-greater-elements.rs b/src/bin/count-elements-with-strictly-smaller-and-greater-elements.rs new file mode 100644 index 00000000..2f691176 --- /dev/null +++ b/src/bin/count-elements-with-strictly-smaller-and-greater-elements.rs @@ -0,0 +1,54 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_elements1(nums: Vec) -> i32 { + let (mut min, mut max) = (i32::MAX, i32::MIN); + + for &i in nums.iter() { + min = min.min(i); + max = max.max(i); + } + + let mut result = 0; + + for i in nums { + if i > min && i < max { + result += 1; + } + } + + result + } + + /// 统计最大值和最小值的个数,然后总数-最大值和最小值的个数即为结果 + pub fn count_elements(nums: Vec) -> i32 { + let (mut min, mut max) = (nums[0], nums[0]); + let (mut min_count, mut max_count) = (1, 1); + + for &i in nums[1..].iter() { + if i < min { + min = i; + min_count = 1; + } else if i == min { + min_count += 1; + } + + if i > max { + max = i; + max_count = 1; + } else if i == max { + max_count += 1; + } + } + + if min == max { + 0 + } else { + nums.len() as i32 - max_count - min_count + } + } +} From 2ccb8a109759899cd61900e19cae69185cb2f33d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 4 Jul 2024 20:56:22 +0800 Subject: [PATCH 1475/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 08755d65..0182a370 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 782 | 345 | 409 | 28 | +| 783 | 346 | 409 | 28 | ### 题目 @@ -519,6 +519,7 @@ |2235 | 将标题首字母大写 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/capitalize-the-title.rs) | [leetcode](https://leetcode-cn.com/problems/capitalize-the-title/) | Easy | |2243 | 检查是否所有 A 都在 B 之前 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-all-as-appears-before-all-bs.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-all-as-appears-before-all-bs/) | Easy | |2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | +|2269 | 元素计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-elements-with-strictly-smaller-and-greater-elements.rs) | [leetcode](https://leetcode-cn.com/problems/count-elements-with-strictly-smaller-and-greater-elements/) | Easy | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | |2290 | 拿出最少数目的魔法豆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-minimum-number-of-magic-beans.rs) | [leetcode](https://leetcode-cn.com/problems/removing-minimum-number-of-magic-beans/) | Medium | |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | From e829775963dc7b390cd6f0caf47081f36c58bd7d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Jul 2024 20:47:07 +0800 Subject: [PATCH 1476/1556] src/bin/modify-the-matrix.rs --- src/bin/modify-the-matrix.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/modify-the-matrix.rs diff --git a/src/bin/modify-the-matrix.rs b/src/bin/modify-the-matrix.rs new file mode 100644 index 00000000..5c277e51 --- /dev/null +++ b/src/bin/modify-the-matrix.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn modified_matrix(matrix: Vec>) -> Vec> { + let mut matrix = matrix; + + for i in 0..matrix[0].len() { + let max = (0..matrix.len()).map(|x| matrix[x][i]).max().unwrap(); + + for j in 0..matrix.len() { + if matrix[j][i] == -1 { + matrix[j][i] = max; + } + } + } + + matrix + } +} From 32db035beae516f21c6738166d46732ae893929a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 5 Jul 2024 20:47:08 +0800 Subject: [PATCH 1477/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0182a370..ad4e5957 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 783 | 346 | 409 | 28 | +| 784 | 347 | 409 | 28 | ### 题目 @@ -650,6 +650,7 @@ |3265 | 最大好子数组和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-good-subarray-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-good-subarray-sum/) | Medium | |3275 | 输入单词需要的最少按键次数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-pushes-to-type-word-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-pushes-to-type-word-i/) | Easy | |3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | +|3330 | 修改矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/modify-the-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/modify-the-matrix/) | Easy | |3334 | 重新分装苹果 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apple-redistribution-into-boxes.rs) | [leetcode](https://leetcode-cn.com/problems/apple-redistribution-into-boxes/) | Easy | |3347 | 将元素分配到两个数组中 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-elements-into-two-arrays-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-elements-into-two-arrays-i/) | Easy | |3371 | 哈沙德数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/harshad-number.rs) | [leetcode](https://leetcode-cn.com/problems/harshad-number/) | Easy | From aad9683fdda11858ff1e7257ba30523349d65783 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 6 Jul 2024 11:25:11 +0800 Subject: [PATCH 1478/1556] src/bin/count-alternating-subarrays.rs --- src/bin/count-alternating-subarrays.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/count-alternating-subarrays.rs diff --git a/src/bin/count-alternating-subarrays.rs b/src/bin/count-alternating-subarrays.rs new file mode 100644 index 00000000..7d89868e --- /dev/null +++ b/src/bin/count-alternating-subarrays.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_alternating_subarrays(nums: Vec) -> i64 { + let mut result = 0; + let mut s = 1; + + for i in 1..nums.len() { + if nums[i] == nums[i - 1] { + s = 1; + } else { + s += 1; + } + result += s; + } + + result + } +} From fbd4ef428ae8a07be6fe6af9b5e4540b90bad36d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 6 Jul 2024 11:25:11 +0800 Subject: [PATCH 1479/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ad4e5957..ee3a3eac 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 784 | 347 | 409 | 28 | +| 785 | 347 | 410 | 28 | ### 题目 @@ -655,6 +655,7 @@ |3347 | 将元素分配到两个数组中 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-elements-into-two-arrays-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-elements-into-two-arrays-i/) | Easy | |3371 | 哈沙德数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/harshad-number.rs) | [leetcode](https://leetcode-cn.com/problems/harshad-number/) | Easy | |3373 | 质数的最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-prime-difference.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-prime-difference/) | Medium | +|3374 | 交替子数组计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-alternating-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-alternating-subarrays/) | Medium | |100160 | URL化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-url-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-url-lcci/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | From a46b30c951f701cf4718a6a21fafabb20fd16389 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 8 Jul 2024 20:50:37 +0800 Subject: [PATCH 1480/1556] src/bin/check-if-word-is-valid-after-substitutions.rs --- ...ck-if-word-is-valid-after-substitutions.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/bin/check-if-word-is-valid-after-substitutions.rs diff --git a/src/bin/check-if-word-is-valid-after-substitutions.rs b/src/bin/check-if-word-is-valid-after-substitutions.rs new file mode 100644 index 00000000..4a5fb392 --- /dev/null +++ b/src/bin/check-if-word-is-valid-after-substitutions.rs @@ -0,0 +1,29 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn is_valid(s: String) -> bool { + let mut stack = vec![]; + + for &i in s.as_bytes() { + match i { + b'a' | b'b' => stack.push(i), + b'c' => { + if stack.len() < 2 { + return false; + } + + if stack.pop().unwrap() != b'b' || stack.pop().unwrap() != b'a' { + return false; + } + } + _ => unreachable!(), + } + } + + stack.is_empty() + } +} From 7ac88aa547472fed4b6d7f3fc69c7108a5aaf0f7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 8 Jul 2024 20:50:37 +0800 Subject: [PATCH 1481/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ee3a3eac..e794abb3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 785 | 347 | 410 | 28 | +| 786 | 347 | 411 | 28 | ### 题目 @@ -362,6 +362,7 @@ |1035 | 二叉树的堂兄弟节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cousins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/cousins-in-binary-tree/) | Easy | |1036 | 腐烂的橘子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotting-oranges.rs) | [leetcode](https://leetcode-cn.com/problems/rotting-oranges/) | Medium | |1041 | 可以被一步捕获的棋子数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/available-captures-for-rook.rs) | [leetcode](https://leetcode-cn.com/problems/available-captures-for-rook/) | Easy | +|1045 | 检查替换后的词是否有效 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-word-is-valid-after-substitutions.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-word-is-valid-after-substitutions/) | Medium | |1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | |1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | From 30ea42d7ae009111b14d3d0dc0534b1926f6960f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 9 Jul 2024 20:16:13 +0800 Subject: [PATCH 1482/1556] src/bin/remove-trailing-zeros-from-a-string.rs --- .../remove-trailing-zeros-from-a-string.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/remove-trailing-zeros-from-a-string.rs diff --git a/src/bin/remove-trailing-zeros-from-a-string.rs b/src/bin/remove-trailing-zeros-from-a-string.rs new file mode 100644 index 00000000..9c9a0f2a --- /dev/null +++ b/src/bin/remove-trailing-zeros-from-a-string.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn remove_trailing_zeros(num: String) -> String { + let mut num = num; + loop { + match num.as_bytes().last() { + Some(b'0') => { + let _ = num.pop(); + } + _ => break, + } + } + + num + } +} From 90fe9842652565a3cb24b4aba056bcce5b549fba Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 9 Jul 2024 20:16:14 +0800 Subject: [PATCH 1483/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e794abb3..d7e49236 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 786 | 347 | 411 | 28 | +| 787 | 348 | 411 | 28 | ### 题目 @@ -611,6 +611,7 @@ |2802 | 求一个整数的惩罚数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-punishment-number-of-an-integer.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-punishment-number-of-an-integer/) | Medium | |2812 | 找出最大的可达成数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-maximum-achievable-number.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-maximum-achievable-number/) | Easy | |2816 | 字典序最小回文串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographically-smallest-palindrome.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographically-smallest-palindrome/) | Easy | +|2819 | 移除字符串中的尾随零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-trailing-zeros-from-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/remove-trailing-zeros-from-a-string/) | Easy | |2828 | 执行子串操作后的字典序最小字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographically-smallest-string-after-substring-operation.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographically-smallest-string-after-substring-operation/) | Medium | |2831 | 美丽下标对的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-beautiful-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-beautiful-pairs/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | From 48683183b2428d18dd3a20e62ad7ac5ff0cd58f2 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 10 Jul 2024 21:11:45 +0800 Subject: [PATCH 1484/1556] src/bin/master-mind-lcci.rs --- src/bin/master-mind-lcci.rs | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/bin/master-mind-lcci.rs diff --git a/src/bin/master-mind-lcci.rs b/src/bin/master-mind-lcci.rs new file mode 100644 index 00000000..edc56225 --- /dev/null +++ b/src/bin/master-mind-lcci.rs @@ -0,0 +1,58 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn master_mind(solution: String, guess: String) -> Vec { + let mut v = vec![0; 4]; + for &i in solution.as_bytes() { + match i { + b'R' => v[0] += 1, + b'Y' => v[1] += 1, + b'G' => v[2] += 1, + b'B' => v[3] += 1, + _ => {} + } + } + let mut right1 = 0; + let mut right2 = 0; + + for i in 0..4 { + if solution.as_bytes()[i] == guess.as_bytes()[i] { + right1 += 1; + } + + match guess.as_bytes()[i] { + b'R' => { + if v[0] > 0 { + v[0] -= 1; + right2 += 1; + } + } + b'Y' => { + if v[1] > 0 { + v[1] -= 1; + right2 += 1; + } + } + b'G' => { + if v[2] > 0 { + v[2] -= 1; + right2 += 1; + } + } + b'B' => { + if v[3] > 0 { + v[3] -= 1; + right2 += 1; + } + } + _ => {} + } + } + + vec![right1, right2 - right1] + } +} From 762994e45ae898f52c486f07b178312be45a5df7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 10 Jul 2024 21:11:46 +0800 Subject: [PATCH 1485/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d7e49236..0dc87501 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 787 | 348 | 411 | 28 | +| 788 | 349 | 411 | 28 | ### 题目 @@ -739,6 +739,7 @@ |100351 | 生存人数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/living-people-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/living-people-lcci/) | Medium | |100352 | 跳水板 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/diving-board-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/diving-board-lcci/) | Easy | |100353 | 平分正方形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/bisect-squares-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/bisect-squares-lcci/) | Medium | +|100355 | 珠玑妙算 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/master-mind-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/master-mind-lcci/) | Easy | |1000021 | 最小K个数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/smallest-k-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/smallest-k-lcci/) | Medium | |1000022 | 最长单词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-word-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/longest-word-lcci/) | Medium | |1000025 | 不用加号的加法 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/add-without-plus-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/add-without-plus-lcci/) | Easy | From 191b17f27436e31e9f904a710b8e51a56c9d79bd Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 11 Jul 2024 21:12:46 +0800 Subject: [PATCH 1486/1556] src/bin/maximum-of-absolute-value-expression.rs --- .../maximum-of-absolute-value-expression.rs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/bin/maximum-of-absolute-value-expression.rs diff --git a/src/bin/maximum-of-absolute-value-expression.rs b/src/bin/maximum-of-absolute-value-expression.rs new file mode 100644 index 00000000..e27e8be7 --- /dev/null +++ b/src/bin/maximum-of-absolute-value-expression.rs @@ -0,0 +1,39 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 将绝对值去掉 + /// |arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j| + // + // = (arr1[i] + arr2[i] + i) - (arr1[j] + arr2[j] + j) + // = (arr1[i] + arr2[i] - i) - (arr1[j] + arr2[j] - j) + // = (arr1[i] - arr2[i] + i) - (arr1[j] - arr2[j] + j) + // = (arr1[i] - arr2[i] - i) - (arr1[j] - arr2[j] - j) + pub fn max_abs_val_expr(arr1: Vec, arr2: Vec) -> i32 { + let (mut a_max, mut b_max, mut c_max, mut d_max) = (i32::MIN, i32::MIN, i32::MIN, i32::MIN); + let (mut a_min, mut b_min, mut c_min, mut d_min) = (i32::MAX, i32::MAX, i32::MAX, i32::MAX); + + for i in 0..arr1.len() { + let (x, y) = (arr1[i], arr2[i]); + a_max = a_max.max(x + y + i as i32); + a_min = a_min.min(x + y + i as i32); + + b_max = b_max.max(x + y - i as i32); + b_min = b_min.min(x + y - i as i32); + + c_max = c_max.max(x - y + i as i32); + c_min = c_min.min(x - y + i as i32); + + d_max = d_max.max(x - y - i as i32); + d_min = d_min.min(x - y - i as i32); + } + + (a_max - a_min) + .max(b_max - b_min) + .max(c_max - c_min) + .max(d_max - d_min) + } +} From aa7f5f906e82936dd636fc3ade7ec782958d66de Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 11 Jul 2024 21:12:47 +0800 Subject: [PATCH 1487/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0dc87501..2b0a1a28 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 788 | 349 | 411 | 28 | +| 789 | 349 | 412 | 28 | ### 题目 @@ -381,6 +381,7 @@ |1184 | 拼车 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/car-pooling.rs) | [leetcode](https://leetcode-cn.com/problems/car-pooling/) | Medium | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | |1218 | 最深叶节点的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-deepest-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves/) | Medium | +|1230 | 绝对值表达式的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-of-absolute-value-expression.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-of-absolute-value-expression/) | Medium | |1236 | 第 N 个泰波那契数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/n-th-tribonacci-number.rs) | [leetcode](https://leetcode-cn.com/problems/n-th-tribonacci-number/) | Easy | |1238 | 字母板上的路径 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alphabet-board-path.rs) | [leetcode](https://leetcode-cn.com/problems/alphabet-board-path/) | Medium | |1249 | 快照数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/snapshot-array.rs) | [leetcode](https://leetcode-cn.com/problems/snapshot-array/) | Medium | From 2ae99043337b4b3cc49d1d05b21ce5386588cb8e Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 12 Jul 2024 07:59:15 +0800 Subject: [PATCH 1488/1556] src/bin/minimum-number-game.rs --- src/bin/minimum-number-game.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/bin/minimum-number-game.rs diff --git a/src/bin/minimum-number-game.rs b/src/bin/minimum-number-game.rs new file mode 100644 index 00000000..50b33e16 --- /dev/null +++ b/src/bin/minimum-number-game.rs @@ -0,0 +1,18 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn number_game(nums: Vec) -> Vec { + let mut nums = nums; + nums.sort_unstable(); + + for i in (1..nums.len()).step_by(2) { + nums.swap(i, i - 1); + } + + nums + } +} From 320522a76255d9ac2e53b933327d1b0f033e1c29 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 12 Jul 2024 07:59:15 +0800 Subject: [PATCH 1489/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2b0a1a28..9eabde76 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 789 | 349 | 412 | 28 | +| 790 | 350 | 412 | 28 | ### 题目 @@ -647,6 +647,7 @@ |3207 | 使三个字符串相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-three-strings-equal.rs) | [leetcode](https://leetcode-cn.com/problems/make-three-strings-equal/) | Easy | |3220 | 统计已测试设备 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-tested-devices-after-test-operations.rs) | [leetcode](https://leetcode-cn.com/problems/count-tested-devices-after-test-operations/) | Easy | |3221 | 找出峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-peaks.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-peaks/) | Easy | +|3226 | 最小数字游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-game.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-game/) | Easy | |3227 | 找出缺失和重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-missing-and-repeated-values.rs) | [leetcode](https://leetcode-cn.com/problems/find-missing-and-repeated-values/) | Easy | |3231 | 需要添加的硬币的最小数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-coins-to-be-added.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-coins-to-be-added/) | Medium | |3241 | 划分数组并满足最大差限制 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/divide-array-into-arrays-with-max-difference.rs) | [leetcode](https://leetcode-cn.com/problems/divide-array-into-arrays-with-max-difference/) | Medium | From 930aa56818c7d2c2184945aa6596576940be4266 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 15 Jul 2024 21:00:27 +0800 Subject: [PATCH 1490/1556] src/bin/count-odd-numbers-in-an-interval-range.rs --- .../count-odd-numbers-in-an-interval-range.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/bin/count-odd-numbers-in-an-interval-range.rs diff --git a/src/bin/count-odd-numbers-in-an-interval-range.rs b/src/bin/count-odd-numbers-in-an-interval-range.rs new file mode 100644 index 00000000..31e40c5c --- /dev/null +++ b/src/bin/count-odd-numbers-in-an-interval-range.rs @@ -0,0 +1,21 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn count_odds(low: i32, high: i32) -> i32 { + let mut low = low; + let mut high = high; + if low % 2 == 0 { + low += 1; + } + + if high % 2 == 0 { + high -= 1; + } + + (high - low) / 2 + 1 + } +} From f6a6c00ac18dfb1acb74d1ee7e8ef9c6e1c019cf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 15 Jul 2024 21:00:28 +0800 Subject: [PATCH 1491/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9eabde76..fda3b349 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 790 | 350 | 412 | 28 | +| 791 | 351 | 412 | 28 | ### 题目 @@ -455,6 +455,7 @@ |1603 | 一维数组的动态和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/running-sum-of-1d-array.rs) | [leetcode](https://leetcode-cn.com/problems/running-sum-of-1d-array/) | Easy | |1604 | 不同整数的最少数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/least-number-of-unique-integers-after-k-removals.rs) | [leetcode](https://leetcode-cn.com/problems/least-number-of-unique-integers-after-k-removals/) | Medium | |1620 | 检查数组对是否可以被 k 整除 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-array-pairs-are-divisible-by-k.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-array-pairs-are-divisible-by-k/) | Medium | +|1630 | 在区间范围内统计奇数数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-odd-numbers-in-an-interval-range.rs) | [leetcode](https://leetcode-cn.com/problems/count-odd-numbers-in-an-interval-range/) | Easy | |1635 | 好数对的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-good-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-good-pairs/) | Easy | |1636 | 仅含 1 的子串数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-substrings-with-only-1s.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-substrings-with-only-1s/) | Medium | |1642 | 换酒问题 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/water-bottles.rs) | [leetcode](https://leetcode-cn.com/problems/water-bottles/) | Easy | From d27aa5bd4ea9eccd9f7f5fd67fd8fb2ee7746010 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 16 Jul 2024 07:55:18 +0800 Subject: [PATCH 1492/1556] src/bin/find-common-elements-between-two-arrays.rs --- ...find-common-elements-between-two-arrays.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/find-common-elements-between-two-arrays.rs diff --git a/src/bin/find-common-elements-between-two-arrays.rs b/src/bin/find-common-elements-between-two-arrays.rs new file mode 100644 index 00000000..92de3a0b --- /dev/null +++ b/src/bin/find-common-elements-between-two-arrays.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_intersection_values(nums1: Vec, nums2: Vec) -> Vec { + let (mut s, mut m) = ( + nums1 + .iter() + .map(|x| *x) + .collect::>(), + nums2 + .iter() + .map(|x| *x) + .collect::>(), + ); + let mut r1 = 0; + let mut r2 = 0; + + for i in nums1 { + if m.contains(&i) { + r1 += 1; + } + } + + for i in nums2 { + if s.contains(&i) { + r2 += 1; + } + } + + vec![r1, r2] + } +} From 5eb9c890850efcfa25787f5848a632c59637cc3a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 16 Jul 2024 07:55:19 +0800 Subject: [PATCH 1493/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fda3b349..211dfcff 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 791 | 351 | 412 | 28 | +| 792 | 352 | 412 | 28 | ### 题目 @@ -645,6 +645,7 @@ |3189 | 找到冠军 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-champion-ii.rs) | [leetcode](https://leetcode-cn.com/problems/find-champion-ii/) | Medium | |3195 | 区分黑球与白球 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/separate-black-and-white-balls.rs) | [leetcode](https://leetcode-cn.com/problems/separate-black-and-white-balls/) | Medium | |3199 | 给小朋友们分糖果 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-candies-among-children-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-candies-among-children-i/) | Easy | +|3206 | 找到两个数组中的公共元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-common-elements-between-two-arrays.rs) | [leetcode](https://leetcode-cn.com/problems/find-common-elements-between-two-arrays/) | Easy | |3207 | 使三个字符串相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/make-three-strings-equal.rs) | [leetcode](https://leetcode-cn.com/problems/make-three-strings-equal/) | Easy | |3220 | 统计已测试设备 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-tested-devices-after-test-operations.rs) | [leetcode](https://leetcode-cn.com/problems/count-tested-devices-after-test-operations/) | Easy | |3221 | 找出峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-peaks.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-peaks/) | Easy | From 2f2bbdcb79a3a8e57c3382e5d264ca6ddea02c13 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 22 Jul 2024 21:15:19 +0800 Subject: [PATCH 1494/1556] src/bin/cells-with-odd-values-in-a-matrix.rs --- src/bin/cells-with-odd-values-in-a-matrix.rs | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/cells-with-odd-values-in-a-matrix.rs diff --git a/src/bin/cells-with-odd-values-in-a-matrix.rs b/src/bin/cells-with-odd-values-in-a-matrix.rs new file mode 100644 index 00000000..bddc2d4a --- /dev/null +++ b/src/bin/cells-with-odd-values-in-a-matrix.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn odd_cells(m: i32, n: i32, indices: Vec>) -> i32 { + let mut row = 0u64; + let mut col = 0u64; + + for e in &indices { + let ri = e[0] as u64; + let ci = e[1] as u64; + row ^= 1u64 << ri; + col ^= 1u64 << ci; + } + + let cx = row.count_ones() as i32; + let cy = col.count_ones() as i32; + cx * (n - cy) + cy * (m - cx) + } +} From e439c007167c05f4da53e57b1b5f51f0d410ab89 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 22 Jul 2024 21:15:20 +0800 Subject: [PATCH 1495/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 211dfcff..5e85f5b6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 792 | 352 | 412 | 28 | +| 793 | 353 | 412 | 28 | ### 题目 @@ -411,6 +411,7 @@ |1369 | 交换字符使得字符串相同 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-swaps-to-make-strings-equal.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-swaps-to-make-strings-equal/) | Medium | |1370 | 统计「优美子数组」 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-number-of-nice-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-number-of-nice-subarrays/) | Medium | |1371 | 移除无效的括号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-remove-to-make-valid-parentheses.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-remove-to-make-valid-parentheses/) | Medium | +|1378 | 奇数值单元格的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cells-with-odd-values-in-a-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/cells-with-odd-values-in-a-matrix/) | Easy | |1379 | 重构 2 行二进制矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/reconstruct-a-2-row-binary-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/reconstruct-a-2-row-binary-matrix/) | Medium | |1380 | 统计封闭岛屿的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-closed-islands.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-closed-islands/) | Medium | |1387 | 在受污染的二叉树中查找元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-elements-in-a-contaminated-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/find-elements-in-a-contaminated-binary-tree/) | Medium | From 50e70d22dd386855522fd2cc7798ee1c94ff16a1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 25 Jul 2024 21:34:57 +0800 Subject: [PATCH 1496/1556] src/bin/minimum-operations-to-make-a-special-number.rs --- ...mum-operations-to-make-a-special-number.rs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/bin/minimum-operations-to-make-a-special-number.rs diff --git a/src/bin/minimum-operations-to-make-a-special-number.rs b/src/bin/minimum-operations-to-make-a-special-number.rs new file mode 100644 index 00000000..d82cd5d2 --- /dev/null +++ b/src/bin/minimum-operations-to-make-a-special-number.rs @@ -0,0 +1,45 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_operations(num: String) -> i32 { + let mut result = num.len() as i32; + let mut s = vec![false, false]; + let len = num.len() as i32 - 1; + + for (i, u) in num.bytes().enumerate().rev() { + match u { + b'0' => { + // 00结尾 + if s[0] { + result = result.min(len - i as i32 + 1); + } + s[0] = true; + } + b'2' | b'7' => { + // 2, 5 + // 7, 5 + if s[1] { + result = result.min(len - i as i32 + 1); + } + } + b'5' => { + // 5,0 + if s[0] { + result = result.min(len - i as i32 + 1); + } + s[1] = true; + } + _ => {} + } + } + + if s[0] { + result = result.min(len); + } + result + } +} From c61b41f7716045daf1d0524329262ec1c1d8edd1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 25 Jul 2024 21:34:58 +0800 Subject: [PATCH 1497/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e85f5b6..f815f44c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 793 | 353 | 412 | 28 | +| 794 | 353 | 413 | 28 | ### 题目 @@ -634,6 +634,7 @@ |2977 | 判别首字母缩略词 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-a-string-is-an-acronym-of-words.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-a-string-is-an-acronym-of-words/) | Easy | |3026 | 找出美丽数组的最小和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-minimum-possible-sum-of-a-beautiful-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-minimum-possible-sum-of-a-beautiful-array/) | Medium | |3045 | 使数组成为递增数组的最少右移次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-right-shifts-to-sort-the-array.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-right-shifts-to-sort-the-array/) | Easy | +|3046 | 生成特殊数字的最少操作 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-make-a-special-number.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-make-a-special-number/) | Medium | |3055 | 最大二进制奇数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-odd-binary-number.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-odd-binary-number/) | Easy | |3093 | 计算 K 置位下标对应元素的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-values-at-indices-with-k-set-bits.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-values-at-indices-with-k-set-bits/) | Easy | |3094 | 使数组为空的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-operations-to-make-array-empty.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-operations-to-make-array-empty/) | Medium | From 89ea814176383499c6337d30d74a397963d4cf4a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 27 Jul 2024 15:04:28 +0800 Subject: [PATCH 1498/1556] src/bin/lexicographically-smallest-string-after-operations-with-constraint.rs --- ...string-after-operations-with-constraint.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/lexicographically-smallest-string-after-operations-with-constraint.rs diff --git a/src/bin/lexicographically-smallest-string-after-operations-with-constraint.rs b/src/bin/lexicographically-smallest-string-after-operations-with-constraint.rs new file mode 100644 index 00000000..41e0e5c9 --- /dev/null +++ b/src/bin/lexicographically-smallest-string-after-operations-with-constraint.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn get_smallest_string(s: String, k: i32) -> String { + let mut r = 0; + let mut k = k; + let mut result = Vec::with_capacity(s.len()); + + for i in s.bytes() { + if k >= (i - b'a').min(b'z' + 1 - i) as i32 { + result.push(b'a'); + k -= (i - b'a').min(b'z' + 1 - i) as i32; + } else if k > 0 { + result.push(i - k as u8); + k = 0; + } else { + result.push(i); + } + } + + String::from_utf8(result).unwrap() + } +} From 7ca2af3dd4246b3d9136cf83c27fe25b704a0b27 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 27 Jul 2024 15:04:28 +0800 Subject: [PATCH 1499/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f815f44c..c8c80fb8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 794 | 353 | 413 | 28 | +| 795 | 353 | 414 | 28 | ### 题目 @@ -660,6 +660,7 @@ |3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | |3330 | 修改矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/modify-the-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/modify-the-matrix/) | Easy | |3334 | 重新分装苹果 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apple-redistribution-into-boxes.rs) | [leetcode](https://leetcode-cn.com/problems/apple-redistribution-into-boxes/) | Easy | +|3346 | 满足距离约束且字典序最小的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographically-smallest-string-after-operations-with-constraint.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographically-smallest-string-after-operations-with-constraint/) | Medium | |3347 | 将元素分配到两个数组中 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-elements-into-two-arrays-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-elements-into-two-arrays-i/) | Easy | |3371 | 哈沙德数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/harshad-number.rs) | [leetcode](https://leetcode-cn.com/problems/harshad-number/) | Easy | |3373 | 质数的最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-prime-difference.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-prime-difference/) | Medium | From 79f063fb53c699110b84d96094a28350dee112de Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 29 Jul 2024 21:19:33 +0800 Subject: [PATCH 1500/1556] src/bin/distribute-candies-to-people.rs --- src/bin/distribute-candies-to-people.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/bin/distribute-candies-to-people.rs diff --git a/src/bin/distribute-candies-to-people.rs b/src/bin/distribute-candies-to-people.rs new file mode 100644 index 00000000..e7e020b2 --- /dev/null +++ b/src/bin/distribute-candies-to-people.rs @@ -0,0 +1,25 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn distribute_candies(candies: i32, num_people: i32) -> Vec { + impl Solution { + pub fn distribute_candies(candies: i32, n: i32) -> Vec { + let m = (((8.0 * candies as f64 + 1.0).sqrt() - 1.0) / 2.0) as i32; + let k = m / n; + let extra = m % n; + let mut ans = (0..n) + .map(|i| { + let k = if i < extra { k + 1 } else { k }; + k * (k - 1) / 2 * n + k * (i + 1) + }) + .collect::>(); + ans[extra as usize] += candies - m * (m + 1) / 2; + ans + } + } + } +} From 7b9a9a45c533b849c3500b4a8114a47c61dfcc0d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 29 Jul 2024 21:19:34 +0800 Subject: [PATCH 1501/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f815f44c..0c7ed513 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 794 | 353 | 413 | 28 | +| 795 | 354 | 413 | 28 | ### 题目 @@ -379,6 +379,7 @@ |1157 | 根到叶路径上的不足节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/insufficient-nodes-in-root-to-leaf-paths.rs) | [leetcode](https://leetcode-cn.com/problems/insufficient-nodes-in-root-to-leaf-paths/) | Medium | |1168 | 复写零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/duplicate-zeros.rs) | [leetcode](https://leetcode-cn.com/problems/duplicate-zeros/) | Easy | |1184 | 拼车 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/car-pooling.rs) | [leetcode](https://leetcode-cn.com/problems/car-pooling/) | Medium | +|1195 | 分糖果 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-candies-to-people.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-candies-to-people/) | Easy | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | |1218 | 最深叶节点的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-deepest-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves/) | Medium | |1230 | 绝对值表达式的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-of-absolute-value-expression.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-of-absolute-value-expression/) | Medium | From 541b3d6c61d733a4eca46e5275af22977d224f82 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 29 Jul 2024 21:20:51 +0800 Subject: [PATCH 1502/1556] src/bin/distribute-candies-to-people.rs --- src/bin/distribute-candies-to-people.rs | 26 +++++++++++-------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/bin/distribute-candies-to-people.rs b/src/bin/distribute-candies-to-people.rs index e7e020b2..7d4db85d 100644 --- a/src/bin/distribute-candies-to-people.rs +++ b/src/bin/distribute-candies-to-people.rs @@ -6,20 +6,16 @@ struct Solution; impl Solution { pub fn distribute_candies(candies: i32, num_people: i32) -> Vec { - impl Solution { - pub fn distribute_candies(candies: i32, n: i32) -> Vec { - let m = (((8.0 * candies as f64 + 1.0).sqrt() - 1.0) / 2.0) as i32; - let k = m / n; - let extra = m % n; - let mut ans = (0..n) - .map(|i| { - let k = if i < extra { k + 1 } else { k }; - k * (k - 1) / 2 * n + k * (i + 1) - }) - .collect::>(); - ans[extra as usize] += candies - m * (m + 1) / 2; - ans - } - } + let m = (((8.0 * candies as f64 + 1.0).sqrt() - 1.0) / 2.0) as i32; + let k = m / num_people; + let extra = m % num_people; + let mut ans = (0..num_people) + .map(|i| { + let k = if i < extra { k + 1 } else { k }; + k * (k - 1) / 2 * num_people + k * (i + 1) + }) + .collect::>(); + ans[extra as usize] += candies - m * (m + 1) / 2; + ans } } From e9a48076c3995084d752570124ef73e0c0a9fc71 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 29 Jul 2024 21:20:51 +0800 Subject: [PATCH 1503/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c7ed513..e3835243 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 795 | 354 | 413 | 28 | +| 796 | 355 | 413 | 28 | ### 题目 @@ -380,6 +380,7 @@ |1168 | 复写零 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/duplicate-zeros.rs) | [leetcode](https://leetcode-cn.com/problems/duplicate-zeros/) | Easy | |1184 | 拼车 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/car-pooling.rs) | [leetcode](https://leetcode-cn.com/problems/car-pooling/) | Medium | |1195 | 分糖果 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-candies-to-people.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-candies-to-people/) | Easy | +|1195 | 分糖果 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-candies-to-people.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-candies-to-people/) | Easy | |1210 | 删除某些元素后的数组均值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/mean-of-array-after-removing-some-elements.rs) | [leetcode](https://leetcode-cn.com/problems/mean-of-array-after-removing-some-elements/) | Easy | |1218 | 最深叶节点的最近公共祖先 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lowest-common-ancestor-of-deepest-leaves.rs) | [leetcode](https://leetcode-cn.com/problems/lowest-common-ancestor-of-deepest-leaves/) | Medium | |1230 | 绝对值表达式的最大值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-of-absolute-value-expression.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-of-absolute-value-expression/) | Medium | From 8c5538743e5d8ce1b084aa8dcb433a46d69ecde1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 30 Jul 2024 21:54:50 +0800 Subject: [PATCH 1504/1556] src/bin/double-modular-exponentiation.rs --- src/bin/double-modular-exponentiation.rs | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/bin/double-modular-exponentiation.rs diff --git a/src/bin/double-modular-exponentiation.rs b/src/bin/double-modular-exponentiation.rs new file mode 100644 index 00000000..10b623db --- /dev/null +++ b/src/bin/double-modular-exponentiation.rs @@ -0,0 +1,35 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn get_good_indices(variables: Vec>, target: i32) -> Vec { + variables + .into_iter() + .enumerate() + .filter_map(|(x, y)| { + if (Self::pow(Self::pow(y[0], y[1], 10), y[2], y[3])) == target { + Some(x as i32) + } else { + None + } + }) + .collect() + } + + fn pow(mut x: i32, mut y: i32, z: i32) -> i32 { + let mut result = 1; + while y > 0 { + if y % 2 > 0 { + result = result * x % z; + } + + x = x * x % z; + y /= 2; + } + + result + } +} From 342736fda4189fd9dc22059c6d1de68284853923 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 30 Jul 2024 21:54:51 +0800 Subject: [PATCH 1505/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e3835243..f49b2d2a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 796 | 355 | 413 | 28 | +| 797 | 355 | 414 | 28 | ### 题目 @@ -656,6 +656,7 @@ |3226 | 最小数字游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-game.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-game/) | Easy | |3227 | 找出缺失和重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-missing-and-repeated-values.rs) | [leetcode](https://leetcode-cn.com/problems/find-missing-and-repeated-values/) | Easy | |3231 | 需要添加的硬币的最小数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-coins-to-be-added.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-coins-to-be-added/) | Medium | +|3234 | 双模幂运算 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/double-modular-exponentiation.rs) | [leetcode](https://leetcode-cn.com/problems/double-modular-exponentiation/) | Medium | |3241 | 划分数组并满足最大差限制 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/divide-array-into-arrays-with-max-difference.rs) | [leetcode](https://leetcode-cn.com/problems/divide-array-into-arrays-with-max-difference/) | Medium | |3265 | 最大好子数组和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-good-subarray-sum.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-good-subarray-sum/) | Medium | |3275 | 输入单词需要的最少按键次数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-pushes-to-type-word-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-pushes-to-type-word-i/) | Easy | From 7734f4d99b33ee903388ae33ea78245ad9300764 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 1 Aug 2024 21:03:49 +0800 Subject: [PATCH 1506/1556] src/bin/uOAnQW.rs --- src/bin/uOAnQW.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/bin/uOAnQW.rs diff --git a/src/bin/uOAnQW.rs b/src/bin/uOAnQW.rs new file mode 100644 index 00000000..8ae60618 --- /dev/null +++ b/src/bin/uOAnQW.rs @@ -0,0 +1,44 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maxmium_score(cards: Vec, cnt: i32) -> i32 { + let mut cards = cards; + cards.sort_unstable_by(|x, y| x.cmp(y).reverse()); + + let (mut min_even, mut min_odd) = (None::, None::); + let (mut max_even, mut max_odd) = (None::, None::); + let mut sum = 0; + + for &i in cards[0..cnt as usize].iter() { + sum += i; + if i % 2 == 0 { + min_even = min_even.map_or(Some(i), |x| Some(x.min(i))); + } else { + min_odd = min_odd.map_or(Some(i), |x| Some(x.min(i))); + } + } + + if sum % 2 == 0 { + return sum; + } + + for &i in cards[cnt as usize..].iter() { + if i % 2 == 0 { + max_even = max_even.map_or(Some(i), |x| Some(x.max(i))); + } else { + max_odd = max_odd.map_or(Some(i), |x| Some(x.max(i))); + } + } + + match (min_even, max_odd, min_odd, max_even) { + (Some(x1), Some(y1), Some(x2), Some(y2)) => (sum - x1 + y1).max(sum - x2 + y2), + (Some(x1), Some(y1), _, _) => sum - x1 + y1, + (_, _, Some(x2), Some(y2)) => sum - x2 + y2, + _ => 0, + } + } +} From b8a309b3a5ba38722114a7cf2601a2a415504215 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 1 Aug 2024 21:03:49 +0800 Subject: [PATCH 1507/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f49b2d2a..6fd55d97 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 797 | 355 | 414 | 28 | +| 798 | 356 | 414 | 28 | ### 题目 @@ -803,5 +803,6 @@ |1000324 | 前 K 个高频元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/g5c51o.rs) | [leetcode](https://leetcode-cn.com/problems/g5c51o/) | Medium | |1000333 | 山峰数组的顶部 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/B1IidL.rs) | [leetcode](https://leetcode-cn.com/problems/B1IidL/) | Easy | |1000341 | 链表排序 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/7WHec2.rs) | [leetcode](https://leetcode-cn.com/problems/7WHec2/) | Medium | +|1000368 | 心算挑战 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/uOAnQW.rs) | [leetcode](https://leetcode-cn.com/problems/uOAnQW/) | Easy | |1000433 | 宝石补给 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/WHnhjV.rs) | [leetcode](https://leetcode-cn.com/problems/WHnhjV/) | Easy | |1000476 | 气温变化趋势 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/6CE719.rs) | [leetcode](https://leetcode-cn.com/problems/6CE719/) | Easy | From ccc49695648aeb7f91800028615d08be92547a90 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 2 Aug 2024 13:59:30 +0800 Subject: [PATCH 1508/1556] src/bin/right-triangles.rs --- src/bin/right-triangles.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/bin/right-triangles.rs diff --git a/src/bin/right-triangles.rs b/src/bin/right-triangles.rs new file mode 100644 index 00000000..56e57ade --- /dev/null +++ b/src/bin/right-triangles.rs @@ -0,0 +1,32 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn number_of_right_triangles(grid: Vec>) -> i64 { + let (mut row, mut col) = (vec![0; grid.len()], vec![0; grid[0].len()]); + + for i in 0..grid.len() { + for j in 0..grid[0].len() { + if grid[i][j] == 1 { + row[i] += 1; + col[j] += 1; + } + } + } + + let mut result = 0; + + for i in 0..grid.len() { + for j in 0..grid[0].len() { + if grid[i][j] == 1 { + result += (row[i] - 1) * (col[j] - 1); + } + } + } + + result + } +} From e76c0e2ade2d4ab1e0b104bfc055bf31ec0dd10a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 2 Aug 2024 13:59:30 +0800 Subject: [PATCH 1509/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c8c80fb8..38f57b3e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 795 | 353 | 414 | 28 | +| 796 | 353 | 415 | 28 | ### 题目 @@ -665,6 +665,7 @@ |3371 | 哈沙德数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/harshad-number.rs) | [leetcode](https://leetcode-cn.com/problems/harshad-number/) | Easy | |3373 | 质数的最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-prime-difference.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-prime-difference/) | Medium | |3374 | 交替子数组计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-alternating-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-alternating-subarrays/) | Medium | +|3388 | 直角三角形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/right-triangles.rs) | [leetcode](https://leetcode-cn.com/problems/right-triangles/) | Medium | |100160 | URL化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-url-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-url-lcci/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | From d024b0b0bc4c5b840bd7127d21a0f342a62050cf Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 5 Aug 2024 21:52:48 +0800 Subject: [PATCH 1510/1556] src/bin/subtree-of-another-tree.rs --- src/bin/subtree-of-another-tree.rs | 75 ++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/bin/subtree-of-another-tree.rs diff --git a/src/bin/subtree-of-another-tree.rs b/src/bin/subtree-of-another-tree.rs new file mode 100644 index 00000000..2969cd2c --- /dev/null +++ b/src/bin/subtree-of-another-tree.rs @@ -0,0 +1,75 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for a binary tree node. +#[derive(Debug, PartialEq, Eq)] +pub struct TreeNode { + pub val: i32, + pub left: Option>>, + pub right: Option>>, +} + +impl TreeNode { + #[inline] + pub fn new(val: i32) -> Self { + TreeNode { + val, + left: None, + right: None, + } + } +} + +use std::cell::RefCell; +use std::rc::Rc; +impl Solution { + pub fn is_subtree( + root: Option>>, + sub_root: Option>>, + ) -> bool { + if root.is_none() || sub_root.is_none() { + return root == sub_root; + } + + Self::check(root.clone(), sub_root.clone()) + || Self::is_subtree( + root.clone().and_then(|x| x.borrow().left.clone()), + sub_root.clone(), + ) + || Self::is_subtree( + root.clone().and_then(|x| x.borrow().right.clone()), + sub_root.clone(), + ) + } + + pub fn check( + root: Option>>, + sub_root: Option>>, + ) -> bool { + if root.is_none() && sub_root.is_none() { + return true; + } else if root.is_none() && sub_root.is_some() { + return false; + } else if root.is_some() && sub_root.is_none() { + return false; + } + + let v1 = root.clone().unwrap().borrow().val; + let v2 = sub_root.clone().unwrap().borrow().val; + + if v1 != v2 { + return false; + } + + Self::check( + root.clone().and_then(|x| x.borrow().left.clone()), + sub_root.clone().and_then(|x| x.borrow().left.clone()), + ) && Self::check( + root.clone().and_then(|x| x.borrow().right.clone()), + sub_root.clone().and_then(|x| x.borrow().right.clone()), + ) + } +} From ab14a50432ab6710eb4c1e4ad142a5b97df49be4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 5 Aug 2024 21:52:48 +0800 Subject: [PATCH 1511/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6fd55d97..e239b5ee 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 798 | 356 | 414 | 28 | +| 799 | 357 | 414 | 28 | ### 题目 @@ -278,6 +278,7 @@ |551 | 学生出勤记录 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/student-attendance-record-i.rs) | [leetcode](https://leetcode-cn.com/problems/student-attendance-record-i/) | Easy | |560 | 和为 K 的子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subarray-sum-equals-k.rs) | [leetcode](https://leetcode-cn.com/problems/subarray-sum-equals-k/) | Medium | |565 | 数组嵌套 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/array-nesting.rs) | [leetcode](https://leetcode-cn.com/problems/array-nesting/) | Medium | +|572 | 另一棵树的子树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/subtree-of-another-tree.rs) | [leetcode](https://leetcode-cn.com/problems/subtree-of-another-tree/) | Easy | |575 | 分糖果 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-candies.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-candies/) | Easy | |581 | 最短无序连续子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/shortest-unsorted-continuous-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/shortest-unsorted-continuous-subarray/) | Medium | |594 | 最长和谐子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-harmonious-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-harmonious-subsequence/) | Easy | From 8c00b50b3d65f8e09c7cd35523bdd19427cde60c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 6 Aug 2024 21:12:07 +0800 Subject: [PATCH 1512/1556] src/bin/minimum-rectangles-to-cover-points.rs --- src/bin/minimum-rectangles-to-cover-points.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/bin/minimum-rectangles-to-cover-points.rs diff --git a/src/bin/minimum-rectangles-to-cover-points.rs b/src/bin/minimum-rectangles-to-cover-points.rs new file mode 100644 index 00000000..1f26c901 --- /dev/null +++ b/src/bin/minimum-rectangles-to-cover-points.rs @@ -0,0 +1,22 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_rectangles_to_cover_points(points: Vec>, w: i32) -> i32 { + let mut points = points; + points.sort_by(|x, y| x[0].cmp(&y[0])); + let mut result = 0; + let mut index = 0; + for i in 0..points.len() { + if points[i][0] - points[index][0] > w { + result += 1; + index = i; + } + } + + result + 1 + } +} From f3fccc1e3efe0f32f1b5573c381cfd6615e08aec Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 6 Aug 2024 21:12:09 +0800 Subject: [PATCH 1513/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e239b5ee..2d44af5b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 799 | 357 | 414 | 28 | +| 800 | 357 | 415 | 28 | ### 题目 @@ -668,6 +668,7 @@ |3371 | 哈沙德数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/harshad-number.rs) | [leetcode](https://leetcode-cn.com/problems/harshad-number/) | Easy | |3373 | 质数的最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-prime-difference.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-prime-difference/) | Medium | |3374 | 交替子数组计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-alternating-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-alternating-subarrays/) | Medium | +|3390 | 覆盖所有点的最少矩形数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-rectangles-to-cover-points.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-rectangles-to-cover-points/) | Medium | |100160 | URL化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-url-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-url-lcci/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | From e2c06b162709a4b0b89b7277de14816fdd0cb1de Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 7 Aug 2024 20:58:16 +0800 Subject: [PATCH 1514/1556] src/bin/find-positive-integer-solution-for-a-given-equation.rs --- ...e-integer-solution-for-a-given-equation.rs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/bin/find-positive-integer-solution-for-a-given-equation.rs diff --git a/src/bin/find-positive-integer-solution-for-a-given-equation.rs b/src/bin/find-positive-integer-solution-for-a-given-equation.rs new file mode 100644 index 00000000..7ae44a82 --- /dev/null +++ b/src/bin/find-positive-integer-solution-for-a-given-equation.rs @@ -0,0 +1,37 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +/* + * // This is the custom function interface. + * // You should not implement it, or speculate about its implementation + */ +struct CustomFunction; +impl CustomFunction { + pub fn f(x: i32, y: i32) -> i32 { + unimplemented!() + } +} +impl Solution { + pub fn find_solution(customfunction: &CustomFunction, z: i32) -> Vec> { + let mut result = vec![]; + let (mut x, mut y) = (1, 1000); + + while x < 1000 && y > 0 { + let r = CustomFunction::f(x, y); + if r > z { + y -= 1; + } else if r < z { + x += 1; + } else { + result.push(vec![x, y]); + x += 1; + y -= 1; + } + } + + result + } +} From 2aae3d6f0a72942a7324e2be59ff1b07090e464d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 7 Aug 2024 20:58:18 +0800 Subject: [PATCH 1515/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d44af5b..b8afe736 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 800 | 357 | 415 | 28 | +| 801 | 357 | 416 | 28 | ### 题目 @@ -408,6 +408,7 @@ |1342 | 可以攻击国王的皇后 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/queens-that-can-attack-the-king.rs) | [leetcode](https://leetcode-cn.com/problems/queens-that-can-attack-the-king/) | Medium | |1353 | 移除字母异位词后的结果数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-resultant-array-after-removing-anagrams.rs) | [leetcode](https://leetcode-cn.com/problems/find-resultant-array-after-removing-anagrams/) | Easy | |1354 | 找出输掉零场或一场比赛的玩家 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-players-with-zero-or-one-losses.rs) | [leetcode](https://leetcode-cn.com/problems/find-players-with-zero-or-one-losses/) | Medium | +|1358 | 找出给定方程的正整数解 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-positive-integer-solution-for-a-given-equation.rs) | [leetcode](https://leetcode-cn.com/problems/find-positive-integer-solution-for-a-given-equation/) | Medium | |1362 | 飞机座位分配概率 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/airplane-seat-assignment-probability.rs) | [leetcode](https://leetcode-cn.com/problems/airplane-seat-assignment-probability/) | Medium | |1363 | 兼具大小写的最好英文字母 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/greatest-english-letter-in-upper-and-lower-case.rs) | [leetcode](https://leetcode-cn.com/problems/greatest-english-letter-in-upper-and-lower-case/) | Easy | |1364 | 同积元组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/tuple-with-same-product.rs) | [leetcode](https://leetcode-cn.com/problems/tuple-with-same-product/) | Medium | From c3efab72493a95718342c24bb023e3f775c6a9c1 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 7 Aug 2024 21:47:32 +0800 Subject: [PATCH 1516/1556] README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e34cc21..22e9e8ae 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 801 | 357 | 416 | 28 | +| 803 | 357 | 418 | 28 | ### 题目 From a2dd96620e37f44fd592733fb1bb1d0bd20bfb49 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 8 Aug 2024 20:24:25 +0800 Subject: [PATCH 1517/1556] src/bin/find-the-integer-added-to-array-i.rs --- src/bin/find-the-integer-added-to-array-i.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/bin/find-the-integer-added-to-array-i.rs diff --git a/src/bin/find-the-integer-added-to-array-i.rs b/src/bin/find-the-integer-added-to-array-i.rs new file mode 100644 index 00000000..5f7a5296 --- /dev/null +++ b/src/bin/find-the-integer-added-to-array-i.rs @@ -0,0 +1,18 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn added_integer(nums1: Vec, nums2: Vec) -> i32 { + let (mut min1, mut min2) = (nums1[0], nums2[0]); + + for i in 1..nums1.len() { + min1 = min1.min(nums1[i]); + min2 = min2.min(nums2[i]); + } + + min2 - min1 + } +} From a8eaf8e17897a7d9cb8e2bdfc519ac29f1408c93 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 8 Aug 2024 20:24:26 +0800 Subject: [PATCH 1518/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 22e9e8ae..da9cc949 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 803 | 357 | 418 | 28 | +| 804 | 358 | 418 | 28 | ### 题目 @@ -672,6 +672,7 @@ |3374 | 交替子数组计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-alternating-subarrays.rs) | [leetcode](https://leetcode-cn.com/problems/count-alternating-subarrays/) | Medium | |3388 | 直角三角形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/right-triangles.rs) | [leetcode](https://leetcode-cn.com/problems/right-triangles/) | Medium | |3390 | 覆盖所有点的最少矩形数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-rectangles-to-cover-points.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-rectangles-to-cover-points/) | Medium | +|3397 | 找出与数组相加的整数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-integer-added-to-array-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-integer-added-to-array-i/) | Easy | |100160 | URL化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-url-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-url-lcci/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | From 6f32b4f0077c3e19ec02bdad37541c48adf53865 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 12 Aug 2024 23:19:17 +0800 Subject: [PATCH 1519/1556] src/bin/implement-magic-dictionary.rs --- src/bin/implement-magic-dictionary.rs | 95 +++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/bin/implement-magic-dictionary.rs diff --git a/src/bin/implement-magic-dictionary.rs b/src/bin/implement-magic-dictionary.rs new file mode 100644 index 00000000..9f432876 --- /dev/null +++ b/src/bin/implement-magic-dictionary.rs @@ -0,0 +1,95 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ + +/** + * Your MagicDictionary object will be instantiated and called as such: + * let obj = MagicDictionary::new(); + * obj.build_dict(dictionary); + * let ret_2: bool = obj.search(searchWord); + */ + +#[derive(Clone)] +struct Tier { + data: Vec>>, + is_end: bool, +} + +impl Tier { + fn new() -> Self { + Tier { + data: vec![None; 26], + is_end: false, + } + } + + fn insert(&mut self, data: &[u8]) { + if data.is_empty() { + return; + } + + let mut node = self; + + for i in data { + let index = (i - b'a') as usize; + if node.data[index].is_none() { + node.data[index] = Some(Box::new(Tier::new())); + } + node = node.data[index].as_mut().unwrap(); + } + + node.is_end = true; + } + + /// flag为true表示已经变换过 + fn search(&self, data: &[u8], flag: bool) -> bool { + if data.is_empty() { + return self.is_end && flag; + } + let index = (data[0] - b'a') as usize; + if let Some(x) = self.data[index].as_ref() { + if x.search(&data[1..], flag | false) { + return true; + } + } + + if !flag { + for i in (0..26).filter(|&x| x != index) { + if let Some(x) = self.data[i].as_ref() { + if x.search(&data[1..], true) { + return true; + } + } + } + } + + false + } +} + +struct MagicDictionary { + tier: Tier, +} + +impl MagicDictionary { + fn new() -> Self { + Self { tier: Tier::new() } + } + + fn build_dict(&mut self, dictionary: Vec) { + dictionary + .into_iter() + .for_each(|x| self.tier.insert(x.as_bytes())); + } + + fn search(&self, search_word: String) -> bool { + self.tier.search(search_word.as_bytes(), false) + } +} From a449acb0aedb149a265d8f991c06876055e32f91 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 12 Aug 2024 23:19:18 +0800 Subject: [PATCH 1520/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da9cc949..fc8e45c9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 804 | 358 | 418 | 28 | +| 805 | 358 | 419 | 28 | ### 题目 @@ -298,6 +298,7 @@ |658 | 找到 K 个最接近的元素 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-k-closest-elements.rs) | [leetcode](https://leetcode-cn.com/problems/find-k-closest-elements/) | Medium | |670 | 最大交换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-swap.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-swap/) | Medium | |674 | 最长连续递增序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-continuous-increasing-subsequence.rs) | [leetcode](https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/) | Easy | +|676 | 实现一个魔法字典 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/implement-magic-dictionary.rs) | [leetcode](https://leetcode-cn.com/problems/implement-magic-dictionary/) | Medium | |682 | 棒球比赛 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/baseball-game.rs) | [leetcode](https://leetcode-cn.com/problems/baseball-game/) | Easy | |718 | 最长重复子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-length-of-repeated-subarray.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/) | Medium | |722 | 删除注释 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-comments.rs) | [leetcode](https://leetcode-cn.com/problems/remove-comments/) | Medium | From c1897121254ab63707d245964abb81e802c9f8a6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 13 Aug 2024 20:56:56 +0800 Subject: [PATCH 1521/1556] src/bin/special-array-i.rs --- src/bin/special-array-i.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/bin/special-array-i.rs diff --git a/src/bin/special-array-i.rs b/src/bin/special-array-i.rs new file mode 100644 index 00000000..2f0c3487 --- /dev/null +++ b/src/bin/special-array-i.rs @@ -0,0 +1,20 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn is_array_special(nums: Vec) -> bool { + let mut i = nums[0] % 2; + for x in nums[1..].into_iter() { + if x % 2 == i { + return false; + } + + i = x % 2; + } + + true + } +} From 8aa48e4df083522d764243d0d58b379f04b34e43 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 13 Aug 2024 20:56:56 +0800 Subject: [PATCH 1522/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc8e45c9..c095a80a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 805 | 358 | 419 | 28 | +| 806 | 359 | 419 | 28 | ### 题目 @@ -674,6 +674,7 @@ |3388 | 直角三角形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/right-triangles.rs) | [leetcode](https://leetcode-cn.com/problems/right-triangles/) | Medium | |3390 | 覆盖所有点的最少矩形数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-rectangles-to-cover-points.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-rectangles-to-cover-points/) | Medium | |3397 | 找出与数组相加的整数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-integer-added-to-array-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-integer-added-to-array-i/) | Easy | +|3429 | 特殊数组 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/special-array-i.rs) | [leetcode](https://leetcode-cn.com/problems/special-array-i/) | Easy | |100160 | URL化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-url-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-url-lcci/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | From 0c889828402d1177113f4cbe9c688ec7c3bd056f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 14 Aug 2024 21:38:36 +0800 Subject: [PATCH 1523/1556] src/bin/special-array-ii.rs --- src/bin/special-array-ii.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/bin/special-array-ii.rs diff --git a/src/bin/special-array-ii.rs b/src/bin/special-array-ii.rs new file mode 100644 index 00000000..d8fb29ec --- /dev/null +++ b/src/bin/special-array-ii.rs @@ -0,0 +1,33 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 前缀和 + /// 对于prefix_sum. 如果nums[i] 与 nums[i-1]的奇偶性不同,则prefix_sum[i] = 0, 否则为1 + /// 因此如果 nums[i] ~ nums[j] 是特殊子数组,则prefix_sum[i] == prefix_sum[j] + pub fn is_array_special(nums: Vec, queries: Vec>) -> Vec { + let mut prefix_sum = vec![0]; + + for i in 1..nums.len() { + if nums[i] % 2 != nums[i - 1] % 2 { + prefix_sum.push(prefix_sum[i - 1]); + } else { + prefix_sum.push(prefix_sum[i - 1] + 1); + } + } + + let mut result = vec![]; + for i in queries { + if prefix_sum[i[0] as usize] == prefix_sum[i[1] as usize] { + result.push(true); + } else { + result.push(false); + } + } + + result + } +} From 6166ec2af3f47a63f5f11ba3ef8dfe17ec732503 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 14 Aug 2024 21:38:36 +0800 Subject: [PATCH 1524/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c095a80a..25b531ef 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 806 | 359 | 419 | 28 | +| 807 | 359 | 420 | 28 | ### 题目 @@ -674,6 +674,7 @@ |3388 | 直角三角形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/right-triangles.rs) | [leetcode](https://leetcode-cn.com/problems/right-triangles/) | Medium | |3390 | 覆盖所有点的最少矩形数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-rectangles-to-cover-points.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-rectangles-to-cover-points/) | Medium | |3397 | 找出与数组相加的整数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-integer-added-to-array-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-integer-added-to-array-i/) | Easy | +|3427 | 特殊数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/special-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/special-array-ii/) | Medium | |3429 | 特殊数组 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/special-array-i.rs) | [leetcode](https://leetcode-cn.com/problems/special-array-i/) | Easy | |100160 | URL化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-url-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-url-lcci/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | From f2e4d95f6a8a42b4919f573c9c15ac05d8f8b2d5 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 15 Aug 2024 21:51:33 +0800 Subject: [PATCH 1525/1556] src/bin/find-the-minimum-and-maximum-number-of-nodes-between-critical-points.rs --- ...number-of-nodes-between-critical-points.rs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/bin/find-the-minimum-and-maximum-number-of-nodes-between-critical-points.rs diff --git a/src/bin/find-the-minimum-and-maximum-number-of-nodes-between-critical-points.rs b/src/bin/find-the-minimum-and-maximum-number-of-nodes-between-critical-points.rs new file mode 100644 index 00000000..4ad4dae4 --- /dev/null +++ b/src/bin/find-the-minimum-and-maximum-number-of-nodes-between-critical-points.rs @@ -0,0 +1,62 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} + +impl Solution { + pub fn nodes_between_critical_points(head: Option>) -> Vec { + let mut min_distance = i32::MAX; + let mut pre_value = head.as_ref().unwrap().val; + let mut pre_index = 0; // 前一个节点的下标 + let mut first_index = None; // 第一个极值的下标 + let mut pre_index_1 = None; // 前一个极值的下标 + + let mut current = head.unwrap().next; + while current.is_some() { + let mut c = current.unwrap(); + let current_val = c.val; + let next = c.next.take(); + if next.is_some() { + let next_value = next.as_ref().unwrap().val; + if (current_val < pre_value && current_val < next_value) + || (current_val > pre_value && current_val > next_value) + { + if first_index.is_none() { + first_index = Some(pre_index + 1); + } + + if let Some(x) = pre_index_1 { + min_distance = min_distance.min(pre_index + 1 - x); + } + + pre_index_1 = Some(pre_index + 1); + } + } + + pre_index += 1; + current = next; + pre_value = current_val; + } + + if first_index != pre_index_1 { + vec![min_distance, pre_index_1.unwrap() - first_index.unwrap()] + } else { + vec![-1, -1] + } + } +} From fa5e329a1eaaeba6ca484a1d799a5a208593963d Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 15 Aug 2024 21:51:33 +0800 Subject: [PATCH 1526/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 25b531ef..cb2d05a7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 807 | 359 | 420 | 28 | +| 808 | 359 | 421 | 28 | ### 题目 @@ -518,6 +518,7 @@ |2168 | 检查句子中的数字是否递增 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-numbers-are-ascending-in-a-sentence.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-numbers-are-ascending-in-a-sentence/) | Easy | |2169 | 简易银行系统 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/simple-bank-system.rs) | [leetcode](https://leetcode-cn.com/problems/simple-bank-system/) | Medium | |2177 | 检查两个字符串是否几乎相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-whether-two-strings-are-almost-equivalent.rs) | [leetcode](https://leetcode-cn.com/problems/check-whether-two-strings-are-almost-equivalent/) | Easy | +|2182 | 找出临界点之间的最小和最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-minimum-and-maximum-number-of-nodes-between-critical-points.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-minimum-and-maximum-number-of-nodes-between-critical-points/) | Medium | |2190 | 统计出现过一次的公共字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-common-words-with-one-occurrence.rs) | [leetcode](https://leetcode-cn.com/problems/count-common-words-with-one-occurrence/) | Easy | |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | |2215 | 找出 3 位偶数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/finding-3-digit-even-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/finding-3-digit-even-numbers/) | Easy | From dc35f03745bfa66fe563eb91b8ca70891736e73a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 16 Aug 2024 08:54:03 +0800 Subject: [PATCH 1527/1556] src/bin/design-bitset.rs --- src/bin/design-bitset.rs | 102 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/bin/design-bitset.rs diff --git a/src/bin/design-bitset.rs b/src/bin/design-bitset.rs new file mode 100644 index 00000000..7a257c08 --- /dev/null +++ b/src/bin/design-bitset.rs @@ -0,0 +1,102 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +/** + * `&self` means the method takes an immutable reference. + * If you need a mutable reference, change it to `&mut self` instead. + */ + +/** + * Your Bitset object will be instantiated and called as such: + * let obj = Bitset::new(size); + * obj.fix(idx); + * obj.unfix(idx); + * obj.flip(); + * let ret_4: bool = obj.all(); + * let ret_5: bool = obj.one(); + * let ret_6: i32 = obj.count(); + * let ret_7: String = obj.to_string(); + */ + +struct Bitset { + data: Vec, + size: i32, + count: i32, +} + +impl Bitset { + fn new(size: i32) -> Self { + Self { + data: vec![0; size as usize / 8 + 1], + size, + count: 0, + } + } + + fn set(&mut self, idx: usize, val: u8) { + let index = idx / 8; + let n = idx % 8; + if val == 1 { + let d = 0b1 << (7 - n); + if self.data[index] != self.data[index] | d { + self.count += 1; + self.data[index] = self.data[index] | d; + } + } else { + let d = 0b11111111 ^ (0b1 << (7 - n)); + if self.data[index] != self.data[index] & d { + self.count -= 1; + self.data[index] = self.data[index] & d; + } + } + } + + fn fix(&mut self, idx: i32) { + self.set(idx as usize, 1); + } + + fn unfix(&mut self, idx: i32) { + self.set(idx as usize, 0) + } + + fn flip(&mut self) { + self.count = self.size - self.count; + + for i in 0..self.data.len() { + self.data[i] = !self.data[i]; + } + } + + fn all(&self) -> bool { + self.count == self.size + } + + fn one(&self) -> bool { + self.count > 0 + } + + fn count(&self) -> i32 { + self.count + } + + fn to_string(&self) -> String { + let mut s = String::with_capacity(self.size as usize); + + 'b: for i in 0..self.data.len() { + for index in 0..8 { + if i * 8 + index >= self.size as usize { + break 'b; + } + if self.data[i] >> (7 - index) & 0b1 == 0b1 { + s.push('1'); + } else { + s.push('0'); + } + } + } + s + } +} From 47ee3b928a92e0e23e2c08d9cb68d163ce0d5385 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 16 Aug 2024 08:54:04 +0800 Subject: [PATCH 1528/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cb2d05a7..c483dd1d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 808 | 359 | 421 | 28 | +| 809 | 359 | 422 | 28 | ### 题目 @@ -531,6 +531,7 @@ |2261 | 分组得分最高的所有下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/all-divisions-with-the-highest-score-of-a-binary-array.rs) | [leetcode](https://leetcode-cn.com/problems/all-divisions-with-the-highest-score-of-a-binary-array/) | Medium | |2269 | 元素计数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-elements-with-strictly-smaller-and-greater-elements.rs) | [leetcode](https://leetcode-cn.com/problems/count-elements-with-strictly-smaller-and-greater-elements/) | Easy | |2279 | 拆分成最多数目的正偶数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-split-of-positive-even-integers.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-split-of-positive-even-integers/) | Medium | +|2285 | 设计位集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-bitset.rs) | [leetcode](https://leetcode-cn.com/problems/design-bitset/) | Medium | |2290 | 拿出最少数目的魔法豆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-minimum-number-of-magic-beans.rs) | [leetcode](https://leetcode-cn.com/problems/removing-minimum-number-of-magic-beans/) | Medium | |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | |2300 | 构造限制重复的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-string-with-repeat-limit.rs) | [leetcode](https://leetcode-cn.com/problems/construct-string-with-repeat-limit/) | Medium | From 993890196e6aff73f1677ee59606f84a186bec3a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 19 Aug 2024 21:32:39 +0800 Subject: [PATCH 1529/1556] src/bin/sum-lists-lcci.rs --- src/bin/sum-lists-lcci.rs | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/bin/sum-lists-lcci.rs diff --git a/src/bin/sum-lists-lcci.rs b/src/bin/sum-lists-lcci.rs new file mode 100644 index 00000000..7e1cb0c0 --- /dev/null +++ b/src/bin/sum-lists-lcci.rs @@ -0,0 +1,52 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} +impl Solution { + pub fn add_two_numbers( + l1: Option>, + l2: Option>, + ) -> Option> { + let mut result = ListNode::new(0); + let mut current = &mut result; + let mut s = 0; // 进制 + let (mut l1, mut l2) = (l1, l2); + + while l1.is_some() || l2.is_some() { + let a = if let Some(mut x) = l1 { + l1 = x.next.take(); + x.val + } else { + 0 + }; + + let b = if let Some(mut x) = l2 { + l2 = x.next.take(); + x.val + } else { + 0 + }; + let s1 = (a + b + s) / 10; + let v = (a + b + s) % 10; + s = s1; + current = current.next.insert(Box::new(ListNode::new(v))); + } + + result.next.take() + } +} From ea344ec5a6fcde328327da9e677d729a07ba86f8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 19 Aug 2024 21:32:40 +0800 Subject: [PATCH 1530/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c483dd1d..5653d416 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 809 | 359 | 422 | 28 | +| 810 | 359 | 423 | 28 | ### 题目 @@ -681,6 +681,7 @@ |100160 | URL化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-url-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-url-lcci/) | Easy | |100162 | 字符串轮转 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-rotation-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-rotation-lcci/) | Easy | |100163 | 移除重复节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/remove-duplicate-node-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/remove-duplicate-node-lcci/) | Easy | +|100188 | 链表求和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-lists-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/sum-lists-lcci/) | Medium | |100240 | 魔术索引 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/magic-index-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/magic-index-lcci/) | Easy | |100273 | 用两个栈实现队列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/yong-liang-ge-zhan-shi-xian-dui-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | Easy | |100274 | 斐波那契数列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/fei-bo-na-qi-shu-lie-lcof.rs) | [leetcode](https://leetcode-cn.com/problems/fei-bo-na-qi-shu-lie-lcof/) | Easy | From c663caab4f36ce834f94567070adee7c6af976e4 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 20 Aug 2024 21:06:23 +0800 Subject: [PATCH 1531/1556] src/bin/maximum-size-of-a-set-after-removals.rs --- .../maximum-size-of-a-set-after-removals.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/bin/maximum-size-of-a-set-after-removals.rs diff --git a/src/bin/maximum-size-of-a-set-after-removals.rs b/src/bin/maximum-size-of-a-set-after-removals.rs new file mode 100644 index 00000000..f2bcbebf --- /dev/null +++ b/src/bin/maximum-size-of-a-set-after-removals.rs @@ -0,0 +1,30 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + /// 1. 先去重 + /// 2. 移除都存在的数 + pub fn maximum_set_size(nums1: Vec, nums2: Vec) -> i32 { + let l = nums1.len() as i32 / 2; + let n1 = nums1.into_iter().collect::>(); + let n2 = nums2.into_iter().collect::>(); + + let mut comm = n1.intersection(&n2).count() as i32; + let mut result = n1.len() as i32 + n2.len() as i32 - comm; // 所有元素的数量 + + if n1.len() as i32 > l { + let nm = comm.min(n1.len() as i32 - l); // 如果交集大于comm,则全部移除交集,否则,移除多余的n1的元素 + result -= n1.len() as i32 - nm - l; + comm -= nm; + } + + if n2.len() as i32 > l { + result -= (n2.len() as i32 - comm.min(n2.len() as i32 - l)) - l; + } + + result + } +} From 783cb4c5939f13d0f55e787fe8d23801f9012377 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Tue, 20 Aug 2024 21:06:24 +0800 Subject: [PATCH 1532/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5653d416..a2080eb5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 810 | 359 | 423 | 28 | +| 811 | 359 | 424 | 28 | ### 题目 @@ -660,6 +660,7 @@ |3221 | 找出峰值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-peaks.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-peaks/) | Easy | |3226 | 最小数字游戏 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-game.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-game/) | Easy | |3227 | 找出缺失和重复的数字 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-missing-and-repeated-values.rs) | [leetcode](https://leetcode-cn.com/problems/find-missing-and-repeated-values/) | Easy | +|3228 | 移除后集合的最多元素数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-size-of-a-set-after-removals.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-size-of-a-set-after-removals/) | Medium | |3231 | 需要添加的硬币的最小数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-coins-to-be-added.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-coins-to-be-added/) | Medium | |3234 | 双模幂运算 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/double-modular-exponentiation.rs) | [leetcode](https://leetcode-cn.com/problems/double-modular-exponentiation/) | Medium | |3241 | 划分数组并满足最大差限制 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/divide-array-into-arrays-with-max-difference.rs) | [leetcode](https://leetcode-cn.com/problems/divide-array-into-arrays-with-max-difference/) | Medium | From 98171930ad2dfd7f70ca2f4e5121c7e67a6c1b02 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 7 Sep 2024 22:56:45 +0800 Subject: [PATCH 1533/1556] src/bin/permutation-difference-between-two-strings.rs --- ...mutation-difference-between-two-strings.rs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/permutation-difference-between-two-strings.rs diff --git a/src/bin/permutation-difference-between-two-strings.rs b/src/bin/permutation-difference-between-two-strings.rs new file mode 100644 index 00000000..e493a642 --- /dev/null +++ b/src/bin/permutation-difference-between-two-strings.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_permutation_difference(s: String, t: String) -> i32 { + let mut map = [0; 26]; + + for (i, v) in s.bytes().enumerate() { + map[(v - b'a') as usize] = i; + } + + let mut result = 0; + + for (i, v) in t.bytes().enumerate() { + result += (i as i32 - map[(v - b'a') as usize] as i32).abs(); + } + + result + } +} From ad408b1884b3a77f05a6d3bf0326fa297cb624b0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 7 Sep 2024 22:56:45 +0800 Subject: [PATCH 1534/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a2080eb5..da8af675 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 811 | 359 | 424 | 28 | +| 812 | 360 | 424 | 28 | ### 题目 @@ -677,6 +677,7 @@ |3388 | 直角三角形 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/right-triangles.rs) | [leetcode](https://leetcode-cn.com/problems/right-triangles/) | Medium | |3390 | 覆盖所有点的最少矩形数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-rectangles-to-cover-points.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-rectangles-to-cover-points/) | Medium | |3397 | 找出与数组相加的整数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-integer-added-to-array-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-integer-added-to-array-i/) | Easy | +|3412 | 两个字符串的排列差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutation-difference-between-two-strings.rs) | [leetcode](https://leetcode-cn.com/problems/permutation-difference-between-two-strings/) | Easy | |3427 | 特殊数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/special-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/special-array-ii/) | Medium | |3429 | 特殊数组 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/special-array-i.rs) | [leetcode](https://leetcode-cn.com/problems/special-array-i/) | Easy | |100160 | URL化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-url-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-url-lcci/) | Easy | From 296ae0bf68b83eb08930cf82333e984b5a397934 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 8 Sep 2024 15:16:23 +0800 Subject: [PATCH 1535/1556] src/bin/sum-of-squares-of-special-elements.rs --- src/bin/sum-of-squares-of-special-elements.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/bin/sum-of-squares-of-special-elements.rs diff --git a/src/bin/sum-of-squares-of-special-elements.rs b/src/bin/sum-of-squares-of-special-elements.rs new file mode 100644 index 00000000..b687fd38 --- /dev/null +++ b/src/bin/sum-of-squares-of-special-elements.rs @@ -0,0 +1,15 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn sum_of_squares(nums: Vec) -> i32 { + let n = nums.len(); + nums.into_iter() + .enumerate() + .filter_map(|(x, y)| if n % (x + 1) == 0 { Some(y * y) } else { None }) + .sum() + } +} From 3db192eb85ffc24d79a29c3e7310bf6fa44126f7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 8 Sep 2024 15:16:24 +0800 Subject: [PATCH 1536/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index da8af675..1b2e2945 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 812 | 360 | 424 | 28 | +| 813 | 361 | 424 | 28 | ### 题目 @@ -625,6 +625,7 @@ |2828 | 执行子串操作后的字典序最小字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographically-smallest-string-after-substring-operation.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographically-smallest-string-after-substring-operation/) | Medium | |2831 | 美丽下标对的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-beautiful-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-beautiful-pairs/) | Easy | |2838 | 查询后矩阵的和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-matrix-after-queries.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-matrix-after-queries/) | Medium | +|2844 | 特殊元素平方和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-squares-of-special-elements.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-squares-of-special-elements/) | Easy | |2847 | 最大字符串配对数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-maximum-number-of-string-pairs.rs) | [leetcode](https://leetcode-cn.com/problems/find-maximum-number-of-string-pairs/) | Easy | |2857 | 总行驶距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/total-distance-traveled.rs) | [leetcode](https://leetcode-cn.com/problems/total-distance-traveled/) | Easy | |2866 | 最长奇偶子数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/longest-even-odd-subarray-with-threshold.rs) | [leetcode](https://leetcode-cn.com/problems/longest-even-odd-subarray-with-threshold/) | Easy | From a9d79421ce24428d0248f6a5e7218e41200c58c7 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 9 Sep 2024 20:13:40 +0800 Subject: [PATCH 1537/1556] src/bin/merge-nodes-in-between-zeros.rs --- src/bin/merge-nodes-in-between-zeros.rs | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/bin/merge-nodes-in-between-zeros.rs diff --git a/src/bin/merge-nodes-in-between-zeros.rs b/src/bin/merge-nodes-in-between-zeros.rs new file mode 100644 index 00000000..ea5cf601 --- /dev/null +++ b/src/bin/merge-nodes-in-between-zeros.rs @@ -0,0 +1,42 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +// Definition for singly-linked list. +#[derive(PartialEq, Eq, Clone, Debug)] +pub struct ListNode { + pub val: i32, + pub next: Option>, +} + +impl ListNode { + #[inline] + fn new(val: i32) -> Self { + ListNode { next: None, val } + } +} + +impl Solution { + pub fn merge_nodes(mut head: Option>) -> Option> { + let mut result = ListNode::new(0); + let mut next = &mut result.next; + let mut current = head.unwrap().next; + + let mut val = 0; + while current.is_some() { + if current.as_ref().unwrap().val == 0 { + next.insert(Box::new(ListNode::new(val))); + val = 0; + next = &mut next.as_mut().unwrap().next; + } else { + val += current.as_ref().unwrap().val; + } + + current = current.unwrap().next; + } + + result.next.take() + } +} From c73784eba7804db6c59517d80fe83565edb5ca5c Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 9 Sep 2024 20:13:41 +0800 Subject: [PATCH 1538/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b2e2945..c399c9c0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 813 | 361 | 424 | 28 | +| 814 | 361 | 425 | 28 | ### 题目 @@ -534,6 +534,7 @@ |2285 | 设计位集 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/design-bitset.rs) | [leetcode](https://leetcode-cn.com/problems/design-bitset/) | Medium | |2290 | 拿出最少数目的魔法豆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-minimum-number-of-magic-beans.rs) | [leetcode](https://leetcode-cn.com/problems/removing-minimum-number-of-magic-beans/) | Medium | |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | +|2299 | 合并零之间的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-nodes-in-between-zeros.rs) | [leetcode](https://leetcode-cn.com/problems/merge-nodes-in-between-zeros/) | Medium | |2300 | 构造限制重复的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-string-with-repeat-limit.rs) | [leetcode](https://leetcode-cn.com/problems/construct-string-with-repeat-limit/) | Medium | |2310 | 将数组和减半的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-halve-array-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-halve-array-sum/) | Medium | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | From 62908f2dc20fcccadef0245a3ab1d9ddca285267 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 22 Sep 2024 09:54:19 +0800 Subject: [PATCH 1539/1556] src/bin/find-the-town-judge.rs --- src/bin/find-the-town-judge.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/bin/find-the-town-judge.rs diff --git a/src/bin/find-the-town-judge.rs b/src/bin/find-the-town-judge.rs new file mode 100644 index 00000000..08439f1b --- /dev/null +++ b/src/bin/find-the-town-judge.rs @@ -0,0 +1,33 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::future::ready; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn find_judge(n: i32, trust: Vec>) -> i32 { + let mut map = std::collections::HashMap::new(); + let mut m = std::collections::HashSet::new(); + + for v in trust { + map.entry(v[1]).and_modify(|x| *x += 1).or_insert(1); + m.insert(v[0]); + } + + let mut result = None; + for i in 1..=n { + let v = map.get(&i).unwrap_or(&0); + if *v == n - 1 && !m.contains(&i) { + if result.is_none() { + result = Some(i); + } else { + return -1; + } + } + } + + result.unwrap_or(-1) + } +} From f0e97611047d2ab329b644caef66472c0fd42ae6 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 22 Sep 2024 09:54:19 +0800 Subject: [PATCH 1540/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c399c9c0..554fa231 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 814 | 361 | 425 | 28 | +| 815 | 362 | 425 | 28 | ### 题目 @@ -363,6 +363,7 @@ |1021 | 在二叉树中分配硬币 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-coins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-coins-in-binary-tree/) | Medium | |1035 | 二叉树的堂兄弟节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/cousins-in-binary-tree.rs) | [leetcode](https://leetcode-cn.com/problems/cousins-in-binary-tree/) | Easy | |1036 | 腐烂的橘子 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rotting-oranges.rs) | [leetcode](https://leetcode-cn.com/problems/rotting-oranges/) | Medium | +|1039 | 找到小镇的法官 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-town-judge.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-town-judge/) | Easy | |1041 | 可以被一步捕获的棋子数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/available-captures-for-rook.rs) | [leetcode](https://leetcode-cn.com/problems/available-captures-for-rook/) | Easy | |1045 | 检查替换后的词是否有效 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-word-is-valid-after-substitutions.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-word-is-valid-after-substitutions/) | Medium | |1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | From 53778c4f30e05318555124359c66e21405ebce85 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 23 Sep 2024 22:31:10 +0800 Subject: [PATCH 1541/1556] src/bin/best-sightseeing-pair.rs --- src/bin/best-sightseeing-pair.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/bin/best-sightseeing-pair.rs diff --git a/src/bin/best-sightseeing-pair.rs b/src/bin/best-sightseeing-pair.rs new file mode 100644 index 00000000..6a7ae98f --- /dev/null +++ b/src/bin/best-sightseeing-pair.rs @@ -0,0 +1,18 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_score_sightseeing_pair(values: Vec) -> i32 { + let mut result = values[0] + 0 + values[1] - 1; + let mut i = (values[0] + 0).max(values[1] + 1); + for index in 2..values.len() { + result = result.max(values[index] - index as i32 + i); + i = i.max(values[index] + index as i32); + } + + result + } +} From 55a881ad79788504d17e0c9c37faa99479f817ad Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Mon, 23 Sep 2024 22:31:10 +0800 Subject: [PATCH 1542/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 554fa231..4fbca7ec 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 815 | 362 | 425 | 28 | +| 816 | 362 | 426 | 28 | ### 题目 @@ -369,6 +369,7 @@ |1046 | 最大连续1的个数 III | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-consecutive-ones-iii.rs) | [leetcode](https://leetcode-cn.com/problems/max-consecutive-ones-iii/) | Medium | |1050 | 前序遍历构造二叉搜索树 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs) | [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/) | Medium | |1054 | 十进制整数的反码 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/complement-of-base-10-integer.rs) | [leetcode](https://leetcode-cn.com/problems/complement-of-base-10-integer/) | Easy | +|1063 | 最佳观光组合 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/best-sightseeing-pair.rs) | [leetcode](https://leetcode-cn.com/problems/best-sightseeing-pair/) | Medium | |1070 | 负二进制转换 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/convert-to-base-2.rs) | [leetcode](https://leetcode-cn.com/problems/convert-to-base-2/) | Medium | |1072 | 链表中的下一个更大节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/next-greater-node-in-linked-list.rs) | [leetcode](https://leetcode-cn.com/problems/next-greater-node-in-linked-list/) | Medium | |1079 | 从根到叶的二进制数之和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/sum-of-root-to-leaf-binary-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/sum-of-root-to-leaf-binary-numbers/) | Easy | From f713c80bb66670f9d5316389c7c89a05ae8fae7a Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 25 Sep 2024 20:58:23 +0800 Subject: [PATCH 1543/1556] src/bin/maximize-number-of-subsequences-in-a-string.rs --- ...mize-number-of-subsequences-in-a-string.rs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/bin/maximize-number-of-subsequences-in-a-string.rs diff --git a/src/bin/maximize-number-of-subsequences-in-a-string.rs b/src/bin/maximize-number-of-subsequences-in-a-string.rs new file mode 100644 index 00000000..d6919e2b --- /dev/null +++ b/src/bin/maximize-number-of-subsequences-in-a-string.rs @@ -0,0 +1,31 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn maximum_subsequence_count(text: String, pattern: String) -> i64 { + let mut pattern = pattern.bytes(); + let a = pattern.next().unwrap(); + let b = pattern.next().unwrap(); + + let mut count = [0; 2]; + + let mut result = 0; + + for i in text.bytes() { + if i == a { + count[0] += 1; + } else if i == b { + result += count[0]; + count[1] += 1; + } + } + if a != b { + result + count[0].max(count[1]) + } else { + count[0] * (count[0] + 1) / 2 + } + } +} From 8afb426a442668361761d5d7f61989ed738b1248 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Wed, 25 Sep 2024 20:58:23 +0800 Subject: [PATCH 1544/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4fbca7ec..c910e181 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 816 | 362 | 426 | 28 | +| 817 | 362 | 427 | 28 | ### 题目 @@ -538,6 +538,7 @@ |2292 | 统计包含给定前缀的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/counting-words-with-a-given-prefix.rs) | [leetcode](https://leetcode-cn.com/problems/counting-words-with-a-given-prefix/) | Easy | |2299 | 合并零之间的节点 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/merge-nodes-in-between-zeros.rs) | [leetcode](https://leetcode-cn.com/problems/merge-nodes-in-between-zeros/) | Medium | |2300 | 构造限制重复的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-string-with-repeat-limit.rs) | [leetcode](https://leetcode-cn.com/problems/construct-string-with-repeat-limit/) | Medium | +|2309 | 字符串中最多数目的子序列 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximize-number-of-subsequences-in-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/maximize-number-of-subsequences-in-a-string/) | Medium | |2310 | 将数组和减半的最少操作次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-halve-array-sum.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-halve-array-sum/) | Medium | |2320 | 找出数组中的所有 K 近邻下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-all-k-distant-indices-in-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/) | Easy | |2328 | 向表达式添加括号后的最小结果 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimize-result-by-adding-parentheses-to-expression.rs) | [leetcode](https://leetcode-cn.com/problems/minimize-result-by-adding-parentheses-to-expression/) | Medium | From 128cc403e54e8cadb4c267489cc5dcacfafb3bc8 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 26 Sep 2024 20:20:04 +0800 Subject: [PATCH 1545/1556] src/bin/difference-between-element-sum-and-digit-sum-of-an-array.rs --- ...n-element-sum-and-digit-sum-of-an-array.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/bin/difference-between-element-sum-and-digit-sum-of-an-array.rs diff --git a/src/bin/difference-between-element-sum-and-digit-sum-of-an-array.rs b/src/bin/difference-between-element-sum-and-digit-sum-of-an-array.rs new file mode 100644 index 00000000..0e3cd707 --- /dev/null +++ b/src/bin/difference-between-element-sum-and-digit-sum-of-an-array.rs @@ -0,0 +1,22 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn difference_of_sum(nums: Vec) -> i32 { + let (mut a1, mut a2) = (0, 0); + + for mut i in nums { + a1 += i; + + while i > 0 { + a2 += i % 10; + i /= 10; + } + } + + (a1 - a2).abs() + } +} From 99fc265072c37f75ffc53181366bb524c2779573 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Thu, 26 Sep 2024 20:20:04 +0800 Subject: [PATCH 1546/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c910e181..2e03080c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 817 | 362 | 427 | 28 | +| 818 | 363 | 427 | 28 | ### 题目 @@ -581,6 +581,7 @@ |2616 | 执行 K 次操作后的最大分数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximal-score-after-applying-k-operations.rs) | [leetcode](https://leetcode-cn.com/problems/maximal-score-after-applying-k-operations/) | Medium | |2619 | 根据规则将箱子分类 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/categorize-box-according-to-criteria.rs) | [leetcode](https://leetcode-cn.com/problems/categorize-box-according-to-criteria/) | Easy | |2621 | 查询数组异或美丽值 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-xor-beauty-of-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-xor-beauty-of-array/) | Medium | +|2624 | 数组元素和与数字和的绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/difference-between-element-sum-and-digit-sum-of-an-array.rs) | [leetcode](https://leetcode-cn.com/problems/difference-between-element-sum-and-digit-sum-of-an-array/) | Easy | |2625 | 子矩阵元素加 1 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/increment-submatrices-by-one.rs) | [leetcode](https://leetcode-cn.com/problems/increment-submatrices-by-one/) | Medium | |2630 | 交替数字和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/alternating-digit-sum.rs) | [leetcode](https://leetcode-cn.com/problems/alternating-digit-sum/) | Easy | |2645 | 递枕头 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/pass-the-pillow.rs) | [leetcode](https://leetcode-cn.com/problems/pass-the-pillow/) | Easy | From 62cd1d0b0dc2bb489223a0d93c69297babfe13e0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 27 Sep 2024 21:02:23 +0800 Subject: [PATCH 1547/1556] src/bin/minimum-recolors-to-get-k-consecutive-black-blocks.rs --- ...olors-to-get-k-consecutive-black-blocks.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/bin/minimum-recolors-to-get-k-consecutive-black-blocks.rs diff --git a/src/bin/minimum-recolors-to-get-k-consecutive-black-blocks.rs b/src/bin/minimum-recolors-to-get-k-consecutive-black-blocks.rs new file mode 100644 index 00000000..549859bb --- /dev/null +++ b/src/bin/minimum-recolors-to-get-k-consecutive-black-blocks.rs @@ -0,0 +1,36 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +use std::io::Read; + +fn main() {} + +struct Solution; + +impl Solution { + pub fn minimum_recolors(blocks: String, k: i32) -> i32 { + let mut b = 0; + + for &i in blocks.as_bytes().into_iter().take(k as usize) { + if i == b'B' { + b += 1; + } + } + + let mut result = k - b; + let block = blocks.as_bytes(); + + for i in 1..=blocks.len() - k as usize { + if block[i - 1] == b'B' { + b -= 1; + } + + if block[i - 1 + k as usize] == b'B' { + b += 1; + } + + result = result.min(k - b); + } + + result + } +} From b72e1bea4c74725c4bc8a7890513eab7ec9bdb26 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 27 Sep 2024 21:02:23 +0800 Subject: [PATCH 1548/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e03080c..582106b5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 818 | 363 | 427 | 28 | +| 819 | 364 | 427 | 28 | ### 题目 @@ -556,6 +556,7 @@ |2442 | 算术三元组的数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/number-of-arithmetic-triplets.rs) | [leetcode](https://leetcode-cn.com/problems/number-of-arithmetic-triplets/) | Easy | |2443 | 检查数组是否存在有效划分 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-there-is-a-valid-partition-for-the-array.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-there-is-a-valid-partition-for-the-array/) | Medium | |2461 | 感染二叉树需要的总时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/amount-of-time-for-binary-tree-to-be-infected.rs) | [leetcode](https://leetcode-cn.com/problems/amount-of-time-for-binary-tree-to-be-infected/) | Medium | +|2463 | 得到 K 个黑块的最少涂色次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-recolors-to-get-k-consecutive-black-blocks.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks/) | Easy | |2470 | 从字符串中移除星号 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/removing-stars-from-a-string.rs) | [leetcode](https://leetcode-cn.com/problems/removing-stars-from-a-string/) | Medium | |2473 | 数位和相等数对的最大和 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/max-sum-of-a-pair-with-equal-sum-of-digits.rs) | [leetcode](https://leetcode-cn.com/problems/max-sum-of-a-pair-with-equal-sum-of-digits/) | Medium | |2482 | 被列覆盖的最多行数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-rows-covered-by-columns.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-rows-covered-by-columns/) | Medium | From 8319528edf5d74af9a627931f21a5559fc842044 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 28 Sep 2024 14:49:31 +0800 Subject: [PATCH 1549/1556] src/bin/check-if-grid-satisfies-conditions.rs --- src/bin/check-if-grid-satisfies-conditions.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/check-if-grid-satisfies-conditions.rs diff --git a/src/bin/check-if-grid-satisfies-conditions.rs b/src/bin/check-if-grid-satisfies-conditions.rs new file mode 100644 index 00000000..e441b621 --- /dev/null +++ b/src/bin/check-if-grid-satisfies-conditions.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn satisfies_conditions(grid: Vec>) -> bool { + for i in 0..grid.len() { + for j in 0..grid[0].len() { + if let Some(Some(&x)) = grid.get(i + 1).map(|c| c.get(j)) { + if x != grid[i][j] { + return false; + } + } + + if let Some(Some(&x)) = grid.get(i).map(|c| c.get(j + 1)) { + if x == grid[i][j] { + return false; + } + } + } + } + + true + } +} From 9b2b4d581df3edeedbca03da6136728d80410d21 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 28 Sep 2024 14:49:31 +0800 Subject: [PATCH 1550/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 582106b5..f6d25a3b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 819 | 364 | 427 | 28 | +| 820 | 365 | 427 | 28 | ### 题目 @@ -685,6 +685,7 @@ |3390 | 覆盖所有点的最少矩形数目 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-rectangles-to-cover-points.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-rectangles-to-cover-points/) | Medium | |3397 | 找出与数组相加的整数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-integer-added-to-array-i.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-integer-added-to-array-i/) | Easy | |3412 | 两个字符串的排列差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/permutation-difference-between-two-strings.rs) | [leetcode](https://leetcode-cn.com/problems/permutation-difference-between-two-strings/) | Easy | +|3415 | 判断矩阵是否满足条件 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-grid-satisfies-conditions.rs) | [leetcode](https://leetcode-cn.com/problems/check-if-grid-satisfies-conditions/) | Easy | |3427 | 特殊数组 II | [src](https://github.com/rustors/leetcode/blob/main/src/bin/special-array-ii.rs) | [leetcode](https://leetcode-cn.com/problems/special-array-ii/) | Medium | |3429 | 特殊数组 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/special-array-i.rs) | [leetcode](https://leetcode-cn.com/problems/special-array-i/) | Easy | |100160 | URL化 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/string-to-url-lcci.rs) | [leetcode](https://leetcode-cn.com/problems/string-to-url-lcci/) | Easy | From 05549a7b8e711fe1f668720f21b4f76befdd187f Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 29 Sep 2024 20:03:53 +0800 Subject: [PATCH 1551/1556] src/bin/time-needed-to-buy-tickets.rs --- src/bin/time-needed-to-buy-tickets.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/bin/time-needed-to-buy-tickets.rs diff --git a/src/bin/time-needed-to-buy-tickets.rs b/src/bin/time-needed-to-buy-tickets.rs new file mode 100644 index 00000000..2041af7d --- /dev/null +++ b/src/bin/time-needed-to-buy-tickets.rs @@ -0,0 +1,27 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn time_required_to_buy(tickets: Vec, k: i32) -> i32 { + let n = tickets[k as usize]; + + tickets + .into_iter() + .enumerate() + .map(|(i, v)| { + if i <= k as usize { + v.min(n) + } else { + if v < n { + v + } else { + n - 1 + } + } + }) + .sum() + } +} From 2cdcaafab9c28908549ba803213ae59f5c00e564 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sun, 29 Sep 2024 20:03:53 +0800 Subject: [PATCH 1552/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f6d25a3b..fc1d9ea8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 820 | 365 | 427 | 28 | +| 821 | 366 | 427 | 28 | ### 题目 @@ -522,6 +522,7 @@ |2177 | 检查两个字符串是否几乎相等 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-whether-two-strings-are-almost-equivalent.rs) | [leetcode](https://leetcode-cn.com/problems/check-whether-two-strings-are-almost-equivalent/) | Easy | |2182 | 找出临界点之间的最小和最大距离 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-the-minimum-and-maximum-number-of-nodes-between-critical-points.rs) | [leetcode](https://leetcode-cn.com/problems/find-the-minimum-and-maximum-number-of-nodes-between-critical-points/) | Medium | |2190 | 统计出现过一次的公共字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/count-common-words-with-one-occurrence.rs) | [leetcode](https://leetcode-cn.com/problems/count-common-words-with-one-occurrence/) | Easy | +|2195 | 买票需要的时间 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/time-needed-to-buy-tickets.rs) | [leetcode](https://leetcode-cn.com/problems/time-needed-to-buy-tickets/) | Easy | |2210 | 找出数组排序后的目标下标 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/find-target-indices-after-sorting-array.rs) | [leetcode](https://leetcode-cn.com/problems/find-target-indices-after-sorting-array/) | Easy | |2215 | 找出 3 位偶数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/finding-3-digit-even-numbers.rs) | [leetcode](https://leetcode-cn.com/problems/finding-3-digit-even-numbers/) | Easy | |2226 | 环和杆 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/rings-and-rods.rs) | [leetcode](https://leetcode-cn.com/problems/rings-and-rods/) | Easy | From 227bd8a087a07ecbd1badb55c00b3a438a5d4fc3 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 4 Oct 2024 11:48:54 +0800 Subject: [PATCH 1553/1556] src/bin/minimum-operations-to-exceed-threshold-value-i.rs --- .../minimum-operations-to-exceed-threshold-value-i.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/bin/minimum-operations-to-exceed-threshold-value-i.rs diff --git a/src/bin/minimum-operations-to-exceed-threshold-value-i.rs b/src/bin/minimum-operations-to-exceed-threshold-value-i.rs new file mode 100644 index 00000000..dd2ee5c3 --- /dev/null +++ b/src/bin/minimum-operations-to-exceed-threshold-value-i.rs @@ -0,0 +1,11 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn min_operations(nums: Vec, k: i32) -> i32 { + nums.into_iter().filter(|x| *x < k).count() as _ + } +} From 286e0ea5307cb7a201274589877c0bfbb7709def Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 4 Oct 2024 11:48:54 +0800 Subject: [PATCH 1554/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fc1d9ea8..f8bcbd76 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 821 | 366 | 427 | 28 | +| 822 | 367 | 427 | 28 | ### 题目 @@ -676,6 +676,7 @@ |3275 | 输入单词需要的最少按键次数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-number-of-pushes-to-type-word-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-number-of-pushes-to-type-word-i/) | Easy | |3320 | 相同分数的最大操作数目 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-operations-with-the-same-score-i.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-operations-with-the-same-score-i/) | Easy | |3330 | 修改矩阵 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/modify-the-matrix.rs) | [leetcode](https://leetcode-cn.com/problems/modify-the-matrix/) | Easy | +|3331 | 超过阈值的最少操作数 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-operations-to-exceed-threshold-value-i.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-operations-to-exceed-threshold-value-i/) | Easy | |3334 | 重新分装苹果 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/apple-redistribution-into-boxes.rs) | [leetcode](https://leetcode-cn.com/problems/apple-redistribution-into-boxes/) | Easy | |3346 | 满足距离约束且字典序最小的字符串 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/lexicographically-smallest-string-after-operations-with-constraint.rs) | [leetcode](https://leetcode-cn.com/problems/lexicographically-smallest-string-after-operations-with-constraint/) | Medium | |3347 | 将元素分配到两个数组中 I | [src](https://github.com/rustors/leetcode/blob/main/src/bin/distribute-elements-into-two-arrays-i.rs) | [leetcode](https://leetcode-cn.com/problems/distribute-elements-into-two-arrays-i/) | Easy | From bcde8d25565e92c52663e91df1b805719441a551 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 5 Oct 2024 10:11:43 +0800 Subject: [PATCH 1555/1556] src/bin/maximum-number-of-balloons.rs --- src/bin/maximum-number-of-balloons.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/bin/maximum-number-of-balloons.rs diff --git a/src/bin/maximum-number-of-balloons.rs b/src/bin/maximum-number-of-balloons.rs new file mode 100644 index 00000000..7d43ee33 --- /dev/null +++ b/src/bin/maximum-number-of-balloons.rs @@ -0,0 +1,23 @@ +#![allow(dead_code, unused, unused_variables, non_snake_case)] + +fn main() {} + +struct Solution; + +impl Solution { + pub fn max_number_of_balloons(text: String) -> i32 { + let mut v = [0; 5]; + for i in text.bytes() { + match i { + b'b' => v[0] += 1, + b'a' => v[1] += 1, + b'l' => v[2] += 1, + b'o' => v[3] += 1, + b'n' => v[4] += 1, + _ => {} + } + } + + v[0].min(v[1]).min(v[2] / 2).min(v[3] / 2).min(v[4]) + } +} From 66a9fdeff5112dcdbe910ba4edc416222cc900b0 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Sat, 5 Oct 2024 10:11:44 +0800 Subject: [PATCH 1556/1556] README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f8bcbd76..94ffc560 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ | Total | Easy | Medium | Hard | | :----: | :----: | :----: | :----: | -| 822 | 367 | 427 | 28 | +| 823 | 368 | 427 | 28 | ### 题目 @@ -400,6 +400,7 @@ |1289 | 一周中的第几天 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/day-of-the-week.rs) | [leetcode](https://leetcode-cn.com/problems/day-of-the-week/) | Easy | |1293 | 存在连续三个奇数的数组 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/three-consecutive-odds.rs) | [leetcode](https://leetcode-cn.com/problems/three-consecutive-odds/) | Easy | |1295 | 收集足够苹果的最小花园周长 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-garden-perimeter-to-collect-enough-apples.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-garden-perimeter-to-collect-enough-apples/) | Medium | +|1297 | “气球” 的最大数量 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/maximum-number-of-balloons.rs) | [leetcode](https://leetcode-cn.com/problems/maximum-number-of-balloons/) | Easy | |1303 | 得到目标值的最少行动次数 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-moves-to-reach-target-score.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-moves-to-reach-target-score/) | Medium | |1306 | 最小绝对差 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/minimum-absolute-difference.rs) | [leetcode](https://leetcode-cn.com/problems/minimum-absolute-difference/) | Easy | |1310 | 给植物浇水 | [src](https://github.com/rustors/leetcode/blob/main/src/bin/watering-plants.rs) | [leetcode](https://leetcode-cn.com/problems/watering-plants/) | Medium |