Ad
  • Default User Avatar

    The Question is how can the code has mistakes when it runs correctly in Qt with the same array as input as in example.

  • Default User Avatar

    Because you didn´t replay anything that could solve the problem

  • Default User Avatar

    Hi everyone. When I run the code in my IDE(Qt) it shows the correct output, but when I run the code here, I get different output. Does someone encountered similar problem?

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    int findOdd(const std::vector<int>& numbers) {

    int arrayLength = numbers.size(); 
    for(int i = 0; i < (arrayLength - 1); i++) {
        int counter = 0;
        for(int j = 0; j <= arrayLength; j++) {
            if (numbers[i] == numbers[j]) {
                counter++;
            }
        }
        if(counter % 2) {
            return numbers[i];
        }
    }
    return numbers[arrayLength - 1];
    

    }

    When I test this code in Qt with sample arrays it returns the correct value, but when I execute it here it doesn't. Any ideas why.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution