C# Solution


  • 1
    S

    Thoughts on my solution?

    public class Solution
    {
     public int[] TwoSum(int[] nums, int target)
        {
            var numCount = nums.Count();
            List<int> returnNums = new List<int>();
            for (var x = 0; x <= numCount; x++)
            {
                for (var y = numCount - 1; y >= 0; y--)
                {
                    if (x != y)
                    {
                        if (nums[x] + nums[y] == target)
                        {
                            returnNums.Add(x);
                            returnNums.Add(y);
                            return returnNums.ToArray();
                        }
                    }
                }
            }
            return null;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.