Skip to content

Commit 1c389c5

Browse files
solves smallest index with equal value
1 parent cef3857 commit 1c389c5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@
489489
| 2042 | [Check if Numbers Are Ascending in a Sentence](https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence) | [![Java](assets/java.png)](src/CheckIfNumbersAreAscendingInASentence.java) | |
490490
| 2047 | [Number of Valid Words in a Sentence](https://leetcode.com/problems/number-of-valid-words-in-a-sentence) | [![Java](assets/java.png)](src/NumberOfValidWordsInASentence.java) | |
491491
| 2053 | [Kth Distinct String in an Array](https://leetcode.com/problems/kth-distinct-string-in-an-array) | [![Java](assets/java.png)](src/KthDistinctStringInAnArray.java) | |
492-
| 2057 | [Smallest Index With Equal Value](https://leetcode.com/problems/smallest-index-with-equal-value) | | |
492+
| 2057 | [Smallest Index With Equal Value](https://leetcode.com/problems/smallest-index-with-equal-value) | [![Java](assets/java.png)](src/SmallestIndexWithEqualValue.java) | |
493493
| 2062 | [Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string) | | |
494494
| 2068 | [Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent) | | |
495495
| 2073 | [Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets) | | |

src/SmallestIndexWithEqualValue.java

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// https://leetcode.com/problems/smallest-index-with-equal-value
2+
// T: O(N)
3+
// S: O(1)
4+
5+
public class SmallestIndexWithEqualValue {
6+
public int smallestEqual(int[] nums) {
7+
for (int i = 0 ; i < nums.length ; i++) {
8+
if (i % 10 == nums[i]) return i;
9+
}
10+
return -1;
11+
}
12+
}

0 commit comments

Comments
 (0)