-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add solutions to lc problem: No.2057 (#3837)
No.2057.Smallest Index With Equal Value
- Loading branch information
Showing
8 changed files
with
134 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
solution/2000-2099/2057.Smallest Index With Equal Value/Solution.cj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class Solution { | ||
func smallestEqual(nums: Array<Int64>): Int64 { | ||
for (i in 0..nums.size) { | ||
if (i % 10 == nums[i]) { | ||
return i | ||
} | ||
} | ||
-1 | ||
} | ||
} |
8 changes: 5 additions & 3 deletions
8
solution/2000-2099/2057.Smallest Index With Equal Value/Solution.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
class Solution { | ||
public: | ||
int smallestEqual(vector<int>& nums) { | ||
for (int i = 0; i < nums.size(); ++i) | ||
if (i % 10 == nums[i]) | ||
for (int i = 0; i < nums.size(); ++i) { | ||
if (i % 10 == nums[i]) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} | ||
}; | ||
}; |
6 changes: 3 additions & 3 deletions
6
solution/2000-2099/2057.Smallest Index With Equal Value/Solution.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
func smallestEqual(nums []int) int { | ||
for i, v := range nums { | ||
if i%10 == v { | ||
for i, x := range nums { | ||
if i%10 == x { | ||
return i | ||
} | ||
} | ||
return -1 | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
solution/2000-2099/2057.Smallest Index With Equal Value/Solution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
class Solution: | ||
def smallestEqual(self, nums: List[int]) -> int: | ||
for i, v in enumerate(nums): | ||
if i % 10 == v: | ||
for i, x in enumerate(nums): | ||
if i % 10 == x: | ||
return i | ||
return -1 |
10 changes: 10 additions & 0 deletions
10
solution/2000-2099/2057.Smallest Index With Equal Value/Solution.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
impl Solution { | ||
pub fn smallest_equal(nums: Vec<i32>) -> i32 { | ||
for (i, &x) in nums.iter().enumerate() { | ||
if i % 10 == x as usize { | ||
return i as i32; | ||
} | ||
} | ||
-1 | ||
} | ||
} |
6 changes: 4 additions & 2 deletions
6
solution/2000-2099/2057.Smallest Index With Equal Value/Solution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
function smallestEqual(nums: number[]): number { | ||
for (let i = 0; i < nums.length; i++) { | ||
if (i % 10 == nums[i]) return i; | ||
for (let i = 0; i < nums.length; ++i) { | ||
if (i % 10 === nums[i]) { | ||
return i; | ||
} | ||
} | ||
return -1; | ||
} |