Skip to main content

rustgym/leetcode/
_1064_fixed_point.rs

1struct Solution;
2
3impl Solution {
4    fn fixed_point(a: Vec<i32>) -> i32 {
5        for i in 0..a.len() {
6            if i as i32 == a[i] {
7                return i as i32;
8            }
9        }
10        -1
11    }
12}
13
14#[test]
15fn test() {
16    assert_eq!(Solution::fixed_point(vec![-10, -5, 0, 3, 7]), 3);
17    assert_eq!(Solution::fixed_point(vec![0, 2, 5, 8, 17]), 0);
18    assert_eq!(Solution::fixed_point(vec![-10, -5, 3, 4, 7, 9]), -1);
19}