-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
134 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[config] | ||
default_to_workspace = false | ||
|
||
[tasks.rm_sqlite] | ||
script = ["rm rustgym.sqlite"] | ||
|
||
[tasks.migration] | ||
script = ["diesel migration run --database-url rustgym.sqlite"] | ||
|
||
[tasks.readme] | ||
script = ["cargo run --bin rustgym-readme"] | ||
dependencies = ["rm_sqlite", "migration"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
migrations/2020-12-15-091647_create_leetcode_description/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- This file should undo anything in `up.sql` |
6 changes: 6 additions & 0 deletions
6
migrations/2020-12-15-091647_create_leetcode_description/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE leetcode_description ( | ||
id INTEGER PRIMARY KEY | ||
NOT NULL, | ||
filename TEXT NOT NULL, | ||
html TEXT NOT NULL | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<div><p>A certain bug's home is on the x-axis at position <code>x</code>. Help them get there from position <code>0</code>.</p> | ||
|
||
<p>The bug jumps according to the following rules:</p> | ||
|
||
<ul> | ||
<li>It can jump exactly <code>a</code> positions <strong>forward</strong> (to the right).</li> | ||
<li>It can jump exactly <code>b</code> positions <strong>backward</strong> (to the left).</li> | ||
<li>It cannot jump backward twice in a row.</li> | ||
<li>It cannot jump to any <code>forbidden</code> positions.</li> | ||
</ul> | ||
|
||
<p>The bug may jump forward <strong>beyond</strong> its home, but it <strong>cannot jump</strong> to positions numbered with <strong>negative</strong> integers.</p> | ||
|
||
<p>Given an array of integers <code>forbidden</code>, where <code>forbidden[i]</code> means that the bug cannot jump to the position <code>forbidden[i]</code>, and integers <code>a</code>, <code>b</code>, and <code>x</code>, return <em>the minimum number of jumps needed for the bug to reach its home</em>. If there is no possible sequence of jumps that lands the bug on position <code>x</code>, return <code>-1.</code></p> | ||
|
||
<p> </p> | ||
<p><strong>Example 1:</strong></p> | ||
|
||
<pre><strong>Input:</strong> forbidden = [14,4,18,1,15], a = 3, b = 15, x = 9 | ||
<strong>Output:</strong> 3 | ||
<strong>Explanation:</strong> 3 jumps forward (0 -> 3 -> 6 -> 9) will get the bug home. | ||
</pre> | ||
|
||
<p><strong>Example 2:</strong></p> | ||
|
||
<pre><strong>Input:</strong> forbidden = [8,3,16,6,12,20], a = 15, b = 13, x = 11 | ||
<strong>Output:</strong> -1 | ||
</pre> | ||
|
||
<p><strong>Example 3:</strong></p> | ||
|
||
<pre><strong>Input:</strong> forbidden = [1,6,2,14,5,17,4], a = 16, b = 9, x = 7 | ||
<strong>Output:</strong> 2 | ||
<strong>Explanation:</strong> One jump forward (0 -> 16) then one jump backward (16 -> 7) will get the bug home. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>1 <= forbidden.length <= 1000</code></li> | ||
<li><code>1 <= a, b, forbidden[i] <= 2000</code></li> | ||
<li><code>0 <= x <= 2000</code></li> | ||
<li>All the elements in <code>forbidden</code> are distinct.</li> | ||
<li>Position <code>x</code> is not forbidden.</li> | ||
</ul> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,4 @@ fn test() { | |
let n = 14; | ||
let res = 13; | ||
assert_eq!(Solution::number_of_matches(n), res); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,4 @@ fn test() { | |
let n = "32".to_string(); | ||
let res = 3; | ||
assert_eq!(Solution::min_partitions(n), res); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters