Failed submission

  • 0

    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 {
    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 =;
    		for (j = i + 1; j < length_input; j++){
    			number_2 =;
    			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;
    	return result_return;


    int main(){

    Solution solution1;
    vector<int> nums, result;
    int target = 9;
    result = solution1.twoSum(nums, target);
    cout << "index1 = " << << ", " << "index2 = " << << "\n";
    return 0;


  • 3

    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

    @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

    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.