Skip to content

Commit

Permalink
use derive_problem
Browse files Browse the repository at this point in the history
  • Loading branch information
SKTT1Ryze committed Oct 25, 2023
1 parent c835050 commit acf69bb
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 127 deletions.
32 changes: 10 additions & 22 deletions leetcode/src/problems/add_two_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,15 @@ use super::{Difficulty, Problem, Topic};

pub struct ProblemImpl;

impl Problem for ProblemImpl {
fn id(&self) -> usize {
2
}
fn difficulty(&self) -> Difficulty {
Difficulty::Medium
}
fn topic(&self) -> Topic {
Topic::Algorithms
}
fn title(&self) -> String {
"Add Two Numbers".into()
}
fn description(&self) -> String {
r#"You are given two non-empty linked lists representing two non-negative integers.
crate::derive_problem!(
ProblemImpl,
2,
Difficulty::Medium,
Topic::Algorithms,
"Add Two Numbers",
r#"You are given two non-empty linked lists representing two non-negative integers.
The digits are stored in reverse order, and each of their nodes contains a single digit.
Add the two numbers and return the sum as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself."#
.into()
}
fn labels(&self) -> Vec<String> {
["Link List".into()].into()
}
}
You may assume the two numbers do not contain any leading zero, except the number 0 itself."#,
"Link List".into()
);
30 changes: 10 additions & 20 deletions leetcode/src/problems/longest_palindromic_substring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@ use super::{Difficulty, Problem, Topic};

pub struct ProblemImpl;

impl Problem for ProblemImpl {
fn id(&self) -> usize {
5
}
fn difficulty(&self) -> Difficulty {
Difficulty::Medium
}
fn topic(&self) -> Topic {
Topic::Algorithms
}
fn title(&self) -> String {
"Longest Palindromic Substring".into()
}
fn description(&self) -> String {
r#"Given a string s, return the longest palindromic substring in s."#.into()
}
fn labels(&self) -> Vec<String> {
["String".into(), "DP".into()].into()
}
}
crate::derive_problem!(
ProblemImpl,
5,
Difficulty::Medium,
Topic::Algorithms,
"Longest Palindromic Substring",
r#"Given a string s, return the longest palindromic substring in s."#,
"String".into(),
"DP".into()
);
33 changes: 11 additions & 22 deletions leetcode/src/problems/longest_substring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,15 @@ use super::{Difficulty, Problem, Topic};

pub struct ProblemImpl;

impl Problem for ProblemImpl {
fn id(&self) -> usize {
3
}
fn difficulty(&self) -> Difficulty {
Difficulty::Medium
}
fn topic(&self) -> Topic {
Topic::Algorithms
}
fn title(&self) -> String {
"Longest Substring Without Repeating Characters".into()
}
fn description(&self) -> String {
r#"Given a string s, find the length of the longest
crate::derive_problem!(
ProblemImpl,
3,
Difficulty::Medium,
Topic::Algorithms,
"Longest Substring Without Repeating Characters",
r#"Given a string s, find the length of the longest
substring without repeating characters.
"#
.into()
}
fn labels(&self) -> Vec<String> {
["String".into(), "Hash Map".into()].into()
}
}
"#,
"String".into(),
"Hash Map".into()
);
31 changes: 10 additions & 21 deletions leetcode/src/problems/median_of_two_sorted_arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,13 @@ use super::{Difficulty, Problem, Topic};

pub struct ProblemImpl;

impl Problem for ProblemImpl {
fn id(&self) -> usize {
4
}
fn difficulty(&self) -> Difficulty {
Difficulty::Hard
}
fn topic(&self) -> Topic {
Topic::Algorithms
}
fn title(&self) -> String {
"Median of Two Sorted Arrays".into()
}
fn description(&self) -> String {
r#"Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
The overall run time complexity should be O(log (m+n))."#.into()
}
fn labels(&self) -> Vec<String> {
["Array".into()].into()
}
}
crate::derive_problem!(
ProblemImpl,
4,
Difficulty::Hard,
Topic::Algorithms,
"Median of Two Sorted Arrays",
r#"Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
The overall run time complexity should be O(log (m+n))."#,
"Array".into()
);
33 changes: 11 additions & 22 deletions leetcode/src/problems/two_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,14 @@ use super::{Difficulty, Problem, Topic};

pub struct ProblemImpl;

impl Problem for ProblemImpl {
fn id(&self) -> usize {
1
}
fn difficulty(&self) -> Difficulty {
Difficulty::Easy
}
fn topic(&self) -> Topic {
Topic::Algorithms
}
fn title(&self) -> String {
"Two Sum".into()
}
fn description(&self) -> String {
r#"Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.You can return the answer in any order."#
.into()
}
fn labels(&self) -> Vec<String> {
["Array".into(), "Hash Map".into()].into()
}
}
crate::derive_problem!(
ProblemImpl,
1,
Difficulty::Easy,
Topic::Algorithms,
"Two Sum",
r#"Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.You can return the answer in any order."#,
"Array".into(),
"Hash Map".into()
);
29 changes: 9 additions & 20 deletions leetcode/src/problems/zigzag_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,12 @@ use super::{Difficulty, Problem, Topic};

pub struct ProblemImpl;

impl Problem for ProblemImpl {
fn id(&self) -> usize {
6
}
fn difficulty(&self) -> Difficulty {
Difficulty::Medium
}
fn topic(&self) -> Topic {
Topic::Algorithms
}
fn title(&self) -> String {
"Zigzag Conversion".into()
}
fn description(&self) -> String {
"".into()
}
fn labels(&self) -> Vec<String> {
["String".into()].into()
}
}
crate::derive_problem!(
ProblemImpl,
6,
Difficulty::Medium,
Topic::Algorithms,
"Zigzag Conversion",
"",
"String".into()
);

0 comments on commit acf69bb

Please sign in to comment.