Skip to content

Feature/new script #3

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 16 commits into from
Jul 25, 2021
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ git2 = "0.13.15"
reqwest = { version = "0.10", features = ["blocking", "json"] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
clap = "3.0.0-beta.2"
tera = "1.12.1"
lazy_static = "1.4.0"
regex = "1"


[[bin]]
name ="leetcode"
path ="src/main.rs"
path = "src/main.rs"
990 changes: 251 additions & 739 deletions README.md

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions src/all.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::file;

use std::sync::{Arc, Mutex};
use std::thread;
use crate::http::Resp;


/// 重新格式化
pub fn all() {
let files = file::get_all_bin_file();

let v = Vec::<Resp>::with_capacity(files.len());

let x = Arc::new(Mutex::new(v));
let mut handlers = vec![];

for i in 0..=files.len() / 10 {
// 把files分块,分成10个文件一块
let files = if i * 10 + 10 > files.len() {
files[i * 10..files.len()].to_vec()
} else {
files[i * 10..i * 10 + 10].to_vec()
};

let x = x.clone();

handlers.push(thread::spawn(move || {
for i in files {
println!("{} downloading", i);
let resp = crate::http::get_question_info(&i);
x.lock().unwrap().push(resp);
}
}))
}

for i in handlers {
i.join().unwrap();
}

crate::file::write_readme(&mut *x.lock().unwrap());
}
2 changes: 1 addition & 1 deletion src/bin/boats-to-save-people.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Solution {
count
}

pub fn num_rescue_boats(mut people: Vec<i32>, limit: i32) -> i32 {
pub fn num_rescue_boats(people: Vec<i32>, limit: i32) -> i32 {
let mut v = vec![0; (limit + 1) as usize];

for i in people {
Expand Down
4 changes: 2 additions & 2 deletions src/bin/climbing-stairs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ptr::hash;


fn main() {}

Expand All @@ -12,7 +12,7 @@ impl Solution {

let (mut a, mut b) = (1, 2);

for i in 3..=n {
for _i in 3..=n {
let a1 = a;
a = b;
b = a1 + b;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/combination-sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Solution {
v.push(i);
r.push(v);
} else if i < target {
let mut x = Self::calc(&candidates, target - i);
let x = Self::calc(&candidates, target - i);
for mut m in x {
if !m.is_empty() {
if i >= *m.last().unwrap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl TreeNode {
}

use std::cell::RefCell;
use std::ops::Deref;

use std::rc::Rc;

struct Solution;
Expand Down
6 changes: 3 additions & 3 deletions src/bin/count-complete-tree-nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ impl TreeNode {
}
}

use std::arch::x86_64::_mm_xor_pd;

use std::cell::RefCell;
use std::cmp::{max, min};

use std::rc::Rc;

impl Solution {
Expand Down Expand Up @@ -70,7 +70,7 @@ impl Solution {
}

while max_count - min_count > 1 {
let mut middle = (min_count + max_count) / 2;
let middle = (min_count + max_count) / 2;

let e = exists(root.as_ref(), middle, level);
if e {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/fei-bo-na-qi-shu-lie-lcof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl Solution {
return n;
}
let (mut last, mut result) = (1, 1);
for i in 2..n {
for _i in 2..n {
let result1 = result + last;
last = result;
result = result1 % 1000000007;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/find-k-closest-elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Solution {
}

let index = Self::split(&arr, x);
let (mut start, mut end, mut k) = (index, index, k as usize);
let (mut start, mut end, k) = (index, index, k as usize);
while end - start < k - 1 {
if start == 0 {
end += 1;
Expand Down
4 changes: 2 additions & 2 deletions src/bin/group-anagrams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Solution {
.or_insert(vec![i]);
}

hash.into_iter().map(|(x, y)| y).collect()
hash.into_iter().map(|(_x, y)| y).collect()
}

// 计算字母出现的个数
Expand All @@ -37,6 +37,6 @@ impl Solution {
}
}

hash.into_iter().map(|(x, y)| y).collect()
hash.into_iter().map(|(_x, y)| y).collect()
}
}
2 changes: 1 addition & 1 deletion src/bin/kth-largest-element-in-an-array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Solution {
}

fn heapify(nums: &mut [i32]) {
let mut index = (nums.len() - 1) / 2;
let index = (nums.len() - 1) / 2;

for i in (0..=index).rev() {
Self::down_heap(nums, i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl Solution {
h.entry(i).and_modify(|x| *x += 1).or_insert(1);
}

let mut s = h.iter().map(|(x, y)| *y).collect::<Vec<i32>>();
let mut s = h.iter().map(|(_x, y)| *y).collect::<Vec<i32>>();
s.sort();

let (mut l, mut k) = (h.len(), k);
Expand Down
2 changes: 1 addition & 1 deletion src/bin/letter-case-permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Solution {

fn func(s: String, v: &mut Vec<String>, index: usize) {
let mut new_s = s.clone();
let mut new_s = unsafe { new_s.as_bytes_mut() };
let new_s = unsafe { new_s.as_bytes_mut() };
v.push(s);
if index == new_s.len() {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/longest-substring-without-repeating-characters.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;


fn main() {
assert_eq!(2, Solution::length_of_longest_substring("aab".to_string()));
Expand Down
2 changes: 1 addition & 1 deletion src/bin/magical-string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fn main() {}
struct Solution;

impl Solution {
pub fn magical_string(mut n: i32) -> i32 {
pub fn magical_string(n: i32) -> i32 {
if n == 0 {
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/bin/majority-element-ii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ impl Solution {
}

m.iter()
.filter(|(&x, &y)| y > length)
.map(|(&x, &y)| x)
.filter(|(&_x, &y)| y > length)
.map(|(&x, &_y)| x)
.collect()
}

Expand Down Expand Up @@ -106,7 +106,7 @@ impl Solution {
None
})
.filter(|x| x.is_some())
.map(|mut x| x.unwrap())
.map(|x| x.unwrap())
.collect()
}
}
27 changes: 27 additions & 0 deletions src/bin/maximum-population-year.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
fn main() {}

struct Solution;

impl Solution {
pub fn maximum_population(logs: Vec<Vec<i32>>) -> i32 {
let mut v = vec![0; 1000];

for i in logs {
for x in (i[0] - 1950) as usize..(i[1] - 1950) as usize {
v[x] += 1;
}
}

let mut max = 0;

for i in 1..v.len() {
max = if v[i] > v[max] {
i
} else {
max
}
}

max as i32 + 1950
}
}
2 changes: 1 addition & 1 deletion src/bin/maximum-product-of-word-lengths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl Solution {

for i in 0..words.len() {
for &j in words[i].as_bytes() {
v[i] |= (1 << (j - b'a'));
v[i] |= 1 << (j - b'a');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/bin/number-complement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {
struct Solution;

impl Solution {
pub fn find_complement(mut num: i32) -> i32 {
pub fn find_complement(num: i32) -> i32 {
let lz = num.leading_zeros();
!num << lz >> lz
}
Expand Down
5 changes: 4 additions & 1 deletion src/bin/qiu-12n-lcof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ impl Solution {
pub fn sum_nums(n: i32) -> i32 {
let mut n = n;
// 利用布尔短路的思想,n == 0 时,不会允许&&后面的表达式
n > 0 && (n += Self::sum_nums(n - 1)) == ();
if n > 0 {
n += Self::sum_nums(n - 1);
}

n
}
}
2 changes: 1 addition & 1 deletion src/bin/reverse-linked-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Solution {
let mut root = v.pop().unwrap();
let mut s = &mut root;
while !v.is_empty() {
let mut node = v.pop().unwrap();
let node = v.pop().unwrap();
s.as_mut().unwrap().next = node;
s = &mut s.as_mut().unwrap().next;
}
Expand Down
2 changes: 1 addition & 1 deletion src/bin/reverse-words-in-a-string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ impl Solution {
if s.is_empty() {
return s;
}
let mut s = s.as_bytes();
let s = s.as_bytes();
let (mut start, mut end) = (0, s.len() - 1);

for i in 0..s.len() {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/robot-bounded-in-circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct Solution;

impl Solution {
/// 只有(x,y)不是原点,并且方向和原来的方向一致,最后才回不去
pub fn is_robot_bounded(mut instructions: String) -> bool {
pub fn is_robot_bounded(instructions: String) -> bool {
let mut start = (0, 0);
let mut direction = 0u8; // 当前的方向,0为向前,1为向左,2为向后,3为向右

Expand Down
2 changes: 1 addition & 1 deletion src/bin/search-in-rotated-sorted-array.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::os::macos::raw::stat;


fn main() {
assert_eq!(4, Solution::search(vec![4, 5, 6, 7, 8, 1, 2, 3], 8));
Expand Down
2 changes: 1 addition & 1 deletion src/bin/sqrtx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ struct Solution;

impl Solution {
pub fn my_sqrt(x: i32) -> i32 {
let mut s = x as f64;
let s = x as f64;
let mut x1 = x as f64;

while (s - x1 * x1).abs() > 0.1 {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/summary-ranges.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde_json::ser::CharEscape::Solidus;


fn main() {
println!("{:?}", Solution::summary_ranges(vec![0, 1, 2, 4, 5, 7]));
Expand Down
4 changes: 2 additions & 2 deletions src/bin/swapping-nodes-in-a-linked-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl Solution {
index += 1;
}

let f = k_node.unwrap().val;
let s = slow.unwrap().val;
let _f = k_node.unwrap().val;
let _s = slow.unwrap().val;

head
}
Expand Down
Loading