Initial commit
This commit is contained in:
commit
5da5a2ca0a
8 changed files with 89 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"rust-analyzer.linkedProjects": [
|
||||||
|
"./Cargo.toml"
|
||||||
|
]
|
||||||
|
}
|
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "leetcode"
|
||||||
|
version = "0.1.0"
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "leetcode"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
16
src/bin/1_two_sum.rs
Normal file
16
src/bin/1_two_sum.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("{:?}", two_sum(vec![2,7,11,15], 9));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
|
||||||
|
let mut components: HashMap<i32, usize> = HashMap::new();
|
||||||
|
for i in 0..nums.len() {
|
||||||
|
let component = target - nums[i];
|
||||||
|
let j = components.get(&component);
|
||||||
|
if j.is_some() { return vec![i as i32, *j.unwrap() as i32]; }
|
||||||
|
components.insert(nums[i], i);
|
||||||
|
}
|
||||||
|
return Vec::new();
|
||||||
|
}
|
24
src/bin/2_add_two_numbers.rs
Normal file
24
src/bin/2_add_two_numbers.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
fn main() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_two_numbers(l1: Option<Box<ListNode>>, l2: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Definition for singly-linked list.
|
||||||
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
|
pub struct ListNode {
|
||||||
|
pub val: i32,
|
||||||
|
pub next: Option<Box<ListNode>>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ListNode {
|
||||||
|
#[inline]
|
||||||
|
fn new(val: i32) -> Self {
|
||||||
|
ListNode {
|
||||||
|
next: None,
|
||||||
|
val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
src/bin/3_longest_substring_without_repeating_characters.rs
Normal file
20
src/bin/3_longest_substring_without_repeating_characters.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("{}", length_of_longest_substring(String::from("abcabcbb")));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn length_of_longest_substring(s: String) -> i32 {
|
||||||
|
let mut seen: HashMap<char, usize> = HashMap::with_capacity(80);
|
||||||
|
let (mut start_index, mut max_length) = (0usize, 0i32);
|
||||||
|
for (i, c) in s.chars().enumerate() {
|
||||||
|
if let Some(index) = seen.get(&c) {
|
||||||
|
max_length = max_length.max((i - start_index) as i32);
|
||||||
|
start_index = *index + 1;
|
||||||
|
seen.retain(|_, i| *i >= start_index);
|
||||||
|
}
|
||||||
|
seen.insert(c, i);
|
||||||
|
}
|
||||||
|
max_length = max_length.max((s.len() - start_index) as i32);
|
||||||
|
return max_length;
|
||||||
|
}
|
8
src/bin/4_median_of_two_sorted_arrays.rs
Normal file
8
src/bin/4_median_of_two_sorted_arrays.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fn main() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn find_median_sorted_arrays(nums1: Vec<i32>, nums2: Vec<i32>) -> f64 {
|
||||||
|
|
||||||
|
return 0.0;
|
||||||
|
}
|
Loading…
Reference in a new issue