Placido_GDD

2sumsums

Jun 13th, 2022 (edited)
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. namespace SumSumTask
  2. {
  3.   using System;
  4.   using System.Collections.Generic;
  5.  
  6.   public class TwoSum
  7.   {
  8.     public int SumOfTwoSumTargets (int[] numbers, int min, int max)
  9.     {
  10.        int target = 0;
  11.        int sum = 0;
  12.        int num1 = 0;
  13.        int num2 = 0;
  14.        List<int> sums = new List<int>();
  15.        int sumOfNums = 0;
  16.        for(int x = min;x < max;x++)
  17.        {
  18.          target = x;
  19.          for(int y = 0;y < numbers.Length;y++)
  20.          {
  21.             num1 = numbers[y];
  22.             num2 = target - num1;
  23.             sum = num1 + num2;
  24.            
  25.          }
  26.          if(sum == target)
  27.             {
  28.               sums.Add(sum);
  29.             }
  30.        }
  31.      
  32.  
  33.         for(int i = 0;i < sums.Count;i++)
  34.         {
  35.           sumOfNums += sums[i];
  36.         }
  37.        
  38.        return sumOfNums;
  39.     }
  40.   }
  41. }
Add Comment
Please, Sign In to add comment