Skip to content

2057. Smallest Index With Equal Value

  • Time: $O(n)$
  • Space: $O(1)$
1
2
3
4
5
6
7
8
9
class Solution {
 public:
  int smallestEqual(vector<int>& nums) {
    for (int i = 0; i < nums.size(); ++i)
      if (nums[i] == i % 10)
        return i;
    return -1;
  }
};
1
2
3
4
5
6
7
8
class Solution {
  public int smallestEqual(int[] nums) {
    for (int i = 0; i < nums.length; ++i)
      if (nums[i] == i % 10)
        return i;
    return -1;
  }
}
1
2
3
class Solution:
  def smallestEqual(self, nums: list[int]) -> int:
    return next((i for i, num in enumerate(nums) if i % 10 == num), -1)