Skip to content

chore: upgrade toolchain to nightly-2025-02-01 #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:

env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
RUST_TOOLCHAIN: nightly-2024-12-01
RUST_TOOLCHAIN: nightly-2025-02-01

name: Check
jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:

env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
RUST_TOOLCHAIN: nightly-2024-12-01
RUST_TOOLCHAIN: nightly-2025-02-01

name: Test
jobs:
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly-2024-12-01"
channel = "nightly-2025-02-01"
8 changes: 4 additions & 4 deletions src/problem/p0001_two_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ pub struct Solution {}
impl Solution {
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
let mut map = HashMap::new();
for (i, item) in nums.iter().enumerate() {
if map.contains_key(&(target - item)) {
return vec![map[&(target - item)], i as i32];
for (i, &n) in nums.iter().enumerate() {
if let Some(&j) = map.get(&(target - n)) {
return vec![j, i as i32];
}
map.insert(item, i as i32);
map.insert(n, i as i32);
}

vec![]
Expand Down
28 changes: 13 additions & 15 deletions src/problem/p0002_add_two_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,29 @@ impl Solution {
return l1;
}

let mut root_pointer = ListNode::new(0);
let mut current = &mut root_pointer;
let mut carry = 0;
let mut l1 = l1;
let mut l2 = l2;
let mut ret = ListNode::new(0);
let mut current = &mut ret;
let mut carry = 0;

while l1.is_some() || l2.is_some() || carry != 0 {
let mut v1 = 0;
let mut v2 = 0;
if let Some(l) = l1 {
v1 = l.val;
l1 = l.next;
if let Some(mut n1) = l1 {
v1 = n1.val;
l1 = n1.next.take();
}
if let Some(l) = l2 {
v2 = l.val;
l2 = l.next;
if let Some(mut n2) = l2 {
v2 = n2.val;
l2 = n2.next.take();
}
let num = v1 + v2 + carry;
carry = num / 10;
let n = num % 10;
current.next = Some(Box::new(ListNode::new(n)));
let v = (v1 + v2 + carry) % 10;
carry = (v1 + v2 + carry) / 10;
current.next = Some(Box::new(ListNode::new(v)));
current = current.next.as_mut().unwrap();
}

ret.next
root_pointer.next
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, hash_map::Entry};
use std::collections::HashMap;

/// [3] Longest Substring Without Repeating Characters
///
Expand Down Expand Up @@ -41,20 +41,20 @@ impl Solution {
return s.len() as i32;
}

let mut map = HashMap::new();
let mut ret = 0;
let mut pre = 0;
let mut dic = HashMap::new();
for (i, b) in s.as_bytes().iter().enumerate() {
match dic.entry(b) {
Entry::Occupied(o) => {
if pre <= *o.get() {
for (i, c) in s.bytes().enumerate() {
match map.entry(c) {
std::collections::hash_map::Entry::Occupied(o) => {
if o.get() >= &pre {
pre = o.get() + 1;
}
}
Entry::Vacant(_) => {}
std::collections::hash_map::Entry::Vacant(_) => {}
}
ret = std::cmp::max(ret, i - pre + 1);
dic.insert(b, i);
ret = ret.max(i - pre + 1);
map.insert(c, i);
}

ret as i32
Expand Down
30 changes: 13 additions & 17 deletions src/problem/p0005_longest_palindromic_substring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,33 @@ pub struct Solution {}

impl Solution {
pub fn longest_palindrome(s: String) -> String {
if s.len() < 2 {
if s.len() == 1 {
return s;
}

let a = s.as_bytes();
let mut ret = &a[0..1];
for i in 0..a.len() - 1 {
let s1 = Self::pali(a, i as i32, i as i32 + 1);
let s2 = Self::pali(a, i as i32, i as i32);
if ret.len() < s1.len() {
let s = s.as_bytes();
let mut ret: &[u8] = &[];
for i in 0..s.len() - 1 {
let s1 = Solution::pali(s, i as i32, i);
let s2 = Solution::pali(s, i as i32, i + 1);
if s1.len() > ret.len() {
ret = s1;
}
if ret.len() < s2.len() {
if s2.len() > ret.len() {
ret = s2;
}
}

String::from_utf8_lossy(ret).to_string()
}

fn pali(a: &[u8], mut i: i32, mut j: i32) -> &[u8] {
if a[i as usize] != a[j as usize] {
return &[];
fn pali(s: &[u8], mut l: i32, mut r: usize) -> &[u8] {
while l >= 0 && r < s.len() && s[l as usize] == s[r] {
l -= 1;
r += 1;
}

while i >= 0 && j < a.len() as i32 && a[i as usize] == a[j as usize] {
i -= 1;
j += 1;
}

&a[(i + 1) as usize..j as usize]
&s[(l + 1) as usize..r]
}
}

Expand Down
16 changes: 5 additions & 11 deletions src/problem/p0007_reverse_integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,17 @@ impl Solution {
return x;
}

let mut sign: i64 = 1;
let mut x = x as i64;
if x < 0 {
sign = -1;
}
x *= sign;

let mut ret = 0;
let mut ret: i64 = 0;
let mut x = x;
while x != 0 {
ret = ret * 10 + x % 10;
if ret * sign > i32::MAX as i64 || ret * sign < i32::MIN as i64 {
ret = x as i64 % 10 + ret * 10;
if ret > i32::MAX as i64 || ret < i32::MIN as i64 {
return 0;
}
x /= 10;
}

(ret * sign) as i32
ret as i32
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/problem/p0011_container_with_most_water.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::cmp::{max, min};

/// [11] Container With Most Water
///
/// You are given an integer array height of length n. There are n vertical lines drawn such that
Expand Down Expand Up @@ -37,14 +35,17 @@ impl Solution {
let mut ret = 0;
let mut i = 0;
let mut j = height.len() - 1;
while i < j {
let t = min(height[i], height[j]) * (j - i) as i32;
ret = max(t, ret);
let mut t;
while i != j {
t = (j - i) as i32;
if height[i] < height[j] {
t *= height[i];
i += 1;
} else {
t *= height[j];
j -= 1;
}
ret = ret.max(t);
}

ret
Expand Down
14 changes: 8 additions & 6 deletions src/problem/p0017_letter_combinations_of_a_phone_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ mod tests {

#[test]
fn test_17() {
assert_eq!(Solution::letter_combinations("23".to_owned()), vec![
"ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"
]);
assert_eq!(Solution::letter_combinations("2".to_owned()), vec![
"a", "b", "c"
]);
assert_eq!(
Solution::letter_combinations("23".to_owned()),
vec!["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]
);
assert_eq!(
Solution::letter_combinations("2".to_owned()),
vec!["a", "b", "c"]
);
assert_eq!(
Solution::letter_combinations("".to_owned()),
Vec::<String>::new()
Expand Down
7 changes: 4 additions & 3 deletions src/problem/p0022_generate_parentheses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ mod tests {

#[test]
fn test_22() {
assert_eq!(Solution::generate_parenthesis(3), vec![
"((()))", "(()())", "(())()", "()(())", "()()()"
]);
assert_eq!(
Solution::generate_parenthesis(3),
vec!["((()))", "(()())", "(())()", "()(())", "()()()"]
);
assert_eq!(Solution::generate_parenthesis(1), vec!["()"]);
assert_eq!(Solution::generate_parenthesis(2), vec!["(())", "()()"]);
}
Expand Down
7 changes: 4 additions & 3 deletions src/problem/p0056_merge_intervals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ mod tests {
Solution::merge(vec![vec![2, 6], vec![1, 3], vec![8, 10], vec![15, 18]]),
vec![vec![1, 6], vec![8, 10], vec![15, 18]]
);
assert_eq!(Solution::merge(vec![vec![1, 4], vec![4, 5]]), vec![vec![
1, 5
]]);
assert_eq!(
Solution::merge(vec![vec![1, 4], vec![4, 5]]),
vec![vec![1, 5]]
);
}
}
7 changes: 4 additions & 3 deletions src/problem/p0094_binary_tree_inorder_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ mod tests {

#[test]
fn test_94() {
assert_eq!(Solution::inorder_traversal(tree![1, null, 2, 3]), vec![
1, 3, 2
]);
assert_eq!(
Solution::inorder_traversal(tree![1, null, 2, 3]),
vec![1, 3, 2]
);
assert_eq!(Solution::inorder_traversal(tree![1]), vec![1]);
assert_eq!(Solution::inorder_traversal(tree![]), vec![]);
}
Expand Down
17 changes: 10 additions & 7 deletions src/problem/p0095_unique_binary_search_trees_ii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ mod tests {

#[test]
fn test_95() {
assert_eq!(Solution::generate_trees(3), vec![
tree![1, null, 2, null, 3],
tree![1, null, 3, 2],
tree![2, 1, 3],
tree![3, 1, null, null, 2],
tree![3, 2, null, 1]
]);
assert_eq!(
Solution::generate_trees(3),
vec![
tree![1, null, 2, null, 3],
tree![1, null, 3, 2],
tree![2, 1, 3],
tree![3, 1, null, null, 2],
tree![3, 2, null, 1]
]
);
}
}
7 changes: 4 additions & 3 deletions src/problem/p0114_flatten_binary_tree_to_linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ mod tests {
fn test_114() {
let tree_node = tree!(1, 2, 5, 3, 4, null, 6);
Solution::flatten(&tree_node);
assert_eq!(tree_node, tree![
1, null, 2, null, 3, null, 4, null, 5, null, 6
]);
assert_eq!(
tree_node,
tree![1, null, 2, null, 3, null, 4, null, 5, null, 6]
);
}
}
7 changes: 4 additions & 3 deletions src/problem/p0144_binary_tree_preorder_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ mod tests {

#[test]
fn test_144() {
assert_eq!(Solution::preorder_traversal(tree![1, null, 2, 3]), vec![
1, 2, 3
]);
assert_eq!(
Solution::preorder_traversal(tree![1, null, 2, 3]),
vec![1, 2, 3]
);
assert_eq!(Solution::preorder_traversal(tree![1]), vec![1]);
assert_eq!(Solution::preorder_traversal(tree![]), vec![]);
}
Expand Down
7 changes: 4 additions & 3 deletions src/problem/p0145_binary_tree_postorder_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ mod tests {

#[test]
fn test_145() {
assert_eq!(Solution::postorder_traversal(tree![1, null, 2, 3]), vec![
3, 2, 1
]);
assert_eq!(
Solution::postorder_traversal(tree![1, null, 2, 3]),
vec![3, 2, 1]
);
assert_eq!(Solution::postorder_traversal(tree![1]), vec![1]);
assert_eq!(Solution::postorder_traversal(tree![1, 2]), vec![2, 1]);
}
Expand Down
14 changes: 8 additions & 6 deletions src/problem/p0503_next_greater_element_ii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ mod tests {

#[test]
fn test_0503() {
assert_eq!(Solution::next_greater_elements(vec![1, 2, 1]), vec![
2, -1, 2
]);
assert_eq!(Solution::next_greater_elements(vec![1, 2, 3, 4, 3]), vec![
2, 3, 4, -1, 4
]);
assert_eq!(
Solution::next_greater_elements(vec![1, 2, 1]),
vec![2, -1, 2]
);
assert_eq!(
Solution::next_greater_elements(vec![1, 2, 3, 4, 3]),
vec![2, 3, 4, -1, 4]
);
}
}
14 changes: 8 additions & 6 deletions src/problem/p0739_daily_temperatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ mod tests {
Solution::daily_temperatures(vec![73, 74, 75, 71, 69, 72, 76, 73]),
vec![1, 1, 4, 2, 1, 1, 0, 0]
);
assert_eq!(Solution::daily_temperatures(vec![30, 40, 50, 60]), vec![
1, 1, 1, 0
]);
assert_eq!(Solution::daily_temperatures(vec![30, 60, 90]), vec![
1, 1, 0
]);
assert_eq!(
Solution::daily_temperatures(vec![30, 40, 50, 60]),
vec![1, 1, 1, 0]
);
assert_eq!(
Solution::daily_temperatures(vec![30, 60, 90]),
vec![1, 1, 0]
);
}
}
Loading
Loading