OJ Only Reads The First Element of My Result? Confused.


  • 0
    A

    Guys,

    I can't figure out why it keeps saying this:

    Submission Result: Wrong Answer

    Input: [3,2,4], 6
    Output: 2
    Expected: 2, 3

    When I compiled locally, my function returns exactly a vector<int> of {2, 3}. Any thoughts? Thanks.


  • 1
    M

    Without seeing the code you submitted, I can't give a definitive answer, but from the result, I believe you are printing out the 2, then the 3, inside the function. Something like:

    cout << pair[0] << endl; 
    cout << pair[1] << endl;
    

    If you have something like this in your code, the output the tester compares to is what gets printed, not what gets returned to the calling function.


  • 0
    A

    Hey Thanks mike3.

    No I have no cout etc in my code. I thot I was supposed to return the results as a vector<int> instead of using cout. Is that correct? Thanks.


  • 0
    A

    mike3, actually, you were right. There was a subtle cout I used when I wanted to debug but forgot to comment out. It works fine now. Thank you so much!!!


Log in to reply
 

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