题解 | #有序数组中出现一次的元素#
有序数组中出现一次的元素
http://www.nowcoder.com/practice/4c67fc80c37649ac906fee76ec82beb4
计数后排序
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param v int整型一维数组
# @return int整型
#
from collections import Counter
class Solution:
def singleElement(self , v: List[int]) -> int:
# write code here
return sorted(Counter(v).items(), key=lambda x:x[1])[0][0]

查看14道真题和解析