Skip to content

Commit a31d671

Browse files
author
ruislan
committed
solved q911
refactor some files to avoid duplication of method names
1 parent ad210a9 commit a31d671

File tree

14 files changed

+59
-14
lines changed

14 files changed

+59
-14
lines changed

src/q/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ mod q896;
415415
mod q897;
416416
mod q905;
417417
mod q908;
418+
mod q911;
418419
mod q914;
419420
mod q917;
420421
mod q921;

src/q/q137.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::q::Solution;
22

33
#[allow(unused)]
44
impl Solution {
5-
pub fn single_number(nums: Vec<i32>) -> i32 {
5+
pub fn single_number_2(nums: Vec<i32>) -> i32 {
66
// 方法1
77
// hashmap
88
// O(n), O(n)

src/q/q1449.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::q::Solution;
22

33
#[allow(unused)]
44
impl Solution {
5-
pub fn largest_number(cost: Vec<i32>, target: i32) -> String {
5+
pub fn largest_number_2(cost: Vec<i32>, target: i32) -> String {
66
// 方法1
77
// 还是个动态规划的典型题目
88
// 这里我们核心要考虑的是两个数字比较,谁大?

src/q/q229.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::q::Solution;
22

33
#[allow(unused)]
44
impl Solution {
5-
pub fn majority_element(nums: Vec<i32>) -> Vec<i32> {
5+
pub fn majority_element_2(nums: Vec<i32>) -> Vec<i32> {
66
// 方法1
77
// 计数,O(n)空间,不是最佳
88
// AC 0ms 2.3mb

src/q/q236.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ impl TreeNode {
2525

2626
#[allow(unused)]
2727
impl Solution {
28-
pub fn lowest_common_ancestor(root: Option<Rc<RefCell<TreeNode>>>, p: Option<Rc<RefCell<TreeNode>>>, q: Option<Rc<RefCell<TreeNode>>>) -> Option<Rc<RefCell<TreeNode>>> {
28+
pub fn lowest_common_ancestor_2(root: Option<Rc<RefCell<TreeNode>>>, p: Option<Rc<RefCell<TreeNode>>>, q: Option<Rc<RefCell<TreeNode>>>) -> Option<Rc<RefCell<TreeNode>>> {
2929
// 方法1
3030
if root.is_none() { return None; }
3131
if root == p || root == q { return root; }
3232
let left = root.as_ref().unwrap().borrow().left.clone();
3333
let right = root.as_ref().unwrap().borrow().right.clone();
34-
let left_parent = Self::lowest_common_ancestor(left, p.clone(), q.clone());
35-
let right_parent = Self::lowest_common_ancestor(right, p.clone(), q.clone());
34+
let left_parent = Self::lowest_common_ancestor_2(left, p.clone(), q.clone());
35+
let right_parent = Self::lowest_common_ancestor_2(right, p.clone(), q.clone());
3636
if left_parent.is_none() { return right_parent; }
3737
if right_parent.is_none() { return left_parent; }
3838
root

src/q/q260.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::q::Solution;
22

33
#[allow(unused)]
44
impl Solution {
5-
pub fn single_number(nums: Vec<i32>) -> Vec<i32> {
5+
pub fn single_number_3(nums: Vec<i32>) -> Vec<i32> {
66
// 方法1
77
// hashset
88
// AC 0ms 2.2mb 32/32

src/q/q275.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::q::Solution;
22

33
#[allow(unused)]
44
impl Solution {
5-
pub fn h_index(citations: Vec<i32>) -> i32 {
5+
pub fn h_index_2(citations: Vec<i32>) -> i32 {
66
// 方法1
77
// 和q274基本相同,这里用二分方法来处理
88
// AC 0ms 2.7mb

src/q/q437.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl TreeNode {
2424

2525
#[allow(unused)]
2626
impl Solution {
27-
pub fn path_sum(root: Option<Rc<RefCell<TreeNode>>>, target_sum: i32) -> i32 {
27+
pub fn path_sum_2(root: Option<Rc<RefCell<TreeNode>>>, target_sum: i32) -> i32 {
2828
// 方法1
2929
// dfs
3030
// 每次向下我们都将结果增加1位,然后遍历,如果结果正好等于target,就叠加计数

src/q/q552.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::q::Solution;
22

33
#[allow(unused)]
44
impl Solution {
5-
pub fn check_record(n: i32) -> i32 {
5+
pub fn check_record_2(n: i32) -> i32 {
66
// 方法1
77
// 回溯 + 记忆化
88
// AC 340ms 29.3mb 用hashmap会超时:(

src/q/q556.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::q::Solution;
22

33
#[allow(unused)]
44
impl Solution {
5-
pub fn next_greater_element(n: i32) -> i32 {
5+
pub fn next_greater_element_2(n: i32) -> i32 {
66
// 方法1
77
// 这个算法还挺有名的哈,就叫next permutation
88
// 简单来说

0 commit comments

Comments
 (0)