发现函数在类中显示异常
#include<iostream>
#include<algorithm>
using namespace std;
class Solution{
public int[] thesum(int[] nums,int target)
{
int n=nums.length;
for(int i=0;i<n;++i){
for(int j=i+1;j<n;++j)
{
if(nums[i]+nums[j]==target){
return new int[]{i,j};
}
}
}
return new int[0];
}
}
error: expected unqualified-id before '[' token
public int[] thesum(int[] nums,int target)
#include<iostream>
#include<algorithm>
using namespace std;
class Solution {
public:
int* thesum(int nums[], int target)
{
int n = sizeof(nums);
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j)
{
if (nums[i] + nums[j] == target) {
return new int[] {i, j};
}
}
}
return nums;
}
}
https://leetcode-cn.com/problems/two-sum/solution/liang-shu-zhi-he-by-leetcode-solution/