30:00
You are given an integer array nums.
nums
Return the smallest index i such that the sum of the digits of nums[i] is equal to i.
i
nums[i]
If no such index exists, return -1.
-1
1≤nums.length≤1001 \leq nums.length \leq 1001≤nums.length≤100
0≤nums[i]≤10000 \leq nums[i] \leq 10000≤nums[i]≤1000
Run code to see results.
Walk the indices from left to right. For each one, add up the digits of nums[i] and compare that sum with i itself.
0
Σ0
1
2
Given an integer array nums, return the smallest index i whose value nums[i] has a digit sum equal to i, or -1 if there is none.