Skip to content

Commit 276cdfc

Browse files
committed
feat: add more
1 parent c8d4f3b commit 276cdfc

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

pools_todo/_1064_fixed_point.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
11
// https://leetcode.com/problems/fixed-point
2+
3+
pub fn fixed_point(arr: Vec<i32>) -> i32 {
4+
for i in 0..arr.len() {
5+
if arr[i] == i as i32 {
6+
return i as i32;
7+
}
8+
}
9+
return -1;
10+
}
11+
12+
#[test]
13+
pub fn t1() {
14+
assert_eq!(fixed_point(vec![-10, -5, 0, 3, 7]), 3);
15+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
11
// https://leetcode.com/problems/index-pairs-of-a-string
2+
3+
pub fn index_pairs(text: String, words: Vec<String>) -> Vec<Vec<i32>> {
4+
let mut result = Vec::new();
5+
let text_len = text.len();
6+
let hs: std::collections::HashSet<String> = std::collections::HashSet::from_iter(words);
7+
for i in 0..text_len {
8+
for j in i..text_len {
9+
if hs.contains(&text[i..=j].to_string()) {
10+
result.push(vec![i as i32, j as i32]);
11+
}
12+
}
13+
}
14+
return result;
15+
}
16+
17+
#[test]
18+
pub fn t1() {
19+
assert_eq!(
20+
index_pairs(
21+
"thestoryofleetcodeandme".to_string(),
22+
vec![
23+
"story".to_string(),
24+
"fleet".to_string(),
25+
"leetcode".to_string(),
26+
]
27+
),
28+
vec![vec![3, 7], vec![9, 13], vec![10, 17]]
29+
);
30+
assert_eq!(
31+
index_pairs(
32+
"ababa".to_string(),
33+
vec![
34+
"aba".to_string(),
35+
"ab".to_string(),
36+
]
37+
),
38+
vec![vec![0, 1], vec![0, 2], vec![2, 3], vec![2, 4]]
39+
);
40+
}
41+

0 commit comments

Comments
 (0)