Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ff6e26a

Browse files
committed
check-if-n-and-its-double-exist
1 parent 523e6c8 commit ff6e26a

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
leetcode by rust
33

44
### 题目
5+
6+
- [746. 使用最小花费爬楼梯]
7+
- [src](https://github.com/rustors/leetcode/blob/main/src/bin/check-if-n-and-its-double-exist.rs)
8+
- [leetcode](https://leetcode-cn.com/problems/check-if-n-and-its-double-exist/)
9+
510
- 1008:前序遍历构造二叉搜索树
6-
- [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs)
7-
- [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/)
11+
- [src](https://github.com/rustors/leetcode/blob/main/src/bin/construct-binary-search-tree-from-preorder-traversal.rs)
12+
- [leetcode](https://leetcode-cn.com/problems/construct-binary-search-tree-from-preorder-traversal/)
813

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
fn main() {}
2+
3+
struct Solution;
4+
5+
impl Solution {
6+
pub fn check_if_exist(arr: Vec<i32>) -> bool {
7+
let mut map = std::collections::HashMap::<i32, usize>::new();
8+
9+
for (index, value) in arr.iter().enumerate() {
10+
map.insert(*value, index);
11+
}
12+
13+
for (index, value) in arr.iter().map(|x| x * 2).enumerate() {
14+
if let Some(i) = map.get(&value) {
15+
if *i != index {
16+
return true;
17+
}
18+
}
19+
}
20+
21+
false
22+
}
23+
}

0 commit comments

Comments
 (0)