2057. Smallest Index With Equal Value Easy
1/**
2 * [2057] Smallest Index With Equal Value
3 *
4 * Given a 0-indexed integer array nums, return the smallest index i of nums such that i mod 10 == nums[i], or -1 if such index does not exist.
5 * x mod y denotes the remainder when x is divided by y.
6 *
7 * Example 1:
8 *
9 * Input: nums = [0,1,2]
10 * Output: 0
11 * Explanation:
12 * i=0: 0 mod 10 = 0 == nums[0].
13 * i=1: 1 mod 10 = 1 == nums[1].
14 * i=2: 2 mod 10 = 2 == nums[2].
15 * All indices have i mod 10 == nums[i], so we return the smallest index 0.
16 *
17 * Example 2:
18 *
19 * Input: nums = [4,3,2,1]
20 * Output: 2
21 * Explanation:
22 * i=0: 0 mod 10 = 0 != nums[0].
23 * i=1: 1 mod 10 = 1 != nums[1].
24 * i=2: 2 mod 10 = 2 == nums[2].
25 * i=3: 3 mod 10 = 3 != nums[3].
26 * 2 is the only index which has i mod 10 == nums[i].
27 *
28 * Example 3:
29 *
30 * Input: nums = [1,2,3,4,5,6,7,8,9,0]
31 * Output: -1
32 * Explanation: No index satisfies i mod 10 == nums[i].
33 *
34 *
35 * Constraints:
36 *
37 * 1 <= nums.length <= 100
38 * 0 <= nums[i] <= 9
39 *
40 */
41pub struct Solution {}
42
43// problem: https://leetcode.com/problems/smallest-index-with-equal-value/
44// discuss: https://leetcode.com/problems/smallest-index-with-equal-value/discuss/?currentPage=1&orderBy=most_votes&query=
45
46// submission codes start here
47
48impl Solution {
49 pub fn smallest_equal(nums: Vec<i32>) -> i32 {
50 0
51 }
52}
53
54// submission codes end
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_2057() {
62 }
63}
64
Back
© 2025 bowen.ge All Rights Reserved.