// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
const counter = {};
const standard = A.length / 2;
for (var i = 0; i < A.length; i++) {
if (counter[A[i]]) {
counter[A[i]].push(i);
} else {
counter[A[i]] = [i]; //인덱스 저장
}
if (counter[A[i]].length > standard) {
return counter[A[i]][0];
}
}
return -1;
}
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
dic = {}
half = len(A)/2
for i in range(len(A)):
if A[i] in dic:
dic[A[i]] += 1
else:
dic[A[i]] = 1
if dic[A[i]] > half:
return i
return -1