A certain bug's home is on the x-axis at position x
. Help them get there from position 0
.
+
+
The bug jumps according to the following rules:
+
+
+ - It can jump exactly
a
positions forward (to the right).
+ - It can jump exactly
b
positions backward (to the left).
+ - It cannot jump backward twice in a row.
+ - It cannot jump to any
forbidden
positions.
+
+
+
The bug may jump forward beyond its home, but it cannot jump to positions numbered with negative integers.
+
+
Given an array of integers forbidden
, where forbidden[i]
means that the bug cannot jump to the position forbidden[i]
, and integers a
, b
, and x
, return the minimum number of jumps needed for the bug to reach its home. If there is no possible sequence of jumps that lands the bug on position x
, return -1.
+
+
+
Example 1:
+
+
Input: forbidden = [14,4,18,1,15], a = 3, b = 15, x = 9
+Output: 3
+Explanation: 3 jumps forward (0 -> 3 -> 6 -> 9) will get the bug home.
+
+
+
Example 2:
+
+
Input: forbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11
+Output: -1
+
+
+
Example 3:
+
+
Input: forbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7
+Output: 2
+Explanation: One jump forward (0 -> 16) then one jump backward (16 -> 7) will get the bug home.
+
+
+
+
Constraints:
+
+
+ 1 <= forbidden.length <= 1000
+ 1 <= a, b, forbidden[i] <= 2000
+ 0 <= x <= 2000
+ - All the elements in
forbidden
are distinct.
+ - Position
x
is not forbidden.
+
+
\ No newline at end of file
diff --git a/rustgym/src/leetcode/_1688_count_of_matches_in_tournament.rs b/rustgym/src/leetcode/_1688_count_of_matches_in_tournament.rs
index b3b8e028..08cedf62 100644
--- a/rustgym/src/leetcode/_1688_count_of_matches_in_tournament.rs
+++ b/rustgym/src/leetcode/_1688_count_of_matches_in_tournament.rs
@@ -22,4 +22,4 @@ fn test() {
let n = 14;
let res = 13;
assert_eq!(Solution::number_of_matches(n), res);
-}
\ No newline at end of file
+}
diff --git a/rustgym/src/leetcode/_1689_partitioning_into_minimum_number_of_deci_binary_numbers.rs b/rustgym/src/leetcode/_1689_partitioning_into_minimum_number_of_deci_binary_numbers.rs
index 085aa21d..6eb5bbbd 100644
--- a/rustgym/src/leetcode/_1689_partitioning_into_minimum_number_of_deci_binary_numbers.rs
+++ b/rustgym/src/leetcode/_1689_partitioning_into_minimum_number_of_deci_binary_numbers.rs
@@ -15,4 +15,4 @@ fn test() {
let n = "32".to_string();
let res = 3;
assert_eq!(Solution::min_partitions(n), res);
-}
\ No newline at end of file
+}
diff --git a/schema/src/leetcode_description.rs b/schema/src/leetcode_description.rs
new file mode 100644
index 00000000..b45acb9c
--- /dev/null
+++ b/schema/src/leetcode_description.rs
@@ -0,0 +1,23 @@
+use super::schema::leetcode_description;
+use rustgym_consts::*;
+use std::fmt;
+
+#[derive(Debug, Queryable, Insertable)]
+#[table_name = "leetcode_description"]
+pub struct LeetcodeDescription {
+ pub id: i32,
+ filename: String,
+ html: String,
+}
+
+impl LeetcodeDescription {
+ pub fn new(id: i32, filename: String, html: String) -> Self {
+ LeetcodeDescription { id, filename, html }
+ }
+}
+
+impl fmt::Display for LeetcodeDescription {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "[{}]({}/{})", self.id, LEETCODE_DESC, self.filename)
+ }
+}
diff --git a/schema/src/leetcode_question.rs b/schema/src/leetcode_question.rs
index 7578a50c..def6a375 100644
--- a/schema/src/leetcode_question.rs
+++ b/schema/src/leetcode_question.rs
@@ -2,7 +2,7 @@ use super::schema::leetcode_question;
use rustgym_consts::*;
use std::fmt;
-#[derive(Debug, Queryable, Insertable, Serialize)]
+#[derive(Debug, Queryable, Insertable)]
#[table_name = "leetcode_question"]
pub struct LeetcodeQuestion {
pub id: i32,
diff --git a/schema/src/lib.rs b/schema/src/lib.rs
index 5f7dd70d..16c75a38 100644
--- a/schema/src/lib.rs
+++ b/schema/src/lib.rs
@@ -1,10 +1,9 @@
#[macro_use]
extern crate diesel;
-#[macro_use]
-extern crate serde;
-
+pub mod leetcode_description;
pub mod leetcode_question;
pub mod schema;
+pub use leetcode_description::*;
pub use leetcode_question::*;
diff --git a/schema/src/schema.rs b/schema/src/schema.rs
index 300556c7..e5bf8404 100644
--- a/schema/src/schema.rs
+++ b/schema/src/schema.rs
@@ -1,3 +1,11 @@
+table! {
+ leetcode_description (id) {
+ id -> Integer,
+ filename -> Text,
+ html -> Text,
+ }
+}
+
table! {
leetcode_question (id) {
id -> Integer,
@@ -7,3 +15,8 @@ table! {
level -> Integer,
}
}
+
+allow_tables_to_appear_in_same_query!(
+ leetcode_description,
+ leetcode_question,
+);