ago
0 like 0 dislike
0 like 0 dislike
ago
0 like 0 dislike
0 like 0 dislike
Sorting is one of the most expensive operations you can do and you’d have to operate on all of the elements before you could search your sorted array.

It would be better to hash the elements (using a set in Python) and do a membership search in a single run through.

The worst-case search time the hash and check method is ~O(N/2) and it will work on any data type that can be coerced to a string.
ago
0 like 0 dislike
0 like 0 dislike
Gad that's a horrible solution! Don't sort.  Just push everything into a hash ( dictionary).

Start with empty dictionary or set


Loop over array:
  
    Check if element is in dictionary

         No: enter it into set as the key.

          Yes : delete key from set


Now the set keys are the elements that appear an odd number of times in list
ago

No related questions found

33.4k questions

135k answers

0 comments

33.7k users

OhhAskMe is a math solving hub where high school and university students ask and answer loads of math questions, discuss the latest in math, and share their knowledge. It’s 100% free!