Skip to content

Commit 72de6f1

Browse files
committed
sort,iterate and return filter which matches target
1 parent 135c4b7 commit 72de6f1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

2089/main.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
impl Solution {
2+
pub fn target_indices(nums: Vec<i32>, target: i32) -> Vec<i32> {
3+
let mut nums = nums;
4+
nums.sort();
5+
nums.iter()
6+
.enumerate()
7+
.filter(|(_, &x)| x == target)
8+
.map(|(x, _)| x as i32)
9+
.collect::<Vec<_>>()
10+
}
11+
}

0 commit comments

Comments
 (0)