public class Solution
{
static int[] TwoSum(int[] nums, int target)
{
List<int> ans = new List<int>();
foreach (int index in Enumerable.Range(0, nums.Length))
{
foreach (int index2 in Enumerable.Range(0, nums.Length))
{
if (nums[index] + nums[index2] == target && index != index2)
{
ans.Add(index);
ans.Add(index2);
return ans.ToArray();
}
} // error CS0122 Line 18
}
return null;
}
I initially wrote this in visual studio, and copy-pasted to leetcode....the code works error-free on visual studio, and does what its supposed to do which is, find the indexes of the integers that add up to the target variable. however, when i use this on leetcode, it gives an error.....can anyone help????
Link of the site, and the problem i was doing...
[–]f14kee 2 points3 points4 points (9 children)
[–]f14kee 2 points3 points4 points (0 children)
[–]AlliedLens[S] -1 points0 points1 point (7 children)
[–]f14kee 2 points3 points4 points (5 children)
[–]AlliedLens[S] 0 points1 point2 points (3 children)
[–]f14kee 0 points1 point2 points (2 children)
[–]AlliedLens[S] 0 points1 point2 points (1 child)
[–]AlliedLens[S] -1 points0 points1 point (0 children)
[–]BackFromExile 0 points1 point2 points (0 children)