C# implements given an integer array nums and an integer target value target

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LianXi
{
    namespace LianXi
    {
        public class Solution
        {
            public static int[] TwoSum(int[] nums, int target)
            {
                for (int j = 1; j < nums.Length; j++)
                {
                    for (int i = 0; i < j; i++)
                    {
                        if (nums[j] + nums[i] == target)
                        {
                            return new int[] { i, j };
                        }
                    }

                }
                return new int[] { -1, -1 };
            }

            public static void Main(String[] args)
            {
                int[] nums = { 1, 2, 3, 4, 5, 6, 7 };
                // int target = 9;
                int[i] a = TwoSum(nums, 9);
                Console.Write(a[0]+",");
                Console.Write(a[1]);
            }
        }
    }
}
 

Guess you like

Origin blog.csdn.net/m0_62316260/article/details/131782351