題目:
Given an integer array sorted in non-decreasing order, there is exactly one
integer in the array that occurs more than 25% of the time.
Return that integer.
Example 1:
Input: arr = [1,2,2,6,6,6,6,7,10]
Output: 6
Constraints:
1 <= arr.length <= 10^4
0 <= arr[i] <= 10^5
code:
class Solution(object):
def findSpecialInteger(self, arr):
"""
:type arr: List[int]
:rtype: int
"""
dic={}
dic=Counter(arr)
for i in dic:
if (dic[i]/len(arr))>0.25:
return i
問題:
我用Visual Studio Code的編譯器跑出來沒問題,但leetcode會跑出None,不知道
哪裡出問題了
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 49.216.60.243 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1587653719.A.314.html
推
04/23 23:29,
4年前
, 1F
04/23 23:29, 1F
→
04/23 23:32,
4年前
, 2F
04/23 23:32, 2F
推
04/23 23:42,
4年前
, 3F
04/23 23:42, 3F
推
04/24 00:27,
4年前
, 4F
04/24 00:27, 4F
→
04/24 00:27,
4年前
, 5F
04/24 00:27, 5F
→
04/29 21:46,
4年前
, 6F
04/29 21:46, 6F