TwoSum Help

This is what I have so far:
C#
public class Solution {
public int[] TwoSum(int[] nums, int target) {

//declarations

var usedPairs = new Dictionary <int, int>(){};
int complement = 0;

//traversal
for(int i = 0; i<nums.Length; i++)
{
complement = target - nums[i];
if(usedPairs.TryGetValue(complement, out int secondIndex))
{
return new int[]{i, secondIndex};
}
usedPairs[nums(i)] = i;
}
return new int[]{};

}
}
C#
public class Solution {
public int[] TwoSum(int[] nums, int target) {

//declarations

var usedPairs = new Dictionary <int, int>(){};
int complement = 0;

//traversal
for(int i = 0; i<nums.Length; i++)
{
complement = target - nums[i];
if(usedPairs.TryGetValue(complement, out int secondIndex))
{
return new int[]{i, secondIndex};
}
usedPairs[nums(i)] = i;
}
return new int[]{};

}
}
I'm getting the following error:
Line 17: Char 23: error CS0149: Method name expected (in Solution.cs)
Line 17: Char 23: error CS0149: Method name expected (in Solution.cs)
with Line 17 being the line with
usedPairs[nums(i)] = i;
usedPairs[nums(i)] = i;
I'm not sure exactly what is wrong with this line
3 Replies
Angius
Angius2y ago
Well, nums is an array If you want to get an ith element from an array, use nums[i] Not nums(i)
Pandraxicon
PandraxiconOP2y ago
oh oops tysm Im dumb Is there anything else with it that you see I might need improvement on?
Angius
Angius2y ago
Not at a glance
Want results from more Discord servers?
Add your server