Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let most_frequent_elt list =
- let rec loop maxelt maxcount elt count = function
- | [] -> if count > maxcount then elt else maxelt
- | x::xs ->
- if elt = x then loop maxelt maxcount elt (count + 1) xs
- else if count > maxcount then loop elt count x 1 xs
- else loop maxelt maxcount x 1 xs in
- match list with
- | [] -> failwith "none"
- | x::xs -> loop x 0 x 1 xs ;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement