C#C
C#3y ago
morry329#

✅ Why is my code still wrong?

So I am resolving this LC puzzle https://leetcode.com/problems/binary-search/description/
I think my code is almost there, it still comes with a couple of failed test cases like this (see the attached screenshot).
Could anyone kindly point me in the right direction?

public static class Extensions{
    public static int indexFinder<T>(this T[] nums, T target){
        return Array.FindIndex(nums, val => val.Equals(target));
    }
}

public class Solution {
    
    public int Search(int[] nums, int target) {
        if(nums.indexFinder(target) == -1){
            return -1;
        } else {
                int index = nums.indexFinder(target);
                if(nums.indexFinder(target) != 1){
                   return index;
                }
            
        }
        return -1;
    }
}
Bildschirmfoto_2023-03-21_um_22.02.25.png
LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
Was this page helpful?