go iterate over map 10x faster than over slice
I found an interesting behavior in this problem. After I reviewed the solutions in discussion, came up with this approach:\n\nfunc longestConsecutive(nums []int
I found an interesting behavior in this problem. After I reviewed the solutions in discussion, came up with this approach:\n```\nfunc longestConsecutive(nums []int) int {\n    numMap := map[int]bool{}\n    consecutiveNumCnt := 0\n\n    for _, num := range nums{\n        numMap[num] = true\n    }\n    \n\t// If I iterate over the map instead of input nums slice, the runtime would be 10x faster than slice one.\n    //for _, num := range nums{\n    for num := range numMap{\n        if numMap[num - 1]{\n            continue\n        }\n        \n        cur := num\n        for numMap[cur+1]{\n            cur++\n        }\n        \n        consecutiveNumCnt = max(consecutiveNumCnt, cur - num+1)\n    }\n    \n    return consecutiveNumCnt\n}\n\nfunc max(a, b int)int{\n    if a > b{\n        return a\n    }\n    return b\n}\n```\n\nIf I iterate over the map instead of input nums slice, the runtime would be 10x faster than slice one.\nIt\'s quite odd, based on my understanding of golang, iterate over slice should be faster than map.\nCan some golang experts help resolve my question? Do I misunderstand or I get anything wrong?\n
['Go']