Is there any thing wrong about the test case.


  • 0
    D

    Hi

    Maybe I made some misunderstanding about this issue. I got bellow information.
    Input:
    [1,2]
    2
    Output:
    []
    Expected:
    [1,2]

    I think my output is ok. no one's frequence more than two.
    Below is my python solution.

    class Solution(object):
    def topKFrequent(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: List[int]
        """
        result = []
        dataHash = {}
        for x in nums:
            if dataHash.has_key(x):
                dataHash[x] += 1
            else:
                dataHash[x] = 1
            
        for x in dataHash.keys():
            if dataHash[x] >= k:
                result.append(x)
               
        return result

  • 0

    "no one's frequence more than two"

    That's not what k is about.


  • 0
    D

    yes, i know why I wrong. because this needs the top k frequent. not more than k.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.