class Solution {
public int[] twoSum(int[] nums, int target) {
for (int i=0; i<= nums.length()-1;i++){
for (int j =i+1 ; j <= nums.length()-2; j++){
if((nums[i]+nums[j]) == target )
int [] r = {i , j};
return r;
}
}
}
}
...
I wrote the following code but I am getting an error in my if statement. I am trying to solve a problem on leetcode but I am running into an error:
Line 9: error: variable declaration not allowed here int [] r = {i , j}; ^
What can I do to fix it and why am I running into this error?
Aucun commentaire:
Enregistrer un commentaire