File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 107107 " \n " ,
108108 " return list(hash.values())\n "
109109 ]
110+ },
111+ {
112+ "cell_type" : " code" ,
113+ "execution_count" : 122 ,
114+ "metadata" : {},
115+ "outputs" : [
116+ {
117+ "name" : " stdout" ,
118+ "output_type" : " stream" ,
119+ "text" : [
120+ " {0: [], 1: []}\n "
121+ ]
122+ },
123+ {
124+ "data" : {
125+ "text/plain" : [
126+ " [1]"
127+ ]
128+ },
129+ "execution_count" : 122 ,
130+ "metadata" : {},
131+ "output_type" : " execute_result"
132+ }
133+ ],
134+ "source" : [
135+ " ### LEETCODE 347\n " ,
136+ " \n " ,
137+ " ### the optimal solution would have first count each element\n " ,
138+ " ### then flip the count and the key\n " ,
139+ " ### this solution does the other way around, which gets the elem from nums\n " ,
140+ " ### based on how many times it had appeared.\n " ,
141+ " ### very slow and expensive\n " ,
142+ " \n " ,
143+ " nums = [1] #4, -1\n " ,
144+ " k = 2\n " ,
145+ " \n " ,
146+ " hash = {i:[] for i in range(len(nums)+1)}\n " ,
147+ " print(hash)\n " ,
148+ " for i in set(nums):\n " ,
149+ " hash[nums.count(i)] += [i]\n " ,
150+ " \n " ,
151+ " L = []\n " ,
152+ " for i in list(hash.values()):\n " ,
153+ " L += i\n " ,
154+ " L[-k:]"
155+ ]
110156 }
111157 ],
112158 "metadata" : {
You can’t perform that action at this time.
0 commit comments