0

Below code is running fine on code blocks but giving error on leetcode platform. Why ?

error :- use of undeclared identifier 'Solution' vector ret = Solution().twoSum(param_1, param_2); return ret;

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,target;
    cout<<"enter size of array"<<endl;
    cin>>n;
    int *nums = new int[n];
    cout<<"enter elements in array"<<endl;
    for(int i=0;i<n;i++){
        cin>>nums[i];
    }
    cout<<"enter target"<<endl;
    cin>>target;


    for(int j=0;j<n;++j){
        int x,c;
        c=1;
        x=nums[j];
        while((x+nums[j+c])!=target){
            ++c;

        }
        if((j+c)<=(n-1))
            cout<<'['<<j<<','<<' '<<j+c<<']';
    }
}
  • 5
    Some so-called "competition" or "online judge" sites requires you to make a `Solution` class with a specifically named function in that class to be called. You need to read the assignment text more thoroughly to see what you need to do. – Some programmer dude Jul 19 '21 at 09:39
  • 4
    Also please read [Why should I not #include ?](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) and [Why is “using namespace std;” considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) And lastly don't use such sites to learn anything, they are not learning or teaching resources. All being taught are truly bad coding habits showcased in many examples (and which you have a few in your code). – Some programmer dude Jul 19 '21 at 09:42
  • @Someprogrammerdude thank you but can you suggest me good platform where i can practice c++ coding in a proper way. – Garvit Chauhan Jul 19 '21 at 09:46
  • Invest in [some good books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and take classes. – Some programmer dude Jul 19 '21 at 10:01
  • @Garvit – My advice: find a real project and just start hacking. You will encounter obstacles, find your way around them and become better along the way. – de. Jul 19 '21 at 10:55

0 Answers0