Skip to content

Commit 8749425

Browse files
committed
p1
0 parents  commit 8749425

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "leetcode"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

helper.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
l = [(l if (l[0] == 0) else [[1, 0][i] for i in l]) for l in matrix]
2+
print(sorted(list(set([(str(i), len([n for n in l if n == i])) for i in l])), key=lambda x: x[1])[-1][1])

src/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mod p2923;
2+
3+
pub fn main() {
4+
p2923::run();
5+
}

src/p1.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use std::collections::HashSet;
2+
3+
pub fn run() {
4+
for i in [
5+
(vec![2,7,11,15], 9)
6+
] {
7+
println!("{:?}", two_sum(i.0, i.1));
8+
}
9+
}
10+
11+
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
12+
let set: HashSet<i32> = HashSet::from_iter(nums.iter().cloned());
13+
14+
for (index, i) in nums.iter().enumerate() {
15+
let d = target - i;
16+
17+
if set.contains(&d) {
18+
let mut a = 0;
19+
for n in &nums {
20+
if a == index as i32 {
21+
continue;
22+
}
23+
if *n == d {
24+
return vec![index as i32, a];
25+
}
26+
a += 1;
27+
}
28+
}
29+
}
30+
31+
vec![]
32+
}

0 commit comments

Comments
 (0)