Class Solution
-
- All Implemented Interfaces:
public final class Solution
2057 - Smallest Index With Equal Value\.
Easy
Given a 0-indexed integer array
nums
, return the smallest indexi
ofnums
such thati mod 10 == nums[i]
, or-1
if such index does not exist.x mod y
denotes the remainder whenx
is divided byy
.Example 1:
Input: nums = 0,1,2
Output: 0
Explanation:
i=0: 0 mod 10 = 0 == nums0.
i=1: 1 mod 10 = 1 == nums1.
i=2: 2 mod 10 = 2 == nums2.
All indices have i mod 10 == numsi, so we return the smallest index 0.
Example 2:
Input: nums = 4,3,2,1
Output: 2
Explanation:
i=0: 0 mod 10 = 0 != nums0.
i=1: 1 mod 10 = 1 != nums1.
i=2: 2 mod 10 = 2 == nums2.
i=3: 3 mod 10 = 3 != nums3.
2 is the only index which has i mod 10 == numsi.
Example 3:
Input: nums = 1,2,3,4,5,6,7,8,9,0
Output: -1
Explanation: No index satisfies i mod 10 == numsi.
Constraints:
1 <= nums.length <= 100
0 <= nums[i] <= 9
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final Integer
smallestEqual(IntArray nums)
-
-
Method Detail
-
smallestEqual
final Integer smallestEqual(IntArray nums)
-
-
-
-