Ad
  • Custom 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.

  • Custom User Avatar

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

  • Custom 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?

  • Custom User Avatar

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

  • Custom 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.

  • Custom User Avatar

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