Failed submission


  • 0
    M

    Recently I started practicing coding on this website and I have a problem with code submission that there shows message "Line 57: redefinition of ‘int main()’." everytime I submit my solution.

    I do not know why and the code itself works fine on my computer.

    Here is the code

    #include <vector>
    

    #include <iostream>

    using namespace std;

    class Solution {
    public:
    vector<int> twoSum(vector<int>& nums, int target) {
    vector<int> index_1_result, index_2_result;
    int i, j, number_1, number_2, sum;

    	int length_input = nums.size();
    
    	// Find all the possible combination;
    
    	for (i = 0; i < length_input; i++){
    		number_1 = nums.at(i);
    		for (j = i + 1; j < length_input; j++){
    			number_2 = nums.at(j);
    			sum = number_1 + number_2;
    			if (sum == target){
    				cout << "number 1 = " << number_1 << "\n";
    				cout << "number 2 = " << number_2 << "\n";
    				index_1_result.push_back(i + 1);
    				index_2_result.push_back(j + 1);
    			}
    		}
    	}
    
    	vector<int> result_return;
    
    	// Since there is only a result by assumption;
    
    	result_return.push_back(index_1_result.at(0));
    	result_return.push_back(index_2_result.at(0));
    	return result_return;
    }
    

    };

    int main(){

    Solution solution1;
    vector<int> nums, result;
    
    nums.push_back(2);
    nums.push_back(7);
    nums.push_back(11);
    nums.push_back(15);
    
    int target = 9;
    
    result = solution1.twoSum(nums, target);
    
    cout << "index1 = " << result.at(0) << ", " << "index2 = " << result.at(1) << "\n";
    return 0;
    

    }


  • 3
    H

    what you should do is commit your algorithms, the function twoSum, you should not commit the main function, leetcode will provide the entry of program ,I think. I hope this answer can help you.(I am chinese , my english is not pretty good, I hope you can understand what I say.)


  • 0
    K

    @hhli ->Could you please elaborate your point more preceisly about the "commit of main".
    Does is it mean that we do not need to write the code of main function .( Code only desired function)


  • 0
    K

    No, we don't need to write the main function. As he/she said, LeetCode takes care of that. Save your time.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.