© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
38 replies
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;
    }
}
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
LeetCode - The World's Leading Online Programming Learning Platform
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.
LeetCode - The World's Leading Online Programming Learning Platform
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

why is my code weird??
C#CC# / help
13mo ago
❔ Something wrong with my code
C#CC# / help
4y ago
Why is my code not thread save?
C#CC# / help
4y ago
Why is my code not runing? [Answered]
C#CC# / help
4y ago