
I think this gets you what you want: majority nums = find (\x -> fromIntegral (length x) > (fromIntegral (length nums)) / 2) (group(sort(nums))) It returns a "Maybe" list containing all majority elements. Something that avoids the sort would be faster though. -Keith
Message: 8 Date: Sun, 22 Feb 2009 01:15:30 +0000 From: "Matthew J. Williams"
Subject: [Haskell-beginners] Majority Element To: beginners@haskell.org Message-ID: <49a0a726.278e420a.6b19.ffffe361@mx.google.com> Content-Type: text/plain; charset="us-ascii"; format=flowed Dear listers
What is a majority element in an array?
Sincerely Matthew J. Williams
------------------------------
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners